abstract class Jennifer::QueryBuilder::IModelQuery

Included Modules

Direct Known Subclasses

Defined in:

jennifer/query_builder/i_model_query.cr

Instance Method Summary

Instance methods inherited from module Jennifer::QueryBuilder::EagerLoading

_select_fields : Array(Criteria) _select_fields, eager_load(*names, **deep_relations) eager_load, includes(*names, **deep_relations) includes, multi_query_relation_tree multi_query_relation_tree, nested_relation_tree : NestedRelationTree nested_relation_tree, preload(*names, **deep_relations) preload, with_relation(names : Array)
with_relation(*names)
with_relation

Instance methods inherited from class Jennifer::QueryBuilder::Query

_select_fields : Array(Criteria) _select_fields, adapter : Adapter::Base adapter, as_sql(generator)
as_sql
as_sql
, clone clone, distinct distinct, do_nothing? : Bool do_nothing?, empty? empty?, eql?(other : Query)
eql?(other : Statement | LogicOperator)
eql?
, except(parts : Array(String)) except, exec(&) exec, expression_builder : Jennifer::QueryBuilder::ExpressionBuilder expression_builder, filterable? filterable?, from(from : String | Query) from, group(column : String)
group(column : Symbol)
group(column : Criteria)
group(*columns : String)
group(*columns : Symbol)
group(&)
group
, having(&) having, limit(count : Int32) limit, lock(type : String | Bool = true) lock, merge(other : self) merge, none none, offset(count : Int32) offset, select(raw_sql : String)
select(field : Criteria)
select(fields : Array(Criteria))
select(*fields : Symbol)
select(&)
select
, set_tree(other : LogicOperator | Condition)
set_tree(other : Query)
set_tree(other : SQLNode)
set_tree(other : Nil)
set_tree
, sql_args : Array(DBAny) sql_args, table : String table, to_json(only : Array(String)? = nil, except : Array(String)? = nil, &)
to_json(json : JSON::Builder)
to_json(json : JSON::Builder, only : Array(String)? = nil, except : Array(String)? = nil, &)
to_json(only : Array(String)? = nil, except : Array(String)? = nil)
to_json
, to_s(io : IO) to_s, tree : Condition | LogicOperator | Nil tree, tree=(tree : Condition | LogicOperator | Nil) tree=, union(query, all : Bool = false) union, where(&)
where(conditions : Hash(Symbol, _))
where
, with(name : String | Symbol, query : Query, recursive : Bool = false) with

Constructor methods inherited from class Jennifer::QueryBuilder::Query

new(table, adapter = Adapter.default_adapter)
new
new

Class methods inherited from class Jennifer::QueryBuilder::Query

[](*args) [], build(*args) build, null(table = "") null

Instance methods inherited from module Jennifer::QueryBuilder::Executables

db_results : Array(Hash(String, DBAny)) db_results, decrement(fields : Hash(Symbol, _))
decrement(**fields)
decrement
, delete delete, each(&) each, each_result_set(&) each_result_set, exists? : Bool exists?, explain : String explain, find_each(primary_key : String, batch_size : Int32 = 1000, start = nil, direction : String | Symbol = "asc", &)
find_each(primary_key : Criteria, batch_size : Int32 = 1000, start = nil, direction : String | Symbol = "asc", &)
find_each(primary_key : Nil, batch_size : Int32 = 1000, start : Int32 = 0, direction : String | Symbol = "asc", &)
find_each(batch_size : Int32 = 1000, start : Int32 = 0, direction : String | Symbol = "asc", &)
find_each
, find_in_batches(primary_key : String, batch_size : Int32 = 1000, start : Int32? = nil, direction : String | Symbol = "asc", &)
find_in_batches(batch_size : Int32 = 1000, start : Int32 = 0, &)
find_in_batches(primary_key : Criteria, batch_size : Int32 = 1000, start = nil, direction : String | Symbol = "asc", &)
find_in_batches(primary_key : Nil, batch_size : Int32 = 1000, start : Int32 = 0, &)
find_in_batches
, find_records_by_sql(query : String, args : Array(DBAny) = [] of DBAny) find_records_by_sql, first first, first! first!, ids ids, increment(fields : Hash(Symbol, _))
increment(**fields)
increment
, insert(fields : Array(String), values : Array(Array(DBAny)))
insert(options : Hash(String | Symbol, DBAny) | NamedTuple)
insert
, last last, last! last!, pluck(fields : Array) : Array(Array(DBAny))
pluck(field : String | Symbol) : Array(DBAny)
pluck(*fields : String | Symbol) : Array(Array(DBAny))
pluck(**types : **T) forall T
pluck
, results : Array(Record) results, to_a to_a, update(&)
update(options : Hash)
update(**options)
update
, upsert(fields : Array(String), values : Array(Array(DBAny)), unique_fields : Array = [] of String)
upsert(fields : Array(String), values : Array(Array(DBAny)), unique_fields : Array, &)
upsert

Instance methods inherited from module Jennifer::QueryBuilder::Joining

join(source : Class, table_alias : String? = nil, type = :inner, relation : String? = nil, &)
join(source : String, table_alias : String? = nil, type = :inner, relation : String? = nil, &)
join(source : Query, table_alias : String, type = :inner, &)
join
, lateral_join(source : Query, table_alias : String, type = :inner, &) lateral_join, left_join(source : Class, table_alias : String? = nil, &)
left_join(source : String, table_alias : String? = nil, &)
left_join
, right_join(source : Class, table_alias : String? = nil, &)
right_join(source : String, table_alias : String? = nil, &)
right_join

Instance methods inherited from module Jennifer::QueryBuilder::Ordering

order(opts : Hash(String, String | Symbol))
order(opts : Hash(Symbol, String | Symbol))
order(opt : OrderExpression)
order(opts : Array(OrderExpression))
order(opts : Hash(String | Symbol, String | Symbol))
order(**opts)
order(&)
order
, ordered? ordered?, reorder(opts : Hash(String, String | Symbol))
reorder(opts : Hash(Symbol, String | Symbol))
reorder(opt : OrderExpression)
reorder(opts : Array(OrderExpression))
reorder(opts : Hash(String | Symbol, String | Symbol))
reorder(**opts)
reorder(&)
reorder

Instance methods inherited from module Jennifer::QueryBuilder::Aggregations

avg(field, klass : T.class) : T forall T avg, count : Int32 count, group_avg(field, klass : T.class) : Array(T) forall T group_avg, group_count(field) group_count, group_max(field, klass : T.class) : Array(T) forall T group_max, group_min(field, klass : T.class) : Array(T) forall T group_min, group_sum(field, klass : T.class) : Array(T) forall T group_sum, max(field, klass : T.class) : T forall T max, min(field, klass : T.class) : T forall T min, sum(field, klass : T.class) : T forall T sum

Instance methods inherited from module Jennifer::QueryBuilder::Statement

as_sql(sql_generator) as_sql, filterable? filterable?, sql_args : Array(DBAny) sql_args

Instance Method Detail

def clone #

NOTE can't be abstract because is already implemented by super class.


[View source]
def destroy #

Triggers #destroy on the each matched object.

Contact.all.where { _name.like('%John%') }.destroy

[View source]
def find(id) #

Returns record by given primary field or nil otherwise.

Contact.all.find(-1) # => nil

[View source]
def find!(id) #

Returns record by given primary field or raises Jennifer::RecordNotFound exception otherwise.

Contact.all.find!(-1) # Jennifer::RecordNotFound

[View source]
def find_each(batch_size : Int32 = 1000, start = nil, direction : String | Symbol = "asc", &) #

Yields each record in batches from #find_in_batches.

Looping through a collection of records from the database is very inefficient since it will instantiate all the objects at once. In that case batch processing methods allow you to work with the records in batches, thereby greatly reducing memory consumption.

Contact.all.where { _age > 21 }.find_each do |contact|
  puts contact.id
end

[View source]
def find_in_batches(batch_size : Int32 = 1000, start = nil, direction : String | Symbol = "asc", &) #

Yields each batch of records that was found by the specified query.

Contact.all.where { _age > 21 }.find_in_batches do |batch|
  batch.each do |contact|
    puts contact.id
  end
end

To get each record one by one use #find_each instead.

NOTE any given ordering will be ignored and query will be reordered based on the primary_key and direction.


[View source]
def model_class #

NOTE improperly detects source of #abstract_class if run sam with only Version model


[View source]
def patch(options : Hash | NamedTuple) #

Triggers #update on the each matched object.

As a result all callbacks and validations are invoked.

Contact.all.where { _name == "Ohn" }.patch({name: "John"})

[View source]
def patch(**opts) #

Triggers #update on the each matched object.

As a result all callbacks and validations are invoked.

Contact.all.where { _name == "Ohn" }.patch({name: "John"})

[View source]
def patch!(options : Hash | NamedTuple) #

Triggers #update! on the each matched object.

As a result all callbacks and validations are invoked. If any individual update raise exception - it will stop all following operations.

Contact.all.where { _name == "Ohn" }.patch!({name: "John"})

[View source]
def patch!(**opts) #

Triggers #update! on the each matched object.

As a result all callbacks and validations are invoked. If any individual update raise exception - it will stop all following operations.

Contact.all.where { _name == "Ohn" }.patch!({name: "John"})

[View source]
def relation(name, type = :left) #

Joins name relation.

You can specify join type passing it as 2nd argument.

Contact.all.relation(:addresses)

[View source]
def table #

Returns target table name.


[View source]