NAME
DBIx::Class::Bootstrap::Simple - Simplistic bootstrapping for DBIx::Class
SYNOPSIS
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);
}
METHODS
init
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',
},
}
);
build_relations
Builds relationship mapping for used schema modules.
dbh
Returns raw dbh handle.
begin_work
Begin a transaction.
commit_work
Commit a transaction.
rollback_work
Rollback a transaction.
rs
Returns a resultset.
create
Mapping to resultset->create(...)
search
Mapping to resultset->search(...)
search_rs
Mapping to resultset->search_rs(...)
find
Mapping to resultset->find(...)
find_or_create
Mapping to resultset->find_or_create(...)
model
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' });
METHODS TO SUBCLASS
override_resultset_class
Subclass this to change the resultset class.
object_type_map
This provides a default mapping of objects for inflation.
An example may be:
sub object_type_map { return { date => 'Your:::DateTime::Package', } }
COPYRIGHT
Copyright 2012 Ohio-Pennsylvania Software, LLC.
LICENSE
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
2012 Ohio-Pennsylvania Software, LLC