Home

Awesome

Epiphy

A persistence framework for RethinkDB. The library is used on phim365.today. Its API is inspired by Lotus::Model.

Epiphy is name after Epiphyllum, my wife's name.

Status

wercker status

Book Simply RethinkDB

I also write this book to practice RethinkDB. Please consider buying a copy if you want to support the author.

I love Lotus::Model so much because it's lightweight, does the job, no magic. I also should fork Lotus and add RethinkDB adapter. However, I want to learn more Ruby and reinvent the wheel because I didn't know how the wheel was created. More than that, my bad code will not be able to make it to Lotus::Model.

Philosophy

Does basic thing well and leave complex query to RethinkDB.

RethinkDB query is very good. By wrapping an ORM around it, we can destroy the joy of using ReQL. I only want to do basic thing with RethinkDB, the complex query should be done use ReQL. The result of query is converted back to an entity of an array of entity when possible.

API

RethinkDB delivers a convenient public API to execute queries and commands against a database. The architecture eases keeping the business logic (entities) separated from details such as persistence or validations.

It implements the following concepts:

Install

gem install epiphy

or add

gem 'epiphy'

to your Gemfile if you use Bundle. Run bundle install

Testing

Minitest is used for testing.

Make sure you have a working RethinkDB with default connection information that is localhost, port 28015, without authentication key and run

$ bundle install
$ rake test

A testing database will be created during the testing. The testing data will hit your RethinkDB. Depend on your storge system, test can be fast or slow.

Usage

Checkout Examples.md for detail guide and examples folder for real code.

Entities

An object that is defined by its identity.

An entity is the core of an application, where the part of the domain logic is implemented. It's a small, cohesive object that expresses coherent and meaningful behaviors.

It deals with one and only one responsibility that is pertinent to the domain of the application, without caring about details such as persistence or validations.

This simplicity of design allows developers to focus on behaviors, or message passing if you will, which is the quintessence of Object Oriented Programming.

Setup

connection = Epiphy::Connection.create
adapter    = Epiphy::Adapter::RethinkDB.new connection
RethinkDB::Repository.configure do |r|
  r.adapter = adapter 
end

Define your entity

class Movie
  include Epiphy::Entity

  self.attributes= :title, :url, :type
end

Define your repository

class MovieRepository
  include Epiphy::Repository  
end

Query


movie = MovieRepository.find id # Find by id

movie = MovieRepository.first :created_at # Find first entity, order by field :date
movie = MovieRepository.last :created_at  # Find first entity, order by field :date

movie = Movie.new
movie.title = "A movie"
MovieRepository.create movie
puts movie.id # return the ID of inserted movie

movie.title = "A new title"
MovieRepository.update movie

movie = Movie.new title: 'Another one', url: "http://youtube.com/foo", type: 'anime'
movie.id = Time.now.to_i #Manually assign an id
MovieRepository.create movie

Custom query

From inside a Repository, we can call query method and pass in a block. The method expose two object

class MovieRepository
  
  def lop
  end
end

Contributing to epiphy

Copyright

Copyright (c) 2014 kureikain. See LICENSE.txt for further details.