class
Prostore::Query::Builder(T)
- Prostore::Query::Builder(T)
- Reference
- Object
Overview
Chainable query builder. Each chained call returns a new builder with
one extra clause; the original is unchanged. Materialization happens
via #to_a, #each, #first, #count, etc.
Generic over T (the model instance type the builder yields). The
macro query :name, ->(...) { ... } emits a class method that
constructs a Builder(self) and runs the lambda body inside a
with builder block, so #where(...), order_by(...) etc. inside
the lambda dispatch to the builder.
Defined in:
prostore/query/builder.crConstructors
Instance Method Summary
- #adapter : Adapter::Base
- #count : Int64
- #db : DB::Database
- #each(&) : Nil
- #empty? : Bool
- #exists? : Bool
- #field_names : Array(String)
- #first : T | Nil
- #first! : T
-
#in_query(&)
Inside-block builder for the macro-emitted class methods.
-
#joins(target_table : String, source_columns : Array(String), target_columns : Array(String)) : Builder(T)
Explicit join with caller-supplied source/target column lists.
-
#joins(target_class : Prostore::Model.class, fk_tag : Int32 | Nil = nil) : Builder(T)
FK-resolved join.
- #limit(n : Int32) : Builder(T)
- #offset(n : Int32) : Builder(T)
- #order_by(field : Symbol | String, desc : Bool = false) : Builder(T)
-
#select(*fields : Symbol | String) : Builder(T)
Project only the named columns in the resulting SELECT (ADR-0014).
- #table : String
- #to_a : Array(T)
- #where(predicate : AST::Predicate) : Builder(T)
- #where(**kwargs) : Builder(T)
Constructor Detail
Instance Method Detail
Inside-block builder for the macro-emitted class methods. The
with builder yield makes naked #where(...) etc. inside the
lambda body resolve to instance methods on the builder.
Explicit join with caller-supplied source/target column lists.
FK-resolved join. Looks for a foreign key linking T (the source
model) and target_class. If multiple FKs exist between the two,
fk_tag disambiguates.
Resolution rules:
- FK on the target references the source (e.g.,
User.joins(Order)where Order hasforeign_key … references: User): ON source.pk = target.fk_columns - FK on the source references the target (e.g.,
Order.joins(User)): ON source.fk_columns = target.pk - Neither found → raise
Prostore::Error.
Project only the named columns in the resulting SELECT (ADR-0014). Materialized instances will have only the projected fields populated; other ivars stay nil and accessing a non-projected non-nullable field raises (per the model's standard accessor semantics).