abstract class
Prostore::Model
- Prostore::Model
- Reference
- Object
Overview
Base class for all prostore-managed models.
Subclasses declare their schema in the class body via the macros installed
by inherited and the macros defined in macros.cr. At compile time, a
Prostore::Schema::Definition value is built and exposed as
Class.prostore_schema.
Defined in:
prostore/macros.crprostore/model.cr
Class Method Summary
-
.__prostore_builder_for(model_class : T.class) forall T
Build a query Builder for the given model class using the default Prostore connection.
Macro Summary
-
field(tag, name, type, **opts)
field tag, :name, Type, **opts -
foreign_key(tag, columns, **opts)
foreign_key tag, [:cols], references: TargetClass, ... -
index(tag, columns, **opts)
index tag, [:cols], unique: false, where: SQL.expr(...), name: "..." -
query(name, lambda)
query :name, ->(args) { body } -
reserved(tag)
reserved tag— permanently retire a field tag (ADR-0002). - reserved_foreign_key(tag)
- reserved_index(tag)
-
sequence(*args, **kwargs)
Reserved DSL keyword for future standalone sequences (ADR-0013).
-
table_name(name)
table_name "users"— overrides the default snake-case derivation.
Instance Method Summary
Class Method Detail
Build a query Builder for the given model class using the default Prostore connection. Used by macro-emitted class methods.
Macro Detail
field tag, :name, Type, **opts
Options (ADR-0011, 0013, 0014): primary: Bool (default false) auto_increment: Bool (default false; requires Int32/Int64 + primary) default: SQL.expr | Proc (new-row strategy) backfill: SQL.expr | Proc (existing-row strategy) lazy: Proc (mutex with default: / backfill:; requires T?)
index tag, [:cols], unique: false, where: SQL.expr(...), name: "..."
query :name, ->(args) { body }
The lambda body is walked as an AST chain; each method call becomes a
Schema::Call record consumed by Query::Analyzer for index planning.
Reserved DSL keyword for future standalone sequences (ADR-0013).
Currently excluded; only auto_increment: true on integer PKs is
supported.