|
NAMEData::Model - model interface which had more data sources unified, a.k.a data/object mapperSYNOPSISpackage Your::Model; use base 'Data::Model'; use Data::Model::Schema; use Data::Model::Driver::DBI; my $dbfile = '/foo/bar.db'; my $driver = Data::Model::Driver::DBI->new( dsn => "dbi:SQLite:dbname=$dbfile", ); base_driver( $driver ); install_model user => schema { key 'id'; columns qw/ id name /; }; # create database file unless (-f $dbfile) { my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1, PrintError => 0 }); for my $sql (__PACKAGE__->as_sqls) { $dbh->do( $sql ); } $dbh->disconnect; } # in your script: use Your::Model; my $model = Your::Model->new; # insert my $row = $model->set( user => { id => 1, } ); my $row = $model->lookup( user => 1 ); $row->delete; DESCRIPTIONData::Model is can use as ORM which can be defined briefly.There are few documents. It is due to be increased in the near future. SCHEMA DEFINITIONOne package can define two or more tables using DSL.see Data::Model::Schema. METHODSnew([ \%options ]);my $model = Class->new; lookup($target => $key)my $row = $model->lookup( user => $id ); print $row->name; lookup_multi($target => \@keylist)my @row = $model->lookup_multi( user => [ $id1, $id2 ] ); print $row[0]->name; print $row[1]->name; get($target => $key [, \%options ])my $iterator = $model->get( user => { id => { IN => [ $id1, $id2 ], } }); while (my $row = $iterator->next) { print $row->name; } # or while (my $row = <$iterator>) { print $row->name; } # or while (<$iterator>) { print $_->name; } set($target => $key, => \%values [, \%options ])$model->set( user => { id => 3, name => 'insert record', }); if insert to table has auto increment then return $row object with fill in key column by last_insert_id. my $row = $model->set( user => { name => 'insert record', }); say $row->id; # show last_insert_id() delete($target => $key [, \%options ])$model->delete( user => 3 ); # id = 3 is deleted ROW OBJECT METHODSrow object is provided by Data::Model::Row.updatemy $row = $model->lookup( user => $id ); $row->name('update record'); $row->update; deletemy $row = $model->lookup( user => $id ); $row->delete; TRANSACTIONsee Data::Model::Transaction.DATA DRIVERSDBIsee Data::Model::Driver::DBI.DBI::MasterSlavemaster-slave composition for mysql.see Data::Model::Driver::DBI::MasterSlave. CacheCash of the result of a query.see Data::Model::Driver::Cache::HASH, see Data::Model::Driver::Cache::Memcached. Memcachedmemcached is used for data storage.see Data::Model::Driver::Memcached. Queue::Q4Mqueuing manager for Q4M.see Data::Model::Driver::Queue::Q4M. Memoryon memory storage.see Data::Model::Driver::Memory. SEE ALSOData::Model::Row, Data::Model::IteratorACKNOWLEDGEMENTSBenjamin Trott more idea given by Data::ObjectDriverAUTHORKazuhiro Osawa <yappo <at> shibuya <doet> pl>REPOSITORYgit clone git://github.com/yappo/p5-Data-Model.git Data::Model's Git repository is hosted at <http://github.com/yappo/p5-Data-Model>. patches and collaborators are welcome. LICENSEThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.POD ERRORSHey! The above document had some coding errors, which are explained below:
Visit the GSP FreeBSD Man Page Interface. |