Skip to content

Commit

Permalink
feat: LIMIT and OFFSET
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Dec 9, 2023
1 parent 76ecc17 commit 927c252
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 1 addition & 2 deletions server/src/lang/ast/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,5 @@ pub struct SqlSelect {
pub core: SelectCore,
pub compound: Vec<(SqlCompoundOperator, SelectCore)>,
pub order_by: Option<Vec<(SqlExpr, SqlOrdering)>>,
pub limit: Option<SqlExpr>,
pub offset: Option<SqlExpr>,
pub limit: Option<(SqlExpr, Option<SqlExpr>)>,
}
23 changes: 21 additions & 2 deletions server/src/lang/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,33 @@ impl<'a> Parser<'a> {
} else {
None
};

let limit = if self.match_next(skw!(Limit)) {
let first_expr = SqlExpr::Default(self.expression()?);
let (second_expr, reverse) = if self.match_next(skw!(Offset)) {
(Some(SqlExpr::Default(self.expression()?)), true)
} else if self.match_next(sym!(Comma)) {
(Some(SqlExpr::Default(self.expression()?)), false)
} else {
(None, false)
};

if second_expr.is_some() && reverse {
Some((second_expr.unwrap(), Some(first_expr)))
} else {
Some((first_expr, second_expr))
}
} else {
None
};

Ok(self.arena.expression(Expr::Select {
span: Span::default(),
query: SqlSelect {
core,
compound: compounds,
order_by,
limit: None, // TODO(vck)
offset: None, // TODO(vck)
limit,
},
}))
}
Expand Down

0 comments on commit 927c252

Please sign in to comment.