class

Prostore::Query::Builder(T)

Inherits Reference < Object

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.

Constructors

new(table : String, field_names : Array(String), materializer : DB::ResultSet -> T, adapter : Adapter::Base, db : DB::Database, plan : Renderer::Plan = Renderer::Plan.new, partial_materializer : DB::ResultSet, Array(String) -> T | Nil = nil)
Source

Instance methods

adapter
Source
count
Source
each
Source
empty?
Source
exists?
Source
field_names
Source
first
Source
first!
Source
in_query

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.

Source
joins(target_table : String, source_columns : Array(String), target_columns : Array(String)) : Builder(T)

Explicit join with caller-supplied source/target column lists.

Source
joins(target_class : Prostore::Model.class, fk_tag : Int32 | Nil = nil) : Builder(T)

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:

  1. FK on the target references the source (e.g., User.joins(Order) where Order has foreign_key … references: User): ON source.pk = target.fk_columns
  2. FK on the source references the target (e.g., Order.joins(User)): ON source.fk_columns = target.pk
  3. Neither found → raise Prostore::Error.
Source
limit(n : Int32) : Builder(T)
Source
offset(n : Int32) : Builder(T)
Source
order_by(field : Symbol | String, desc : Bool = false) : Builder(T)
Source
select(*fields : Symbol | String) : Builder(T)

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).

Source
table
Source
to_a
Source
where(predicate : AST::Predicate) : Builder(T)
Source
where
Source