Commit | Line | Data |
---|---|---|
ea2e61bf | 1 | package DBIx::Class::DB; |
2 | ||
3 | use base qw/Class::Data::Inheritable/; | |
8b445e33 | 4 | use DBIx::Class::Storage::DBI; |
604d9f38 | 5 | use DBI; |
ea2e61bf | 6 | |
34d52be2 | 7 | =head1 NAME |
8 | ||
8b445e33 | 9 | DBIx::Class::DB - Simple DBIx::Class Database connection by class inheritance |
34d52be2 | 10 | |
11 | =head1 SYNOPSIS | |
12 | ||
8b445e33 | 13 | package MyDB; |
14 | ||
15 | use base qw/DBIx::Class/; | |
4a9d7cae | 16 | __PACKAGE__->load_components('Core'); |
8b445e33 | 17 | |
18 | __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs); | |
19 | ||
20 | package MyDB::MyTable; | |
21 | ||
22 | use base qw/MyDB/; | |
4a9d7cae | 23 | |
24 | ... | |
8b445e33 | 25 | |
34d52be2 | 26 | =head1 DESCRIPTION |
27 | ||
8b445e33 | 28 | This class provides a simple way of specifying a database connection. |
34d52be2 | 29 | |
30 | =head1 METHODS | |
31 | ||
32 | =over 4 | |
33 | ||
34 | =cut | |
35 | ||
8b445e33 | 36 | __PACKAGE__->mk_classdata('storage'); |
8fe001e1 | 37 | |
39fe0e65 | 38 | =item connection |
39 | ||
40 | __PACKAGE__->connection($dsn, $user, $pass, $attrs); | |
41 | ||
42 | Specifies the arguments that will be passed to DBI->connect(...) to | |
43 | instantiate the class dbh when required. | |
44 | ||
45 | =cut | |
46 | ||
8fe001e1 | 47 | sub connection { |
48 | my ($class, @info) = @_; | |
8b445e33 | 49 | my $storage = DBIx::Class::Storage::DBI->new; |
50 | $storage->connect_info(\@info); | |
51 | $class->storage($storage); | |
ea2e61bf | 52 | } |
53 | ||
39fe0e65 | 54 | =item dbi_commit |
55 | ||
56 | $class->dbi_commit; | |
57 | ||
58 | Issues a commit again the current dbh | |
59 | ||
60 | =cut | |
61 | ||
8b445e33 | 62 | sub dbi_commit { $_[0]->storage->commit; } |
a29644e1 | 63 | |
39fe0e65 | 64 | =item dbi_rollback |
65 | ||
66 | $class->dbi_rollback; | |
67 | ||
68 | Issues a rollback again the current dbh | |
69 | ||
70 | =cut | |
71 | ||
8b445e33 | 72 | sub dbi_rollback { $_[0]->storage->rollback; } |
73 | ||
ea2e61bf | 74 | 1; |
34d52be2 | 75 | |
76 | =back | |
77 | ||
78 | =head1 AUTHORS | |
79 | ||
80 | Matt S. Trout <perl-stuff@trout.me.uk> | |
81 | ||
82 | =head1 LICENSE | |
83 | ||
84 | You may distribute this code under the same terms as Perl itself. | |
85 | ||
86 | =cut | |
87 |