1 package DBIx::Class::DB;
3 use base qw/DBIx::Class/;
4 use DBIx::Class::Storage::DBI;
5 use DBIx::Class::ClassResolver::PassThrough;
8 __PACKAGE__->load_components(qw/ResultSetInstance/);
10 *dbi_commit = \&txn_commit;
11 *dbi_rollback = \&txn_rollback;
13 sub storage { shift->storage_instance(@_); }
15 sub resultset_instance {
17 my $table = $class->table_instance->new($class->table_instance);
18 $table->storage($class->storage_instance);
19 $table->result_class($class);
20 return $table->resultset;
25 DBIx::Class::DB - Simple DBIx::Class Database connection by class inheritance
31 use base qw/DBIx::Class/;
32 __PACKAGE__->load_components('DB');
34 __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs);
36 package MyDB::MyTable;
39 __PACKAGE__->load_components('Core'); # just load this in MyDB if it will always be there
45 This class provides a simple way of specifying a database connection.
51 Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
55 Sets or gets the class to use for resolving a class. Defaults to
56 L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you give
57 it. See resolve_class below.
61 __PACKAGE__->mk_classdata('class_resolver' =>
62 'DBIx::Class::ClassResolver::PassThrough');
66 __PACKAGE__->connection($dsn, $user, $pass, $attrs);
68 Specifies the arguments that will be passed to DBI->connect(...) to
69 instantiate the class dbh when required.
74 my ($class, @info) = @_;
75 my $storage = DBIx::Class::Storage::DBI->new;
76 $storage->connect_info(\@info);
77 $class->mk_classdata('storage_instance' => $storage);
82 Begins a transaction (does nothing if AutoCommit is off).
86 sub txn_begin { $_[0]->storage->txn_begin }
90 Commits the current transaction.
94 sub txn_commit { $_[0]->storage->txn_commit }
98 Rolls back the current transaction.
102 sub txn_rollback { $_[0]->storage->txn_rollback }
104 sub resolve_class { return shift->class_resolver->class(@_); }
110 Matt S. Trout <mst@shadowcatsystems.co.uk>
114 You may distribute this code under the same terms as Perl itself.