abstract class Prostore::Model

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.cr
prostore/model.cr

Class Method Summary

Macro Summary

Instance Method Summary

Class Method Detail

def self.__prostore_builder_for(model_class : T.class) forall T #

Build a query Builder for the given model class using the default Prostore connection. Used by macro-emitted class methods.


[View source]

Macro Detail

macro field(tag, name, type, **opts) #

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


[View source]
macro foreign_key(tag, columns, **opts) #

foreign_key tag, [:cols], references: TargetClass, ...


[View source]
macro index(tag, columns, **opts) #

index tag, [:cols], unique: false, where: SQL.expr(...), name: "..."


[View source]
macro query(name, lambda) #

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.


[View source]
macro reserved(tag) #

reserved tag — permanently retire a field tag (ADR-0002).


[View source]
macro reserved_foreign_key(tag) #

[View source]
macro reserved_index(tag) #

[View source]
macro sequence(*args, **kwargs) #

Reserved DSL keyword for future standalone sequences (ADR-0013). Currently excluded; only auto_increment: true on integer PKs is supported.


[View source]
macro table_name(name) #

table_name "users" — overrides the default snake-case derivation.


[View source]

Instance Method Detail

def __prostore_mark_persisted! : Nil #

[View source]
def persisted? : Bool #

[View source]