module
Lustra::SQL::SelectBuilder
Included Modules
- Lustra::SQL::Query::Aggregate
- Lustra::SQL::Query::BeforeQuery
- Lustra::SQL::Query::Change
- Lustra::SQL::Query::Connection
- Lustra::SQL::Query::CTE
- Lustra::SQL::Query::Execute
- Lustra::SQL::Query::Fetch
- Lustra::SQL::Query::From
- Lustra::SQL::Query::GroupBy
- Lustra::SQL::Query::Having
- Lustra::SQL::Query::Join
- Lustra::SQL::Query::Lock
- Lustra::SQL::Query::OffsetLimit
- Lustra::SQL::Query::OrderBy
- Lustra::SQL::Query::Pluck
- Lustra::SQL::Query::Select
- Lustra::SQL::Query::Where
- Lustra::SQL::Query::Window
- Lustra::SQL::Query::WithPagination
Direct including types
Defined in:
lustra/sql/select_builder.crConstructors
Instance Method Summary
-
#before_query(&block : -> Nil)
A hook to apply some operation just before the query is executed.
- #columns : Array(SQL::Column)
- #default_wildcard_table
-
#dup : self
Duplicate the query
- #havings : Array(Lustra::Expression::Node)
- #is_distinct?
- #joins : Array(SQL::Join)
- #limit : Int64 | Nil
- #lock : String | Nil
- #offset : Int64 | Nil
- #order_bys : Array(Lustra::SQL::Query::OrderBy::Record)
-
#to_delete
Construct a delete query from this select query.
- #to_sql : String
- #to_update
- #total_entries : Int64 | Nil
- #total_entries=(total_entries : Int64 | Nil)
-
#wheres : Array(Lustra::Expression::Node)
Return the list of where clause; each where clause are transformed into Lustra::Expression::Node
Instance methods inherited from module Lustra::SQL::Query::WithPagination
current_page : Int32 | Int64
current_page,
first_page?
first_page?,
last_page?
last_page?,
next_page
next_page,
out_of_bounds?
out_of_bounds?,
paginate(page : Int32 = DEFAULT_PAGE, per_page : Int32 = DEFAULT_LIMIT)
paginate,
per_page : Int32 | Int64
per_page,
previous_page
previous_page,
total_pages : Int32 | Int64
total_pages
Instance methods inherited from module Lustra::SQL::Query::Change
change! : self
change!
Instance methods inherited from module Lustra::SQL::Query::Connection
connection_name : String
connection_name,
use_connection(connection_name : String)
use_connection
Instance methods inherited from module Lustra::SQL::Query::Pluck
pluck(fields : Tuple(*T)) forall Tpluck(*fields) : Array
pluck(**fields : **T) forall T pluck, pluck_col(field : Lustra::SQL::Symbolic, type : T.class) : Array(T) forall T
pluck_col(field : Lustra::SQL::Symbolic) : Array(Lustra::SQL::Any) pluck_col
Instance methods inherited from module Lustra::SQL::Query::Fetch
fetch(fetch_all = false, & : Hash(String, Lustra::SQL::Any) -> Nil)
fetch,
fetch_first
fetch_first,
fetch_first!
fetch_first!,
fetch_with_cursor(count = 1000, & : Hash(String, Lustra::SQL::Any) -> Nil)
fetch_with_cursor,
first
first,
first!
first!,
scalar(type : T.class) forall T
scalar,
to_a : Array(Hash(String, Lustra::SQL::Any))
to_a
Instance methods inherited from module Lustra::SQL::Query::Execute
execute(connection_name : String | Nil = nil)
execute,
execute_and_count(connection_name : String | Nil = nil) : Int64
execute_and_count,
explain(connection_name : String | Nil = nil) : String
explain,
explain_analyze(connection_name : String | Nil = nil) : String
explain_analyze
Instance methods inherited from module Lustra::SQL::Query::Lock
with_lock(str : String = "FOR UPDATE")
with_lock
Instance methods inherited from module Lustra::SQL::Query::Window
clear_windows
clear_windows,
print_windows
print_windows,
window(name, value)window(windows : NamedTuple) window, windows : Array(WindowDeclaration) windows
Instance methods inherited from module Lustra::SQL::Query::CTE
cte : Hash(String, CTEAuthorized)
cte,
with_cte(name, request : CTEAuthorized)with_cte(tuple : NamedTuple) with_cte
Instance methods inherited from module Lustra::SQL::Query::Aggregate
agg(field, x : X.class) forall X
agg,
avg(field, x : X.class) forall X
avg,
count(type : X.class = Int64) forall X
count,
exists? : Bool
exists?,
max(field, x : X.class) forall X
max,
min(field, x : X.class) forall X
min,
sum(field) : Float64
sum
Instance methods inherited from module Lustra::SQL::Query::OffsetLimit
clear_limit
clear_limit,
clear_offset
clear_offset,
limit(x : Int | Nil)
limit,
offset(x : Int | Nil)
offset
Instance methods inherited from module Lustra::SQL::Query::GroupBy
clear_group_bys
clear_group_bys,
group_by(column : Symbolic)
group_by,
group_bys : Array(Symbolic)
group_bys
Instance methods inherited from module Lustra::SQL::Query::OrderBy
clear_order_bys
clear_order_bys,
order_by(tuple : NamedTuple)order_by(expression : Symbol, direction : Symbol = :asc, nulls : Symbol | Nil = nil)
order_by(expression : String, direction : Symbol = :asc, nulls : Symbol | Nil = nil)
order_by(**tuple) order_by, reverse_order_by reverse_order_by
Instance methods inherited from module Lustra::SQL::Query::Having
clear_havings
clear_havings,
having(node : Lustra::Expression::Node)having(&)
having(conditions : NamedTuple | Hash(String, Lustra::SQL::Any))
having(template : String, *args)
having(template : String, **tuple)
having(**tuple) having, or_having(node : Lustra::Expression::Node)
or_having(template : String, *args)
or_having(template : String, **named_tuple)
or_having(&) or_having
Instance methods inherited from module Lustra::SQL::Query::Where
clear_wheres
clear_wheres,
not(&)not(conditions : NamedTuple | Hash(String, Lustra::SQL::Any))
not(template : String)
not(template : String, *args)
not(template : String, **tuple)
not(**tuple) not, or(node : Lustra::Expression::Node)
or(&)
or(conditions : NamedTuple | Hash(String, Lustra::SQL::Any))
or(template : String, *args)
or(template : String, **tuple)
or(**tuple) or, where(node : Lustra::Expression::Node)
where(&)
where(conditions : NamedTuple | Hash(String, Lustra::SQL::Any))
where(template : String)
where(template : String, *args)
where(template : String, **tuple)
where(**tuple) where
Instance methods inherited from module Lustra::SQL::Query::Join
cross_join(name : Selectable, lateral = false)
cross_join,
full_outer_join(name : Selectable, lateral = false, &)full_outer_join(name : Selectable, condition : String = "true", lateral = false) full_outer_join, inner_join(name : Selectable, lateral = false, &)
inner_join(name : Selectable, condition : String = "true", lateral = false) inner_join, join(name : Selectable, type = :inner, lateral = false, &)
join(name : Selectable, type = :inner, condition : String = "true", lateral = false)
join(name : Selectable, type = :inner, lateral = false) join, left_join(name : Selectable, lateral = false, &)
left_join(name : Selectable, condition : String = "true", lateral = false) left_join, right_join(name : Selectable, lateral = false, &)
right_join(name : Selectable, condition : String = "true", lateral = false) right_join
Instance methods inherited from module Lustra::SQL::Query::From
clear_from
clear_from,
from(*args)from(**tuple) from, froms : Array(SQL::From) froms
Instance methods inherited from module Lustra::SQL::Query::Select
clear_distinct
clear_distinct,
clear_select
clear_select,
default_wildcard_table=(table : String | Nil = nil)
default_wildcard_table=,
distinct(on : String | Nil = "")
distinct,
distinct_value : String | Nil
distinct_value,
select(c : Column)select(*args) select
Constructor Detail
def self.new(distinct_value = nil, cte = {} of String => Lustra::SQL::SelectBuilder | String, columns = [] of SQL::Column, froms = [] of SQL::From, joins = [] of SQL::Join, wheres = [] of Lustra::Expression::Node, havings = [] of Lustra::Expression::Node, windows = [] of ::Tuple(String, String), group_bys = [] of Symbolic, order_bys = [] of Lustra::SQL::Query::OrderBy::Record, limit = nil, offset = nil, lock = nil, before_query_triggers = [] of (-> Nil))
#
Instance Method Detail
def before_query(&block : -> Nil)
#
A hook to apply some operation just before the query is executed.
call = 0
req = Lustra::SQL.select("1").before_query { call += 1 }
10.times { req.execute }
pp call # 10
def to_delete
#
Construct a delete query from this select query.
It uses only the from
and the where
clause fo the current select request.
Can be useful in some case, but
use at your own risk !
def wheres : Array(Lustra::Expression::Node)
#
Return the list of where clause; each where clause are transformed into Lustra::Expression::Node