Reputation:
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
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
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
Reputation: 4532
Rule #1, don't write your own.
There are quite a number of ORMs on CPAN, including ...
Upvotes: 30