Aniki - The ORM as our great brother.
use 5.014002; package MyProj::DB::Schema { use DBIx::Schema::DSL; create_table 'module' => columns { integer 'id', primary_key, auto_increment; varchar 'name'; integer 'author_id'; add_index 'author_id_idx' => ['author_id']; belongs_to 'author'; }; create_table 'author' => columns { integer 'id', primary_key, auto_increment; varchar 'name', unique; has_many 'module'; }; }; package MyProj::DB::Filter { use Aniki::Filter::Declare; use Scalar::Util qw/blessed/; use Time::Moment; # define inflate/deflate filters in table context. table author => sub { inflate name => sub { my $name = shift; return uc $name; }; deflate name => sub { my $name = shift; return lc $name; }; }; inflate qr/_at$/ => sub { my $datetime = shift; $datetime =~ tr/ /T/; $datetime .= 'Z'; return Time::Moment->from_string($datetime); }; deflate qr/_at$/ => sub { my $datetime = shift; return $datetime->at_utc->strftime('%F %T') if blessed $datetime and $datetime->isa('Time::Moment'); return $datetime; }; }; package MyProj::DB { use Mouse; extends qw/Aniki/; __PACKAGE__->setup( schema => 'MyProj::DB::Schema', filter => 'MyProj::DB::Filter', row => 'MyProj::DB::Row', ); }; package main { my $db = MyProj::DB->new(connect_info => [...]); my $author_id = $db->insert_and_fetch_id(author => { name => 'songmu' }); $db->insert(module => { name => 'DBIx::Schema::DSL', author_id => $author_id, }); $db->insert(module => { name => 'Riji', author_id => $author_id, }); my $module = $db->select(module => { name => 'Riji', }, { limit => 1, })->first; $module->name; ## Riji $module->author->name; ## SONGMU my $author = $db->select(author => { name => 'songmu', }, { limit => 1, relay => [qw/module/], })->first; $author->name; ## SONGMU $_->name for $author->modules; ## DBIx::Schema::DSL, Riji }; 1;
IT'S STILL IN DEVELOPMENT PHASE. I haven't written document and test script yet.
Aniki is ORM. Lite, but powerful.
Copyright (C) karupanerura.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
karupanerura <karupa@cpan.org>
To install Aniki, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Aniki
CPAN shell
perl -MCPAN -e shell install Aniki
For more information on module installation, please visit the detailed CPAN module installation guide.