Shard Detail

rethinkdb-orm v0.1.0

RethinkDB ORM for Crystal lang

Install & Use

Add the following code to your project's shard.yml under:

dependencies to use in production
- OR -
development_dependencies to use in development


rethinkdb-orm:
  github: spider-gazelle/rethinkdb-orm
  version: 0.1.0

Readme

RethinkDB ORM for Crystal Lang

Build Status

Extending ActiveModel for attribute definitions and validations

Callbacks

Register callbacks for save, update, create and destroy by setting the corresponding before/after callback handler.

class ModelWithCallbacks < RethinkORM::Base
  attribute address : String
  attribute age : Int32 = 10

  before_create :set_address
  after_update :set_age
  before_destroy do
    self.name = "joe"
  end

  def set_address
    self.address = "23"
  end

  def set_age
    self.age = 30
  end
end

Associations

Set associations with belongs_to and has_many.

Access children in parent by accessing the method correpsonding to the pluralised child. Children collection method name is generated by dumb pluralisation (appending an s). Optionally set children collection name in has_many by setting collection_name param.

class Parent < RethinkORM::Base
  attribute name : String
  has_many Child, collection_name: "children"
end

class Child < RethinkORM::Base
  attribute age : Int32
  belongs_to Parent
  has_many Pet
end

class Pet < RethinkORM::Base
  attribute name : String
  belongs_to Child
end

parent = Parent.new(name: "Phil")
parent.children.empty? # => true

child = Child.new(age: 99)
child.pets.empty? # => true

Dependency

dependent param in the association definition macros defines the fate of the association on model destruction.
Default is :none, :destroy and :delete ensure destruction of association dependents.

Through Relation

In progress..

Changefeeds

In progress...