Lafcadio 0.9.3: PostgreSQL support, eager loading, more

The newest development release of Lafcadio, 0.9.3, now supports
PostgreSQL, adds eager loading, and has a few more additions.

As always, odd-numbered releases should be considered beta. If you want
to play it safe, use 0.8.3 instead.

== What’s Lafcadio? ==

Lafcadio is an object-relational mapping library for use with MySQL. It
supports a lot of advanced features, including extensive aid in mapping
to legacy databases, in-Ruby triggers, and 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.

I use it in production code on a regular basis, most notably at, an online community with more than 1 million pageviews a

== What’s new? ==

= PostgreSQL support =

Lafcadio now supports PostgreSQL. Activating is a simple matter of
setting ‘dbtype’ in LafcadioConfig:

‘dbuser’ => ‘testuser’, ‘dbpassword’ => ‘password’,
‘dbname’ => ‘test_db’, ‘dbhost’ => ‘localhost’, ‘dbtype’ => ‘Pg’

Everything else – single-row retrieval, transactions, query inference,
order and limit clauses – works transparently across both MySQL and

= Eager loading =

To prevent excessive selects, you can now use eager loading to load
across associations with one select statement:

all_invoices = Invoice.all( :include => :client )

Knows Client information without incurring another select

= MockObjectStore handles transactions =

Transaction support was previously added, in 0.9.0, but I forgot to add
transaction support to the MockObjectStore. Now that the
MockObjectStore mimics the database, you can test transaction-dependent
logic in-memory, within having a real database installed.

For example, below is a (somewhat stupid) method that uses
transactions, with a test-case using the in-memory MockObjectStore:

def transfer_money( from_account, to_account, tr_amount )
object_store = Lafcadio::ObjectStore.get_object_store
object_store.transaction do |tr|
‘amount’ => from_account.amount - tr_amount
to_account.update!( ‘amount’ => to_account.amount + tr_amount )
tr.rollback if from_account.amount < 0

class TestTransferMoney < Test::Unit::TestCase
def test_rollback_if_less_than_zero
mock_object_store =
ObjectStore.set_object_store mock_object_store
from_account = ‘amount’ => 100.0 ).commit
to_account = ‘amount’ => 0.0 ).commit
transfer_money( from_account, to_account, 200.0 )
from_account_prime = Account[from_account.pk_id]
assert_equal( 100.0, from_account_prime.amount )

Commits and rollbacks work for the test code, even if you don’t have a
database installed.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs