module Selectable
Overview
Handles methods related to selecting columns.
Defined in:
query/selectable.crInstance Method Summary
-
#distinct
Sets the distinct flag to true.
-
#select(*columns : Symbol | String)
Specifies the columns to select.
-
#select(**fields : Hash(String | Symbol, Array(Symbol) | Symbol))
Specifies the columns to select.
- #select(**fields)
-
#select(*cols : Symbol | String, **fields : Hash(String | Symbol, Array(Symbol) | Symbol))
Allow mixing String/Symbol args and Hash
- #select(*cols, **columns)
Instance Method Detail
def distinct
#
Sets the distinct flag to true.
Example Setting the distinct flag to true
query.distinct
def select(*columns : Symbol | String)
#
Specifies the columns to select.
- @param columns [Symbol*] The columns to select
- @return [Query] The query object
Example
query.select(:name, :age)
=> "SELECT name, age FROM users"
def select(**fields : Hash(String | Symbol, Array(Symbol) | Symbol))
#
Specifies the columns to select.
- @param fields [Hash(Symbol, Array(Symbol) | Symbol)] The columns to select
- @return [Query] The query object
Example
query.from(:users, :address).select(users: [:name, :age], address: [:city, :state])
=> "SELECT users.name, users.age, address.city, address.state FROM users, address"
** Example with aggregates **
query.from(:users).select(count: :id)
=> "SELECT COUNT(id) FROM users"
** Example with aliases **
query.from(:users, :orders).select(users: [:name, :age], orders: [:total_amount, :status])
=> "SELECT users.name, users.age, orders.total_amount, orders.status FROM users, orders"
def select(*cols : Symbol | String, **fields : Hash(String | Symbol, Array(Symbol) | Symbol))
#
Allow mixing String/Symbol args and Hash