create now on resultset as well
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / DB.pm
CommitLineData
ea2e61bf 1package DBIx::Class::DB;
2
1edd1722 3use base qw/DBIx::Class/;
8b445e33 4use DBIx::Class::Storage::DBI;
11b78bd6 5use DBIx::Class::ClassResolver::PassThrough;
604d9f38 6use DBI;
ea2e61bf 7
2d679367 8__PACKAGE__->load_components(qw/ResultSetInstance/);
9
8091aa91 10*dbi_commit = \&txn_commit;
11*dbi_rollback = \&txn_rollback;
12
2d679367 13sub storage { shift->storage_instance(@_); }
14
f6858c33 15sub resultset_instance {
16 my $class = shift;
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;
21}
22
34d52be2 23=head1 NAME
24
8b445e33 25DBIx::Class::DB - Simple DBIx::Class Database connection by class inheritance
34d52be2 26
27=head1 SYNOPSIS
28
8b445e33 29 package MyDB;
30
31 use base qw/DBIx::Class/;
503536d5 32 __PACKAGE__->load_components('DB');
8b445e33 33
34 __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs);
35
36 package MyDB::MyTable;
37
38 use base qw/MyDB/;
8091aa91 39 __PACKAGE__->load_components('Core'); # just load this in MyDB if it will always be there
4a9d7cae 40
41 ...
8b445e33 42
34d52be2 43=head1 DESCRIPTION
44
8b445e33 45This class provides a simple way of specifying a database connection.
34d52be2 46
47=head1 METHODS
48
8091aa91 49=head2 storage
076652e8 50
8091aa91 51Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
076652e8 52
8091aa91 53=head2 class_resolver
076652e8 54
8091aa91 55Sets or gets the class to use for resolving a class. Defaults to
56L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you give
57it. See resolve_class below.
076652e8 58
34d52be2 59=cut
60
11b78bd6 61__PACKAGE__->mk_classdata('class_resolver' =>
62 'DBIx::Class::ClassResolver::PassThrough');
8fe001e1 63
8091aa91 64=head2 connection
39fe0e65 65
66 __PACKAGE__->connection($dsn, $user, $pass, $attrs);
67
68Specifies the arguments that will be passed to DBI->connect(...) to
69instantiate the class dbh when required.
70
71=cut
72
8fe001e1 73sub connection {
74 my ($class, @info) = @_;
8b445e33 75 my $storage = DBIx::Class::Storage::DBI->new;
76 $storage->connect_info(\@info);
2d679367 77 $class->mk_classdata('storage_instance' => $storage);
ea2e61bf 78}
79
8091aa91 80=head2 txn_begin
39fe0e65 81
8091aa91 82Begins a transaction (does nothing if AutoCommit is off).
39fe0e65 83
84=cut
85
8091aa91 86sub txn_begin { $_[0]->storage->txn_begin }
a29644e1 87
8091aa91 88=head2 txn_commit
39fe0e65 89
8091aa91 90Commits the current transaction.
39fe0e65 91
8091aa91 92=cut
93
94sub txn_commit { $_[0]->storage->txn_commit }
95
96=head2 txn_rollback
97
98Rolls back the current transaction.
39fe0e65 99
100=cut
101
8091aa91 102sub txn_rollback { $_[0]->storage->txn_rollback }
8b445e33 103
11b78bd6 104sub resolve_class { return shift->class_resolver->class(@_); }
105
ea2e61bf 1061;
34d52be2 107
34d52be2 108=head1 AUTHORS
109
daec44b8 110Matt S. Trout <mst@shadowcatsystems.co.uk>
34d52be2 111
112=head1 LICENSE
113
114You may distribute this code under the same terms as Perl itself.
115
116=cut
117