tags:

views:

847

answers:

4
create table person
(
    name varchar(15),
    attr1 varchar(15),
    attr2 varchar(1),
    attr3 char(1),
    attr4 int
)

How I can use basic ORM in Perl by taking a simple table like the one above and mapping it to Perl objects? Next I'd like to perform basic operations like select results using some criteria system Perl like syntax. eg.:

@myResults = findAll(attr1 == 3 && attr2 =~ /abc/);
+20  A: 

Rule #1, don't write your own.

There are quite a number of ORMs on CPAN, including ...

  • DBIx::Class - probably #1 in popularity at the moment
  • Rose::DB::Object
  • Fey::ORM - my own contribution, most notable for being Moose-based, which means you get all the power of Moose in your ORM-based classes.
Dave Rolsky
I was basically posting to say the same thing when I saw this. Perl is all about reusing existing code.
glenatron
It's nice that Perl has 3 ways to do this. However, can support compare and contrast the 3 libraries? Popularity is one criteria. Simplicity and time to use is another.
this'd probably best as a new question of its own.
Dave Rolsky
It's easier to compare them for you if you tell us what's important to you. :)
brian d foy
You should edit the question to encapsulate the additional information you are asking for
Shabbyrobe
+1  A: 

DBIx::Class worked for me.

yogman
A: 

(Chiming late) Data::ObjectDriver (also on CPAN) provides great flexibility especially if partitioning and caching is on the list of your requirements.

Yann
A: 

Of the suggestions I'd use DBIx::Class. Here's some code to introspect a 50 table legacy database (with relationships specified in the schema):

#!/usr/bin/perl
use warnings;
use strict;
use DBIx::Class::Schema::Loader qw/ make_schema_at /;

make_schema_at("Zotero::Schema",
               {
                   # components => ['InflateColumn::DateTime'],
                   debug => 1,
                   relationships => 1,
                   dump_directory => './lib' ,
               },
               ["dbi:SQLite:dbname=../zotero.sqlite", "",""]);
singingfish