Mostly refactored everything to select/update/delete off storage handle
[dbsrgits/DBIx-Class.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 sub _get_dbh { shift->storage->dbh; }
74
75 1;
76
77 =back
78
79 =head1 AUTHORS
80
81 Matt S. Trout <perl-stuff@trout.me.uk>
82
83 =head1 LICENSE
84
85 You may distribute this code under the same terms as Perl itself.
86
87 =cut
88