Prostore::Records
Record-layer helpers shared by every model class.
The Prostore::Model.__prostore_run_backfill macro emits a call into
this module to perform a chunked Crystal-lambda backfill. Splitting the
loop into a free function keeps the per-model macro emission small.
Constants
Instance methods
Array coercion: JSON-encode the array. Crystal generics require a
forall overload because Array(T) can't appear in a regular union.
Enum coercion (ADR-0016, ADR-0017). Dispatches on the portable tag:
enum_int stores the underlying integer (Int64-promoted),
enum_string stores the wire form derived from the source-level name
via the field's naming: algorithm (defaults to :as_declared,
which preserves the PascalCase Crystal identifier verbatim). The
reverse trip lives in the macro-emitted ___assign_from_rs.
INSERT a row from explicit column/value lists. If auto_increment_pk
is supplied, the column is omitted from the INSERT and the new ID is
returned via adapter.insert_returning_id. Otherwise the call returns
nil and the caller is responsible for whatever PK ergonomics fit.
Returns the JSON-encoded array body as a String, regardless of which
backend produced it (SQLite stores JSON in TEXT; Postgres returns
JSONB as a JSON::PullParser). The macro-emitted caller does the
per-row Array(T).from_json(string) step on the result.
Read an Int64? from a result set, accepting any integer-typed wire
form. SQLite returns INTEGER columns as Int64 already; Postgres may
return Int32 for narrower column types. Used by the enum_int reader to
stay agnostic to the live column width.
Walk the table in chunks, invoking lambda on each row. The
WHERE col IS NULL filter is the correctness invariant from
ADR-0009 invariant 3 — re-running the loop is a no-op for already-
populated rows, which makes the operation idempotent under retry.