Project

tyrion

0.0
No commit activity in last 3 years
No release in over 3 years
Tyrion's goal is to provide a fast (as in _easy to setup_) and dirty unstructured document store.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

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?)