1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: keep order by in orm blocks (#7576)

This commit is contained in:
Lukas Neubert 2020-12-26 13:18:09 +01:00 committed by GitHub
parent dfcbf31f65
commit f707e13b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -1028,6 +1028,13 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
f.write(' where ') f.write(' where ')
f.expr(node.where_expr) f.expr(node.where_expr)
} }
if node.has_order {
f.write(' order by ')
f.expr(node.order_expr)
if node.has_desc {
f.write(' desc')
}
}
if node.has_limit { if node.has_limit {
f.write(' limit ') f.write(' limit ')
f.expr(node.limit_expr) f.expr(node.limit_expr)

View File

@ -33,6 +33,12 @@ fn main() {
customer := sql db { customer := sql db {
select from Customer where id == 1 limit 1 select from Customer where id == 1 limit 1
} }
best_customer := sql db {
select from Customer order by nr_orders desc limit 1
}
second_best := sql db {
select from UCustomerser order by nr_orders desc limit 1 offset 1
}
println('$customer.id - $customer.name') println('$customer.id - $customer.name')
// insert a new customer // insert a new customer
new_customer := Customer{ new_customer := Customer{