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