MongrelDB::Client
Client is the MongrelDB HTTP client. Create one with Client.new and a
base URL, then use its methods for health, table management, CRUD, query,
SQL, schema, and maintenance.
A Client is safe for concurrent use by multiple fibers once configured --
each request builds its own HTTP::Client.
Constructors
Create a new MongrelDB client.
url- daemon base URL (e.g.http://127.0.0.1:8453). Defaults toDEFAULT_BASE_URLwhen empty.token- bearer token (--auth-tokenmode). Takes precedence over basic-auth credentials when set.username/password- basic auth (--auth-usersmode).connect_timeout- seconds to wait for the connection to open.read_timeout- seconds to wait for one block of the response body.
Class methods
Convert a column-id-to-value map to the server's flat
[col_id, value, col_id, value, ...] array. Pair order is not
significant -- each value is preceded by its own column id.
Flatten a column-id-to-value map to the server's flat
[col_id, value, ...] array in ascending column-id order.
Stable ordering is required for idempotency keys: the server hashes the
request payload, and unordered hash iteration would make two commits of
the same cells look like a reuse mismatch.
Coerce a Crystal value into a JSON::Any for the request payload.
Accepts the native Crystal scalars and containers callers pass in (from
Cells/Column values as well as ad-hoc query-parameter literals).
Generic Array and Hash literals (e.g. ["a", "b"] typed as
Array(String)) are coerced element-wise so callers do not have to widen
them to Array(CellValue) themselves.
Instance methods
Begin a batch transaction. Operations are staged locally and committed
atomically in a single /kit/txn request.
Request cancellation of a running SQL query.
Commit a batch of staged operations atomically. Exposed for the
Transaction type; prefer Transaction#commit.
Create a table with constraints and full secondary-index definitions.
Create a table with a constraints block (uniques, foreign keys).
Create a table with typed columns. Returns the assigned table id.
Perform a GET request and return the Response, mapping HTTP errors to
typed exceptions.
Check whether the daemon is reachable and healthy. Returns true on a
successful /health request, false on any error.
Inspect the durable MVCC history window. Returns both
history_retention_epochs and earliest_retained_epoch.
Current number of commit epochs the daemon will retain for time travel.
Perform a DELETE request and return the Response.
(Named http_delete to avoid clobbering the typed CRUD method
delete(table, row_id) defined above.)
Perform a POST request with a JSON body (Content-Type: application/json)
and return the Response. A nil body sends an empty request.
Insert a row.
table- table name.cells- column id -> value pairs (e.g.{1 => 1, 2 => "Alice"}). Flattened to the server's[col_id, value, ...]array before sending.idempotency_key- when non-empty, makes the commit safe to retry.
Retained SQL status for durable recovery (GET /queries/{query_id}).
Text → embed → ANN retrieve (POST /kit/retrieve_text, 0.64+).
Start a hybrid SearchBuilder against table (POST /kit/search).
Set the durable MVCC history window. Requires ADMIN permission when the daemon runs with catalog authentication. Returns the post-update window.
Execute a SQL statement via the /sql endpoint, requesting JSON output.
The server returns a JSON array of row objects keyed by column name. For
statements that yield no rows (DDL/DML), an empty array is returned.
Upsert a row (insert or update on a primary-key conflict).
update_cells- values written on a primary-key conflict (nilmeans DO NOTHING).idempotency_key- idempotency key for safe retries.