class

MongrelDB::QueryBuilder

Inherits Reference < Object

QueryBuilder builds a request for the daemon's /kit/query endpoint, where conditions push down to the engine's specialized indexes.

Condition parameters accept friendly aliases that are translated to the server's exact on-wire keys before sending (see #where).

Example:

rows = db.query("orders")
  .where("bitmap_eq", {"column" => 2, "value" => "electronics"})
  .where("range_f64", {"column" => 3, "min" => 100.0})
  .projection([1, 2, 3])
  .limit(50)
  .execute

if db.query("orders").truncated
  # result set hit the limit; more matches exist on the server
end

Constructors

new(client : Client, table : String)

Initialize a new QueryBuilder. Normally created via Client#query.

Source

Class methods

normalize_condition(type : String, params : Hash) : Hash(String, JSON::Any)

Translate friendly parameter aliases to the server's canonical on-wire keys. Both spellings are accepted, so callers may use whichever is clearer.

Source

Instance methods

build

Build the request payload that will be sent to /kit/query.

Source
execute

Run the query and return the matching rows. Also records whether the result was truncated by the limit; check it with #truncated.

Source
limit(limit : Int32 | Nil) : QueryBuilder

Cap the number of rows returned.

Source
offset(offset : Int64 | Nil) : QueryBuilder

Skip matching rows before applying the limit.

Source
projection(column_ids : Array(Int32) | Nil) : QueryBuilder

Set the column projection (column ids to return). nil means all columns.

Source
truncated?

Whether the most recent #execute result was capped by the limit. Returns false until #execute has been called.

Source
where(type : String, params : Hash) : QueryBuilder

Add a native condition (AND-ed). Friendly aliases (column -> column_id, min/max -> lo/hi) are accepted; the server's canonical keys are also accepted as-is.

Source