Tyrion Build Status

A small JSON ODM.

Goal

Tyrion's goal is to provide a fast (as in easy to setup) and dirty unstructured document store.

Usage

Connection

Tyrion uses a folder to store JSON files, one for each Tyrion document defined. Each file is an array of homogeneous documents (much like collections).

  Tyrion::Connection.path = "/a/folder"

Document

It supports validations from ActiveModel::Validations.

  class Post
    include Tyrion::Document

    field :title
    field :body
    field :rank

    validates_presence_of :title, :body, :rank
  end

Persistence

Save

  post = Post.new :title => "Hello", :body => "Hi there, ..."
  post.save
  Post.create :title => "Hello", :body => "Hi there, ..."

Delete

  post = Post.create :title => "Hello", :body => "Hi there, ..."
  post.delete
  Post.delete_all

Querying

Chainable querying is allowed.
First called is first executed and an enumerable is returned.

where: all matching documents

  Post.where :title => 'Hello', :rank => 3

limit: limits returned documents

  Post.limit(5)

skip: offsets returned documents

  Post.skip(5)

asc: sorts ascendingly according to passed keys

  Post.asc(:rank, :title)

desc: sorts discendingly according to passed keys

  Post.desc(:rank, :title)

Fancy chains

  Post.where(:rank => 5).desc(:title, :body).skip(5).limit(5)

And since it delegates to an enumerable...

  Post.where(:rank => 5).count
  Post.where(:rank => 10).each{ |doc| ... }

ToDos

  • Modifiers on criterias (delete, update, ...)
  • Default values for attributes
  • Embedded documents
  • Keys (_id?)