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