NOTE: How you store/supply each connection's URL is up to you; Granite only cares that it gets registered viaGranite::Connections << adapter_object
.
timestamps
macro defines created_at
and updated_at
field for you.column
macro with the primary: true
option to denote the primary key.NOTE: Composite primary keys are not yet supported.
belongs_to
associations can also be used as a primary key in much the same way.id : Int64
.auto: false
option.UUID
. This will generate a secure UUID when the model is saved.crystal docs
will not include Granite methods, constants, and properties. To include these, use the granite_docs
flag when generating the documentation. E.x. crystal docs -D granite_docs
.column
macro.property
keyword for its columns, annotations are able to be applied easily. These can either be JSON::Field
, YAML::Field
, or third party annotations.T
generic argument that tells the converter what type should be read from the DB::ResultSet
. For example, if you wanted to use the JSON
converter and your underlying database column is BLOB
, you would use Bytes
, if it was TEXT
, you would use String
.Enum(E, T)
- Converts an Enum of type E
to/from a database column of type T
. Supported types for T
are: Number
, String
, and Bytes
.Json(M, T)
- Converters an Object
of type M
to/from a database column of type T.
Supported types for T
are: String
, JSON::Any
, and Bytes
.M
must implement #to_json
and .from_json
methods.PgNumeric
- Converts a PG::Numeric
value to a Float64
on read.OrderStatus
enum typed field. When saved, the enum value would be converted to a string to be stored in the DB. Then, when read, the string would be used to parse a new instance of OrderStatus
.#to_json
/#to_yaml
and .from_json
/.from_yaml
methods.