module

Clear::SQL::Query::Select

Instance methods

clear_distinct

Remove distinct

Source
clear_force_select
Source
clear_select
Source
distinct(on : String | Nil = "")

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) ...
Source
distinct_value
Source
force_select(c : Column)
Source
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")
query.select("a, b").to_sql # => Output "SELECT a, b, id"
query.clear_select.to_sql   # => Output "SELECT *, id"
Source
force_select
Source
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"
Source
select
Source
set_default_table_wildcard(table : String | Nil = 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. ameba:disable Naming/AccessorMethodName

Source