Over the last week I've made improvements to Rhino, a Ruby ORM for HBase that I created a while ago, and I now want to share it with this list.

Post: http://qslack.com/2008/07/27/now-in-rhino/
Git: git clone git://github.com/sqs/rhino.git
Github: http://github.com/sqs/rhino/tree/master
Specs: http://github.com/sqs/rhino/tree/master/spec

I'd appreciate all the help and feedback I can get, from contributors, users, and anyone who has strong feelings about this ORM design. There's certainly a lot more work to be done.

Features
* Ruby
* Uses the Thrift API
* Basic get, put, scanning, deletion
* Has_many and belongs_to (within a single table, not between two tables as in other ORMs)
* Constraints (a.k.a. validations)
* RSpec tests and decent docs
* Rudimentary Rails integration (other Ruby web frameworks would work even better)

Here's an example of a Page model that has_many links. Page is the table; Link consists of columns in the "link:" column family.

class Page < Rhino::Model
  column_family :title
  column_family :contents
  column_family :links
  column_family :meta
  column_family :images

  alias_attribute :author, 'meta:author'

  has_many :links, Link

constraint(:title_required) { |page| page.title and ! page.title.empty? }
end

class Link < Rhino::Cell
  belongs_to :page

  # convert from com.example.www/path => www.example.com/path
  def url
    url_parts = key.split('/')
    backwards_host = url_parts.shift
    path = url_parts.join('/')
    host = backwards_host.split('.').reverse.join('.')
    "http://#{host}/#{path}";
  end
end

# now the following code will work
page = Page.new('com.qslack.www', :title=>'My Homepage', :contents=>'<p>Welcome</p>', :author=>'Quinn Slack', :meta_language=>'en-US')
page.title # => 'My Homepage'
page.meta_language # => 'en-US' (from the meta:language column)
page.links.add('com.google.www/search', 'My Favorite Search Engine')
page.save

# later on...
page = Page.find('com.qslack.www')
goog_link = page.links.find('com.google.www/search')
goog_link.contents # => 'My Favorite Search Engine'
goog_link.url # => 'http://www.google.com/search'
goog_link.contents = 'My Second Favorite Search Engine'
goog_link.save

_____________
Quinn Slack
[EMAIL PROTECTED]
http://qslack.com








Reply via email to