fhwang.net

Lafcadio 0.6.0

Lafcadio 0.6.0, the next production release, is out and available at http://lafcadio.rubyforge.org/.

What’s Lafcadio?

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.

What’s new in 0.6.0?

Lots, if you’ve been using the last production branch (0.4.x).

  • Improved querying: With previous versions you were able to call ObjectStore#get_&lt: domain class > to infer a query:
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.

  • Optional field value checking: You can have Lafcadio verify fields of domain objects before trying to commit them to the database.
  • De-Java-fied code. Methods are now underscored instead of camel-cased, classes and test classes are grouped into larger files instead of their own files.
  • Misc cleanup. Removed a lot of unnecessary methods and classes, and also sent some methods to live in the Extensions library.
blog comments powered by Disqus

« Previous post

Next post »