orm: require `order by` instead of just `order`

pull/5630/head
Delyan Angelov 2020-07-02 23:37:24 +03:00
parent 7004f74b71
commit 3c432f5e07
2 changed files with 8 additions and 2 deletions

View File

@ -199,14 +199,14 @@ fn test_orm_sqlite() {
assert z[0].id == 3
oldest := sql db {
select from User order age desc limit 1
select from User order by age desc limit 1
}
assert oldest.age == 34
offs := 1
second_oldest := sql db {
select from User order age desc limit 1 offset offs
select from User order by age desc limit 1 offset offs
}
assert second_oldest.age == 31
}

View File

@ -47,6 +47,12 @@ fn (mut p Parser) sql_expr() ast.Expr {
mut has_desc := false
if p.tok.kind == .name && p.tok.lit == 'order' {
p.check_name() // `order`
order_pos := p.tok.position()
if p.tok.kind == .name && p.tok.lit == 'by' {
p.check_name() // `by`
} else {
p.error_with_pos('use `order by` in ORM queries', order_pos)
}
has_order = true
order_expr = p.expr(0)
if p.tok.kind == .name && p.tok.lit == 'desc' {