Skip to content

dorren/omnidata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

omnidata

warning: Currently in super alpha stage, everything's subjected to change.

Omnidata allows you to define your models in persistence agnostic fashion, so model can be saved in any database you like, mongodb, couchdb etc.

Gem uses Virtus for defining attributes.

For example, to define the database and model.

Omnidata.setup_database(:db1, {:adapter => 'mongodb', :database => 'mydb'})
Omnidata.setup_database(:db2, {:adapter => 'mongodb', :database => 'mydb2'})

class User
  include Omnidata::Model
  use_database :db1

  attribute :name, String
  attribute :age, Integer

  index :age
end

Typical query usage

user = User.new(:name => 'Jack Hunt', :age => 27)
user.save
User.find(user.id)

User.find  # return all users

User.count
User.find(:limit => 10, :skip => 10)    # paginated query

User.find(:order => :age)      # sort by age

Switch to another db temporarily.

User.with_database(:db2) do
  User.find(user.id)
end

About

persistence agnostic ORM

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages