Module: SQB::Ordering
Constant Summary collapse
- VALID_ORDERS =
['ASC', 'DESC']
Instance Method Summary collapse
-
#no_order! ⇒ Object
Remove all ordering for this query.
-
#order(column, direction = nil) ⇒ Query
Add an order column.
-
#order!(*args) ⇒ Object
Add an order replacing all previous ones.
Instance Method Details
#no_order! ⇒ Object
Remove all ordering for this query
34 35 36 |
# File 'lib/sqb/ordering.rb', line 34 def no_order! @orders = [] end |
#order(column, direction = nil) ⇒ Query
Add an order column
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sqb/ordering.rb', line 11 def order(column, direction = nil) direction = direction ? direction.to_s.upcase : 'ASC' unless VALID_ORDERS.include?(direction) raise InvalidOrderDirectionError, "Invalid order direction #{direction}" end @orders ||= [] with_table_and_column(column) do |table, column| @orders << [escape_and_join(table, column), direction].join(' ') end self end |
#order!(*args) ⇒ Object
Add an order replacing all previous ones
28 29 30 31 |
# File 'lib/sqb/ordering.rb', line 28 def order!(*args) @orders = [] order(*args) end |