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
-
#order_by(expression : String, direction : Symbol = :asc, nulls : Symbol | Nil = nil)
Add one ORDER BY clause
-
#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
Instance Method Detail
def order_by(tuple : NamedTuple)
#
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
def order_by(**tuple)
#
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
def 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
return self