=head1 NAME

Data::Model - model interface which had more data sources unified, a.k.a data/object mapper

=head1 SYNOPSIS

  package 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;

=head1 DESCRIPTION

Data::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.

=head1 SCHEMA DEFINITION

One package can define two or more tables using DSL.

see L<Data::Model::Schema>.

=head1 METHODS

=head2 new([ \%options ]);

  my $model = Class->new;

=head2 lookup($target => $key)

  my $row = $model->lookup( user => $id );
  print $row->name;

=head2 lookup_multi($target => \@keylist)

  my @row = $model->lookup_multi( user => [ $id1, $id2 ] );
  print $row[0]->name;
  print $row[1]->name;

=head2 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;
  }

=head2 set($target => $key, => \%values [, \%options ])

  $model->set( user => {
    id   => 3,
    name => 'insert record',
  });

=head2 delete($target => $key [, \%options ])

  $model->delete( user => 3 ); # id = 3 is deleted

=head1 ROW OBJECT METHODS

row object is provided by L<Data::Model::Row>.

=head2 update

  my $row = $model->lookup( user => $id );
  $row->name('update record');
  $row->update;

=head2 delete

  my $row = $model->lookup( user => $id );
  $row->delete;

=head1 TRANSACTION

see L<Data::Model::Transaction>.

=head1 DATA DRIVERS

=head2 DBI

see L<Data::Model::Driver::DBI>.

=head2 DBI::MasterSlave

master-slave composition for mysql.

see L<Data::Model::Driver::DBI::MasterSlave>.

=head2 Cache

Cash of the result of a query.

see L<Data::Model::Driver::Cache::HASH>,
see L<Data::Model::Driver::Cache::Memcached>.

=head2 Memcached

memcached is used for data storage.

see L<Data::Model::Driver::Memcached>.

=head2 Queue::Q4M

queuing manager for Q4M.

see L<Data::Model::Driver::Queue::Q4M>.

=head2 Memory

on memory storage.

see L<Data::Model::Driver::Memory>.

=head1 SEE ALSO

L<Data::Model::Row>,
L<Data::Model::Iterator>

=head1 ACKNOWLEDGEMENTS

Benjamin Trott more idea given by L<Data::ObjectDriver>

=head1 AUTHOR

Kazuhiro Osawa E<lt>yappo <at> shibuya <döt> plE<gt>

=head1 REPOSITORY

  git clone git://github.com/yappo/p5-Data-Model.git

Data::Model's Git repository is hosted at L<http://github.com/yappo/p5-Data-Model>.
patches and collaborators are welcome.

=head1 LICENSE

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.


=cut

