orm: require `order by` instead of just `order`
parent
7004f74b71
commit
3c432f5e07
|
@ -199,14 +199,14 @@ fn test_orm_sqlite() {
|
||||||
assert z[0].id == 3
|
assert z[0].id == 3
|
||||||
|
|
||||||
oldest := sql db {
|
oldest := sql db {
|
||||||
select from User order age desc limit 1
|
select from User order by age desc limit 1
|
||||||
}
|
}
|
||||||
assert oldest.age == 34
|
assert oldest.age == 34
|
||||||
|
|
||||||
offs := 1
|
offs := 1
|
||||||
|
|
||||||
second_oldest := sql db {
|
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
|
assert second_oldest.age == 31
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,12 @@ fn (mut p Parser) sql_expr() ast.Expr {
|
||||||
mut has_desc := false
|
mut has_desc := false
|
||||||
if p.tok.kind == .name && p.tok.lit == 'order' {
|
if p.tok.kind == .name && p.tok.lit == 'order' {
|
||||||
p.check_name() // `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
|
has_order = true
|
||||||
order_expr = p.expr(0)
|
order_expr = p.expr(0)
|
||||||
if p.tok.kind == .name && p.tok.lit == 'desc' {
|
if p.tok.kind == .name && p.tok.lit == 'desc' {
|
||||||
|
|
Loading…
Reference in New Issue