Tyrion
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
class Post
include Tyrion::Document
field :title
field :body
field :rank
end
Persistence
Save
post = Post.create :title => "Hello", :body => "Hi there, ..."
post.save
# Insta-save with !
Post.create! :title => "Hello", :body => "Hi there, ..."
Delete
post = Post.create :title => "Hello", :body => "Hi there, ..."
post.delete
Post.delete_all # You get the idea
Post.delete :title => /^Hello/
Querying
find_by_attribute
: just the first match
Post.find_by_title "Hello"
Post.find_by_body /^Hi there/i
where
: all matching documents
Post.where :title => /^Hello/, :rank => 3