module Clear::SQL::Query::OrderBy
Overview
Encode for:
ORDER BY expression [ASC | DESC | USING operator] [NULLS FIRST | NULLS LAST];
Current implementation:
[x] Multiple Order by clauses [x] ASC/DESC [x] NULLS FIRST / NULLS LAST [ ] NOT IMPLEMENTED: USING OPERATOR
Direct including types
Defined in:
clear/sql/query/order_by.crInstance Method Summary
-
#clear_order_bys
Remove all order by clauses
-
#order_by(__tuple : NamedTuple)
Add multiple ORDER BY clause using a tuple:
-
#order_by(expression : Symbol, direction : Symbol = :asc, nulls : Symbol | Nil = nil)
Add one ORDER BY clause
query = Clear::SQL.select.from("users").order_by(:id, :desc, nulls_last) query.to_sql # > SELECT * FROM users ORDER BY "id" DESC NULLS LAST
-
#order_by(expression : String, direction : Symbol = :asc, nulls : Symbol | Nil = nil)
Add one ORDER BY clause
query = Clear::SQL.select.from("users").order_by(:id, :desc, nulls_last) query.to_sql # > SELECT * FROM users ORDER BY "id" DESC NULLS LAST
-
#order_by(**tuple)
Add multiple ORDER BY clause using a tuple:
-
#reverse_order_by
Flip over all order bys by switching the ASC direction to DESC and the NULLS FIRST to NULLS LAST
query = Clear::SQL.select.from("users").order_by(id: :desc, name: :asc, company: {:asc, :nulls_last}) query.reverse_order_by query.to_sql # SELECT * FROM users ORDER BY "id" ASC, "name" DESC, "company" DESC NULLS FIRST
Instance Method Detail
Add multiple ORDER BY clause using a tuple:
query = Clear::SQL.select.from("users").order_by(id: :desc, name: {:asc, :nulls_last})
query.to_sql # > SELECT * FROM users ORDER BY "id" DESC, "name" ASC NULLS LAST
Add one ORDER BY clause
query = Clear::SQL.select.from("users").order_by(:id, :desc, nulls_last)
query.to_sql # > SELECT * FROM users ORDER BY "id" DESC NULLS LAST
Add one ORDER BY clause
query = Clear::SQL.select.from("users").order_by(:id, :desc, nulls_last)
query.to_sql # > SELECT * FROM users ORDER BY "id" DESC NULLS LAST
Add multiple ORDER BY clause using a tuple:
query = Clear::SQL.select.from("users").order_by(id: :desc, name: {:asc, :nulls_last})
query.to_sql # > SELECT * FROM users ORDER BY "id" DESC, "name" ASC NULLS LAST
Flip over all order bys by switching the ASC direction to DESC and the NULLS FIRST to NULLS LAST
query = Clear::SQL.select.from("users").order_by(id: :desc, name: :asc, company: {:asc, :nulls_last})
query.reverse_order_by
query.to_sql # SELECT * FROM users ORDER BY "id" ASC, "name" DESC, "company" DESC NULLS FIRST
return self