Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

RDDB: RESTful Ruby Document-Oriented Database

By Peter Cooper / November 6, 2007

RDDB is a Ruby document-oriented database system inspired by CouchDB and developed by Anthony Eden. If you're familiar with CouchDB, the whole system should make sense from the start, but if not, read on. You can create a database and insert documents in a simple enough way:

# First create an database object
database = Rddb::Database.new

# Put some documents into it
database << {:name => 'John', :income => 35000}
database << {:name => 'Bob', :income => 40000}

To "query" the database, you define a "view" using a Ruby block, as such:

# Create a view that will return the names
database.create_view('names') do |document, args|
  document.name
end

# The result of querying will return an array of names
assert_equal ['John','Bob','Jim'], database.query('names')

Views are defined as Ruby blocks that are then used to select the documents and the attributes in the documents that you wish to retrieve. It all gets rather more powerful (and complex) than this very quickly (especially when you apply additional Ruby logic to views), and further examples are available to view at the official RDDB site.

(Thanks to Matthew Williams for pointing this library out)

Other Posts to Enjoy

Twitter Mentions