module Onyx::SQL::Model::Mappable(T)


This module allows to map a Model to the database.

Defined in:


Class Method Summary

Class Method Detail

def self.db_column(variable : T::Field | T::Reference) : String #

Return a instance variable SQL column name.

User.db_column(:id)      # "id"
User.db_column(:unknown) # Compilation-time error

[View source]
def self.db_values(**values : **U) : Tuple forall U #

Return a Tuple of DB-ready values. It respects Field and Reference annotations, also working with Converters.

It ignores not_null option. It will call .not_nil! on enumerable references' primary keys, thus can raise NilAssertionError.

User.db_values(id:  # => {42}
User.db_values(foo: "bar")   # => Compilation-time error: unknown User instance variable foo
Post.db_values(author: user) # => May raise NilAssertionError if `` is `nil`

[View source]