# Lafcadio 0.9.3: PostgreSQL support, eager loading, more

**URL:** <https://www.ruby-forum.com/t/lafcadio-0-9-3-postgresql-support-eager-loading-more/55576>\
**Category:** Ruby\
**Created:** [March 22, 2006, 6:13am UTC](https://www.ruby-forum.com/t/lafcadio-0-9-3-postgresql-support-eager-loading-more/55576 "2006-03-22T06:13:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francis\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@Francis\_H](https://www.ruby-forum.com/u/Francis_H)\
**Post date:** [March 22, 2006, 6:13am UTC](https://www.ruby-forum.com/t/lafcadio-0-9-3-postgresql-support-eager-loading-more/55576/1 "2006-03-22T06:13:57Z")

</div>

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.

[http://lafcadio.rubyforge.org/](http://lafcadio.rubyforge.org/)

== 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  
[Rhizome.org](http://Rhizome.org), an online community with more than 1 million pageviews a  
month.

== What’s new? ==

= PostgreSQL support =

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

LafcadioConfig.set\_values(  
‘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  
PostgreSQL.

= 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

all\_invoices.first.client.name

= 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|  
from\_account.update!(  
‘amount’ =\> from\_account.amount - tr\_amount  
)  
to\_account.update!( ‘amount’ =\> to\_account.amount + tr\_amount )  
tr.rollback if from\_account.amount \< 0  
end  
end

class TestTransferMoney \< Test::Unit::TestCase  
def test\_rollback\_if\_less\_than\_zero  
mock\_object\_store = MockObjectStore.new  
ObjectStore.set\_object\_store mock\_object\_store  
from\_account = Account.new( ‘amount’ =\> 100.0 ).commit  
to\_account = Account.new( ‘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 )  
end  
end

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