ODB is an object database implementation for Ruby. I have seen this idea in many forms. Some are object-relational mapping tools, some offer a transparent API, but do not scale up well. For languages other than Ruby, there are options in this area as well. All that I have seen either require too much extra work on the part of the programmer or are brittle due to the static nature of the language on which they are built, such as C++. In short, while many people have made attempts in this area, none have quite done what I want. For this reason, I created Ruby ODB.
Ruby ODB was developed and is maintained by Brian Ollenberger. If you need to contact me, see the contact link above.
Ruby ODB has the following features and characteristics:
ODB is developed for Ruby 1.8. It uses DBI for database access and is designed for use with PostgreSQL, although there are few queries and it could be ported to another DBMS if necessary. I recommend only using a DBMS with transaction and foreign key support though.
The easiest way to understand Ruby ODB, is to see an example of it in use. Following is a simple example of initializing a database with a hash object. This will allow us to store any other objects we want into that hash and they will be made persistent.
require 'odb'
odb = ObjectDB.new('dbi:Pg:database', 'user')
root_object = {}
odb.create(root_object)
Now in another process, or in the same process we can do the following.
odb['key'] = 42
Finally in another process again, we can get that value back.
puts odb['key'].to_s
Which will output "42".
This is, of course, just a simple contrived example of what can be done. Also note that here we used implicit transactions. For most uses, explicit transactions are safer and allow more complex operations.
# Perform an explicit transaction. This is equivalent to the similar
# example above.
odb.transaction do |root|
root['key'] = 42
end
ACID transaction semantics are inherited from PostgreSQL.
The ObjectDB constructor takes the same arguments as DBI.connect, in the DBI package. See the DBI documentation for the details. Based on these examples, you now know the entire ODB interface. It is really that simple. If you want to store large collections of objects, though, use the PersistentArray class provided instead of the Ruby Array class, since the latter will be stored as a single object with all of its contents.
I may augment this example section with more detailed documentation in the future. If you would like to contribute such a thing, please contact me.
You can download Ruby ODB below. It is released under a BSD License.
The current release is version 0.3.