anon
anon

Reputation:

Is there an ORM for Perl?

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/);

Upvotes: 9

Views: 5965

Answers (3)

singingfish
singingfish

Reputation: 3167

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", "",""]);

Upvotes: 0

Yann
Yann

Reputation: 170

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

Upvotes: 0

Dave Rolsky
Dave Rolsky

Reputation: 4532

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.

Upvotes: 30

Related Questions