Permalink
Browse files

Add Ohm (Redis object-hash-mapper) to models

  • Loading branch information...
1 parent e6be638 commit 6230544a9baa313afcb23c101fac6aa4443d5a47 jamesmartin committed Feb 27, 2011
Showing with 45 additions and 0 deletions.
  1. +45 −0 models/ohm.md
View
45 models/ohm.md
@@ -0,0 +1,45 @@
+Ohm
+------------
+
+[Ohm](http://ohm.keyvalue.org/) is an object hash-mapping library for the [Redis](http://redis.io/) database.
+
+Require the Ohm gem in your app:
+
+ require 'rubygems'
+ require 'sinatra'
+ require 'ohm'
+
+Configure Ohm for your environment:
+
+ configure :production do
+ Ohm.connect(:url => ENV["MY_REDIS_URL"])
+ end
+
+Create a model class and a Redis index to allow fast lookups:
+
+ class Post < Ohm::Model
+ attribute :title
+ attribute :body
+ index :title
+ end
+
+Save a new instance of your model from a route:
+
+ post '/post' do
+ Post.create :title => params[:title],
+ :body => params[:body]
+ end
+
+Find and render instances of your model matching a criteria:
+
+ get '/posts/:title' do
+ @posts = Post.find(:title => params[:title])
+ erb :index
+ end
+
+This will render ./views/index.erb:
+
+ <% for post in @posts %>
+ <h1><%= post.title %></h1>
+ <% end %>
+

0 comments on commit 6230544

Please sign in to comment.