DBIx::Class::Bootstrap::Simple - Simplistic bootstrapping for DBIx::Class
Your model:
package YourNamespace::DB::User; use base 'DBIx::Class::Bootstrap::Simple'; use strict; __PACKAGE__->init( table => 'users', primary_key => 'user_id', definition => [ { key => 'user_id', type => 'INT(11)', special => 'AUTO_INCREMENT', null => 0, primary => 1, }, { key => 'company_id', type => 'INT', }, { key => 'password_id', type => 'INT(11)', }, { key => 'stash', type => 'BLOB', }, }, # link datetime objects here as well objects => { # class must have an inflate and deflate method # inflate method is Class->inflate(value_to_inflate) # deflate is $yourinflated_object->deflate; stash => 'YourApp::DB::DataType::Stash', }, references => { company => { class => 'YourApp::DB::Company', column => 'company_id', cascade_update => 1, #defaults to 0 cascade_delete => 1, #defaults to 0 cascade_copy => 1, #defaults to 0 }, password => { class => 'YourApp::DB::Password', column => 'password_id', }, } );
Your application:
# load other model classes DBIx::Class::Bootstrap::Simple->build_relations; my $schema = DBIx::Class::Bootstrap::Simple->connect(sub { }); # on a connection basis $schema->storage->DESTROY; my $dbh = DBI->connect(..., { RaiseError => 1 }); $schema->storage->connect_info([{ dbh_maker => sub { $dbh } }]); sub db { my ($self, $table) = @_; die "invalid table name: $table" unless $DBIx::Class::Bootstrap::Simple::CONFIG{$table}; return $schema->model($table); }
The init method should be called in every "table package", it configures DBIx::Class::Bootstrap::Simple with the table's schema.
__PACKAGE__->init( table => 'users', primary_key => 'user_id', definition => [ { key => 'user_id', type => 'INT(11)', special => 'AUTO_INCREMENT', null => 0, primary => 1, }, { key => 'company_id', type => 'INT', }, { key => 'password_id', type => 'INT(11)', }, { key => 'stash', type => 'BLOB', }, }, # link datetime objects here as well objects => { # class must have an inflate and deflate method # inflate method is Class->inflate(value_to_inflate) # deflate is $yourinflated_object->deflate; stash => 'YourApp::DB::DataType::Stash', }, references => { company => { class => 'YourApp::DB::Company', column => 'company_id', cascade_update => 1, # defaults to 0 cascade_delete => 1, # defaults to 0 cascade_copy => 1, # defaults to 0 }, password => { class => 'YourApp::DB::Password', column => 'password_id', }, banjos => { class => 'YourApp::DB::Banjos', column => 'user_id', # or, if mapping columns differ local_column => 'banjo_user_id', foreign_column => 'eskimo_banjo_user_id', }, } );
Builds relationship mapping for used schema modules.
Returns raw dbh handle.
Begin a transaction.
Commit a transaction.
Rollback a transaction.
Returns a resultset.
Mapping to resultset->create(...)
Mapping to resultset->search(...)
Mapping to resultset->search_rs(...)
Mapping to resultset->find(...)
Mapping to resultset->find_or_create(...)
Given a table name as an argument, return a resultset from a table name.
Example:
DBIx::Class::Bootstrap::Simple->model('users')->create({ name => 'Moon Panda' });
Subclass this to change the resultset class.
This provides a default mapping of objects for inflation.
An example may be:
sub object_type_map { return { date => 'Your:::DateTime::Package', } }
Copyright 2012 Ohio-Pennsylvania Software, LLC.
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
2012 Ohio-Pennsylvania Software, LLC
To install DBIx::Class::Bootstrap::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::Bootstrap::Simple
CPAN shell
perl -MCPAN -e shell install DBIx::Class::Bootstrap::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.