annotation Onyx::SQL::Model::Options

Overview

This annotation specifies options for a Model. It has two mandatory options itself:

@[Onyx::SQL::Options(table: "users", primary_key: @id)]
class User
  include Onyx::SQL::Model
  @id : Int32?
end

The Model.schema macro defines the Options annotation for you:

class User
  include Onyx::SQL::Model

  schema users do   # "users" is going to be the :table option
    pkey id : Int32 # @id is the :primary_key
  end
end

TODO Handle different :primary_key variants:

@[Options(primary_key: {@a, @b})] # Composite

@[Options(primary_key: {x: @a, y: @b})] # With different getters (and composite)
class User
  def x
    @a
  end
end

Defined in:

onyx-sql/model.cr