sigzero has asked for the wisdom of the Perl Monks concerning the following question:

I was reading this:

http://www.onjava.com/pub/a/onjava/2005/02/02/sqlmaps.html

I thought it was a pretty good way to separate out the SLQ and mappings.

I was wondering if anyone had implemented something like that in Perl. What would be considered O/R in the house of Perl?

Here are 10 reasons they give for Java using SQLMaps:

10  Works with any database that has a JDBC driver (no plugins required)
9   Configurable caching (including dependencies)
8   Local and Global transaction support and management
7   Simple XML mapping document structure
6   Supports Map, Collection, List and Primitive Wrappers
5   Supports JavaBeans classes (get/set methods)
4   Supports complex object mappings (populating lists, complex object models etc.)
3   Object models are never perfect (no changes required!)
2   Database designs are never perfect (no changes required!)
1   You already know SQL, why waste time learning something else?

Of course, some of those are Java specific, but I like the idea behind it.

Thoughts and opinions welcome!

Edit by castaway - linkified link

Replies are listed 'Best First'.
Re: SQLMaps
by Joost (Canon) on Mar 23, 2005 at 20:50 UTC
    IIRC SQLMaps do not do Object-Relational mappings as it's generally understood. For a reasonably good O/R mapping (in the usual sense) in perl see Class::DBI.

    As I understand it, SQL maps merely transforms the results of a hand-written SQL query as an object with some getter/setter methods. You can get the same kind of functionality by doing something like

    my $data = $sth->fetchrow_hashref(); my $object = bless $data,Some::Class; package Some::Class; use base 'Class::Accessor'; __PACKAGE__->mk_accessors(qw(result_column_a result_column_b .... );

    THe only other thing SQLMaps does is that it allows you to take the SQL code out of the java code (which means you can, and probably should, rewrite the SQL for every database you want to support)

    I'm not trying to take the piss out of SQLMaps; Java just forces you to make all of this really difficult. I'm not sure if there is an equivalent module for Perl at the moment. I would like one, as long as it didn't require me to configure it in XML.

Re: SQLMaps
by cazz (Pilgrim) on Mar 23, 2005 at 20:13 UTC
    Class::DBI does a great job implementing most of the features people will use from SQLMaps.