diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index a28d270f50..98b7ce38df 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1028,6 +1028,13 @@ pub fn (mut f Fmt) expr(node ast.Expr) { f.write(' where ') 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 { f.write(' limit ') f.expr(node.limit_expr) diff --git a/vlib/v/fmt/tests/orm_keep.vv b/vlib/v/fmt/tests/orm_keep.vv index 28630c68bf..be3683057e 100644 --- a/vlib/v/fmt/tests/orm_keep.vv +++ b/vlib/v/fmt/tests/orm_keep.vv @@ -33,6 +33,12 @@ fn main() { customer := sql db { 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') // insert a new customer new_customer := Customer{