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