<< Shut down! |
| Holding pattern >>
Posted Sunday, January 2, 2005
Lafcadio 0.6.0, the next production release, is out and available at http://lafcadio.rubyforge.org/.
An object-relational mapping library for use with MySQL. It supports a lot of advanced features, including in-Ruby field value checking, extensive aid in mapping to legacy databases, an advanced query engine that allows you to form queries in Ruby that can be run either against the live database, or an in-memory mock store for testing purposes.
Lafcadio is more than a year old and is currently in use on production websites, most notably http://rhizome.org/, an online community that has a 6-year-old legacy database and gets more than 3 million hits a month.
Lots, if you’ve been using the last production branch (0.4.x).
users = object_store.get_users { |user| user.fname.equals( 'Francis' ) }
But now you can also call Query.infer, in case you want to edit the query object a bit:
query = Query.infer( User ) { |user| user.fname.equals( "Francis" ) }
users = object_store.get_subset( query )
You can user Query#and and Query#or to modify it in place:
query = query.and { |user| user.lname.equals( "Hwang" ) }
only_me = object_store.get_subset( query )
You can also now query against the primary key field, and boolean fields implicitly:
old_users = object_store.get_users { |user| user.pk_id.lt( 100 ) }
administrators = object_store.get_users { |user| user.administrator }
Of course, the point of these queries (as opposed to simply passing in a SQL string) is that they work just as well with the in-memory MockObjectStore as with the MySQL database. This means that if your code uses Lafcadio, you can write complex tests that depend on database logic.