module Clear::SQL::Query::Select

Direct including types

Defined in:


Instance Method Summary

Instance Method Detail

def clear_distinct #

Remove distinct

[View source]
def clear_force_select #

[View source]
def clear_select #

[View source]
def distinct(on : String? = "") #

Add DISTINCT to the SELECT part of the query

  • If on is blank (empty string, default), will call a simple SELECT DISTINCT ...
  • If on is nil, will remove the distinct (see #clear_distinct)
  • If on is a non empty string, will call SELECT DISTINCT ON (on) ...

[View source]
def distinct_value : String? #

[View source]
def force_select(c : Column) #

[View source]
def force_select(*__args) #

Act as #select method, but is not cleared by #clear_select

This is useful for enriching a query which absolutely need some key colums, for example this is used in relations caching under the hood.

query.force_select("id")"a, b").to_sql # => Output "SELECT a, b, id"
query.clear_select.to_sql   # => Output "SELECT *, id"

[View source]
def force_select(**__tuple) #

[View source]
def select(*__args) #

Add columns in the SELECT query. By default, a new SELECT query will select all using wildcard *.

After a call to select is made, the query will select the given fields instead.

 select(user_id: "uid", updated_at: "updated_at")
 # => Output "SELECT user_id as uid, updated_at as updated_at"

[View source]
def select(**__tuple) #

[View source]
def set_default_table_wildcard(table : String? = nil) #

In some case you want you query to return table.* instead of * if no select parameters has been set. This occurs in the case of joins between models.

[View source]