remove_columns now deletes columns from _columns fixing has_columns false positives
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / DB.pm
CommitLineData
ea2e61bf 1package DBIx::Class::DB;
2
bf5ecff9 3use strict;
4use warnings;
5
1edd1722 6use base qw/DBIx::Class/;
7fb16f1a 7use DBIx::Class::Schema;
8b445e33 8use DBIx::Class::Storage::DBI;
11b78bd6 9use DBIx::Class::ClassResolver::PassThrough;
604d9f38 10use DBI;
ea2e61bf 11
80c90f5d 12__PACKAGE__->load_components(qw/ResultSetProxy/);
2d679367 13
bf5ecff9 14{
15 no warnings 'once';
16 *dbi_commit = \&txn_commit;
17 *dbi_rollback = \&txn_rollback;
18}
8091aa91 19
7fb16f1a 20sub storage { shift->schema_instance(@_)->storage; }
2d679367 21
75d07914 22=head1 NAME
34d52be2 23
1c81f831 24DBIx::Class::DB - (DEPRECATED) classdata schema component
34d52be2 25
26=head1 SYNOPSIS
27
8b445e33 28 package MyDB;
29
30 use base qw/DBIx::Class/;
503536d5 31 __PACKAGE__->load_components('DB');
8b445e33 32
33 __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs);
34
35 package MyDB::MyTable;
36
37 use base qw/MyDB/;
bc0c9800 38 __PACKAGE__->load_components('Core'); # just load this in MyDB if it will
39 # always be there
4a9d7cae 40
41 ...
8b445e33 42
34d52be2 43=head1 DESCRIPTION
44
66d9ef6b 45This class is designed to support the Class::DBI connection-as-classdata style
46for DBIx::Class. You are *strongly* recommended to use a DBIx::Class::Schema
1c81f831 47instead; DBIx::Class::DB will not undergo new development and will be moved
48to being a CDBICompat-only component before 1.0.
34d52be2 49
50=head1 METHODS
51
8091aa91 52=head2 storage
076652e8 53
8091aa91 54Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
076652e8 55
87c4e602 56=head2 class_resolver
57
58****DEPRECATED****
076652e8 59
75d07914 60Sets or gets the class to use for resolving a class. Defaults to
8091aa91 61L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you give
62it. See resolve_class below.
076652e8 63
34d52be2 64=cut
65
11b78bd6 66__PACKAGE__->mk_classdata('class_resolver' =>
181a28f4 67 'DBIx::Class::ClassResolver::PassThrough');
8fe001e1 68
8091aa91 69=head2 connection
39fe0e65 70
71 __PACKAGE__->connection($dsn, $user, $pass, $attrs);
72
73Specifies the arguments that will be passed to DBI->connect(...) to
74instantiate the class dbh when required.
75
76=cut
77
8fe001e1 78sub connection {
79 my ($class, @info) = @_;
66d9ef6b 80 $class->setup_schema_instance unless $class->can('schema_instance');
81 $class->schema_instance->connection(@info);
82}
83
84=head2 setup_schema_instance
85
86Creates a class method ->schema_instance which contains a DBIx::Class::Schema;
87all class-method operations are proxies through to this object. If you don't
88call ->connection in your DBIx::Class::DB subclass at load time you *must*
89call ->setup_schema_instance in order for subclasses to find the schema and
90register themselves with it.
91
92=cut
93
94sub setup_schema_instance {
95 my $class = shift;
04786a4c 96 my $schema = {};
97 bless $schema, 'DBIx::Class::Schema';
7fb16f1a 98 $class->mk_classdata('schema_instance' => $schema);
ea2e61bf 99}
100
8091aa91 101=head2 txn_begin
39fe0e65 102
8091aa91 103Begins a transaction (does nothing if AutoCommit is off).
39fe0e65 104
105=cut
106
181a28f4 107sub txn_begin { shift->schema_instance->txn_begin(@_); }
a29644e1 108
8091aa91 109=head2 txn_commit
39fe0e65 110
8091aa91 111Commits the current transaction.
39fe0e65 112
8091aa91 113=cut
114
181a28f4 115sub txn_commit { shift->schema_instance->txn_commit(@_); }
8091aa91 116
117=head2 txn_rollback
118
119Rolls back the current transaction.
39fe0e65 120
121=cut
122
181a28f4 123sub txn_rollback { shift->schema_instance->txn_rollback(@_); }
124
125=head2 txn_do
126
127Executes a block of code transactionally. If this code reference
128throws an exception, the transaction is rolled back and the exception
bc0c9800 129is rethrown. See L<DBIx::Class::Schema/"txn_do"> for more details.
181a28f4 130
131=cut
132
133sub txn_do { shift->schema_instance->txn_do(@_); }
8b445e33 134
8452e496 135{
136 my $warn;
137
138 sub resolve_class {
139 warn "resolve_class deprecated as of 0.04999_02" unless $warn++;
140 return shift->class_resolver->class(@_);
141 }
7fb16f1a 142}
11b78bd6 143
7eb4ecc8 144=head2 resultset_instance
145
146Returns an instance of a resultset for this class - effectively
147mapping the L<Class::DBI> connection-as-classdata paradigm into the
148native L<DBIx::Class::ResultSet> system.
149
150=cut
151
152sub resultset_instance {
153 my $class = ref $_[0] || $_[0];
154 my $source = $class->result_source_instance;
155 if ($source->result_class ne $class) {
156 $source = $source->new($source);
157 $source->result_class($class);
158 }
159 return $source->resultset;
160}
161
162=head2 resolve_class
163
164****DEPRECATED****
165
166See L<class_resolver>
167
168=head2 dbi_commit
169
170****DEPRECATED****
171
172Alias for L<txn_commit>
173
174=head2 dbi_rollback
175
176****DEPRECATED****
177
178Alias for L<txn_rollback>
179
34d52be2 180=head1 AUTHORS
181
daec44b8 182Matt S. Trout <mst@shadowcatsystems.co.uk>
34d52be2 183
184=head1 LICENSE
185
186You may distribute this code under the same terms as Perl itself.
187
188=cut
189
76b2b77c 1901;