This post originated from an RSS feed registered with Ruby Buzz
by Jonathan Weiss.
Original Post: SimplyStored and CouchDB
Feed Title: BlogFish
Feed URL: http://blog.innerewut.de/feed/atom.xml
Feed Description: Weblog by Jonathan Weiss about Unix, BSD, security, Programming in Ruby, Ruby on Rails and Agile Development.
There is a recording of the presentation at ustream.tv.
Mathias and I wrote SimplyStored in order to easily interact with Ruby objects serialized in CouchDB. We use CouchDB as the main data store for Scalarium and so far it has been great. But it is a bit cumbersome to write all those map and reduce functions yourself.
SimplyStored generates the JavaScript map&reduce functions for handling associations or dynamic finders for you.
SimplyStored offers:
Models
Associations
Callbacks
Validations
Dynamic finder
S3 attachments
Paranoid delete
class User
include SimplyStored::Couch
property :login
property :age
property :accepted_terms_of_service, :type => :boolean
property :last_login, :type => Time
end
user = User.new(:login => 'Bert',
:age => 12,
:accepted_terms_of_service => true,
:last_login = Time.now)
user.save
User.find_by_age(12).login
# => 'Bert'
User.all
# => [user]
class Post
include SimplyStored::Couch
property :title
property :body
belongs_to :user
end
class User
has_many :posts
end
post = Post.create(:title => 'My first post',
:body => 'SimplyStored is so nice!',
:user => user)
user.posts
# => [post]
Post.find_all_by_title_and_user_id('My first post', user.id).first.body
# => 'SimplyStored is so nice!'
post.destroy
user.posts(:force_reload => true)
# => []
Another thing I talked about is RockingChair. RockingChair is an in-memory CouchDB implementation that understands all of SimplyStored's functionality. We use it to speed up our tests and be able to run them in parallel.