Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
Data::Model::Tutorial:User3Contributed Perl DocumeData::Model::Tutorial::JA(3)

NAME
       Data::Model::Tutorial::JA - Data::Model::TutorialXXXX

Data::Model XX
       id:yappo	XXXXXXXXX O/R MapperXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXX

       XXXXXData::Model	XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX

       XXX Data::Model XXXXXXXX	Data::Model Track - JPerl Advent Calendar 2009
       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
       <http://perl-users.jp/articles/advent-calendar/2009/data-model/>
       XXXXXXXXXXXXXXXX	POD XXXXXXXX

XXXXXX
   DBI XXXXXXXXXX
       Data::Model XXData::Model XXXXXXXXXCREATE TABLE XXXXXXXXXXX
       XXXXXXXXXXXXXXXXX Perl XXXXXX

	 # lib/Neko/DB/User.pm
	 package Neko::DB::User;
	 use strict;
	 use warnings;
	 use base 'Data::Model';
	 use Data::Model::Schema sugar => 'myapp';
	 use Neko::Columns;

	 install_model user => schema {
	     # primary key
	     key 'id';

	     # XXXXX
	     column 'user.id' => { auto_increment => 1 };
	     utf8_column 'user.name';
	 };
	 1;

       XXXXXXXXXXXXXXXXXXXXX

	 # lib/Neko/Columns.pm
	 package Neko::Columns;
	 use strict;
	 use warnings;
	 use Data::Model::Schema sugar => 'myapp';

	 column_sugar 'user.id'
	     =>	int => {
		 required => 1,
		 unsigned => 1,
	     };
	 column_sugar 'user.name'
	     =>	'varchar' => {
		 required => 1,
		 size	  => 255,
	     };
	 1;

       XXXXXXXXXXXXXXXXXXXXXXXXX O/R Mapper XXXXXXXXX
       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX created_on
       XXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX

   XXXXXXXXXXXXX
       XXXXXXXXCREATE TABLE XXXXXXXXX

	 # script/dump_schema.pl
	 use strict;
	 use warnings;
	 use Neko::DB::User;
	 use Data::Model::Driver::DBI;

	 my $dm	= Neko::DB::User->new();

	 do {
	     # XXXXXXXXXXX
	     my	$driver	= Data::Model::Driver::DBI->new(
		 dsn =>	'dbi:SQLite:'
	     );
	     $dm->set_base_driver($driver);
	 };

	 for my	$target	($dm->schema_names) {
	     for my $sql ($dm->as_sqls($target)) {
		 print "$sql\n";
	     }
	 }

       XXXXXXXXdriver XX schema	XXXXXXXXXXXXXXXXXXXXXX
       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

	 # script/crud.pl
	 use strict;
	 use warnings;
	 use Test::More	tests => 10;
	 use Neko::DB::User;
	 use Data::Model::Driver::DBI;

	 my $dm	= Neko::DB::User->new();

	 # XXXXXXXXXXX
	 {
	     my	$driver	= Data::Model::Driver::DBI->new(
		 dsn =>	'dbi:SQLite:'
	     );
	     $dm->set_base_driver($driver);
	 }

	 # schema XXXXXXX
	 for my	$target	($dm->schema_names) {
	     my	$dbh = $dm->get_driver($target)->rw_handle;
	     for my $sql ($dm->as_sqls($target)) {
		 $dbh->do($sql);
	     }
	 }

	 # INSERT XXXX
	 $dm->set( 'user' => {
	     name => 'yappo'
	 });
	 $dm->set('user' => {
	     name => 'ukonmanaho'
	 });

	 # SELECT XXXX
	 #  XXXXXXXXXXXXXXXXXX
	 {
	     my	$iterator = $dm->get('user' => {
		 order => {'id'	=> 'ASC'}
	     });
	     my	@names;
	     while (my $row = $iterator->next) {
		 push @names, $row->name;
	     }
	     is	join(',', @names), 'yappo,ukonmanaho';
	 }

	 # XXXXXXXXXXXXXXX
	 {
	     my	@users = $dm->get('user' => {order => {	'id' =>	'DESC' }});
	     is	scalar(@users),	2;
	     is	$users[0]->name, 'ukonmanaho';
	     is	$users[1]->name, 'yappo';
	 }

	 # XXXXXXX
	 {
	     my	@users = $dm->get('user' => {
		 where => [
		     name => 'yappo'
		 ],
	     });
	     is	scalar(@users),	1;
	     is	$users[0]->name, 'yappo';
	 }

	 # update
	 {
	     my	($ukon,	) = $dm->get('user' => {
		 where => [
		     name => 'ukonmanaho'
		 ],
	     });
	     is	$ukon->name, 'ukonmanaho';
	     $ukon->name('jack');
	     $ukon->update;
	 }

	 # delete
	 {
	     my	$count_users = sub {
		 scalar(my @users = $dm->get('user'));
	     };

	     is	$count_users->(), 2;

	     my	($jack,	) = $dm->get('user' => {
		 where => [
		     name => 'jack'
		 ],
	     });
	     is	$jack->name, 'jack';
	     $jack->delete;

	     is	$count_users->(), 1;
	 }

       XXXXX SELECT/INSERT/UPDATE/DELETE XXXXXXXXXXXX

   Memcached XXXXXXX
       Data::Model XXXXXXXXXX SQLite XXX memcached protocol XXXXXXX
       XXXXXXXXXXXXXXXXXXXX hash database XXXXXXXXXXXXX	XXXXXXXTokyo Tyrant
       XXXXXXXXXXXXData::Model XXXXXXXXX XXXXXXXXX

       Memcached XXXXXXXXXXXXXXXXXXXXXXXXXX

	 # script/memcached.pl
	 use strict;
	 use warnings;
	 use Test::More	tests => 2;
	 use Neko::DB::User;
	 use Data::Model::Driver::Memcached;
	 use Cache::Memcached::Fast;

	 my $dm	= Neko::DB::User->new();

	 # XXXXXXXXXXX
	 {
	     my	$driver	= Data::Model::Driver::Memcached->new(
		 memcached => Cache::Memcached::Fast->new({
		     servers =>	[
			 '127.0.0.1:11211',
		     ],
		 }),
	     );
	     warn $dm->set_base_driver($driver);
	 }

	 # INSERT
	 warn $dm->set(	'user' => 1, {
	     name => 'yappo'
	 });
	 warn $dm->set('user' => 2, {
	     name => 'ukonmanaho'
	 });

	 # SELECT
	 {
	     my	($yappo) = $dm->get('user' => 1);
	     warn $yappo;
	     is	$yappo->name, 'yappo';
	 }
	 {
	     my	($ukonmanaho) =	$dm->get('user'	=> 2);
	     warn $ukonmanaho;
	     is	$ukonmanaho->name, 'ukonmanaho';
	 }

   XXXXXXXXXXX
       DBI X Memcached XXXXXXXXXXXXXXXXX Memcached XXXXXXXXX XXXXXXXXXXXXXX

   Q4M
XXXXXXXX
XXXXXXXXXXXXXXXXXXXXXX
   get
   lookup
   lookup_multi
   set
   replace
   update
   delete
Mixin XXXX
trigger	XXXX
XXXXXXXXXXX
       tokuhirom (original
       http://github.com/tokuhirom/data-model-tutorial/tree/master)

       yappo (XXXX)

perl v5.32.1			  2013-07-08	  Data::Model::Tutorial::JA(3)

NAME | Data::Model XX | XXXXXX | XXXXXXXX | XXXXXXXXXXXXXXXXXXXXXX | Mixin XXXX | trigger XXXX | XXXXXXXXXXX

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Data::Model::Tutorial::JA&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help