diff --git a/vlib/orm/orm_test.v b/vlib/orm/orm_test.v index 88f685cc38..bc3a485858 100644 --- a/vlib/orm/orm_test.v +++ b/vlib/orm/orm_test.v @@ -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 } diff --git a/vlib/v/parser/sql.v b/vlib/v/parser/sql.v index c71c258b9c..0c9956bca5 100644 --- a/vlib/v/parser/sql.v +++ b/vlib/v/parser/sql.v @@ -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' {