7 # Always remember to do all digits for the version even if they're 0
8 # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
9 # brain damage and presumably various other packaging systems too
11 # $VERSION declaration must stay up here, ahead of any other package
12 # declarations, as to not confuse various modules attempting to determine
13 # this ones version, whether that be s.c.o. or Module::Metadata, etc
16 $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
19 package # hide from pause
27 BROKEN_FORK => ($^O eq 'MSWin32') ? 1 : 0,
29 HAS_ITHREADS => $Config{useithreads} ? 1 : 0,
31 # ::Runmode would only be loaded by DBICTest, which in turn implies t/
32 DBICTEST => eval { DBICTest::RunMode->is_author } ? 1 : 0,
34 # During 5.13 dev cycle HELEMs started to leak on copy
36 # request for all tests would force "non-leaky" illusion and vice-versa
37 defined $ENV{DBICTEST_ALL_LEAKS} ? !$ENV{DBICTEST_ALL_LEAKS}
38 # otherwise confess that this perl is busted ONLY on smokers
39 : eval { DBICTest::RunMode->is_smoker } && ($] >= 5.013005 and $] <= 5.013006) ? 1
40 # otherwise we are good
47 constant->import( OLD_MRO => 1 );
51 constant->import( OLD_MRO => 0 );
57 use DBIx::Class::Optional::Dependencies;
59 use base qw/DBIx::Class::Componentised DBIx::Class::AccessorGroup/;
60 use DBIx::Class::StartupCheck;
62 __PACKAGE__->mk_group_accessors(inherited => '_skip_namespace_frames');
63 __PACKAGE__->_skip_namespace_frames('^DBIx::Class|^SQL::Abstract|^Try::Tiny|^Class::Accessor::Grouped|^Context::Preserve');
66 shift->mk_classaccessor(@_);
69 sub mk_classaccessor {
71 $self->mk_group_accessors('inherited', $_[0]);
72 $self->set_inherited(@_) if @_ > 1;
75 sub component_base_class { 'DBIx::Class' }
77 sub MODIFY_CODE_ATTRIBUTES {
78 my ($class,$code,@attrs) = @_;
79 $class->mk_classdata('__attr_cache' => {})
80 unless $class->can('__attr_cache');
81 $class->__attr_cache->{$code} = [@attrs];
87 my $cache = $self->can('__attr_cache') ? $self->__attr_cache : {};
91 %{ $self->maybe::next::method || {} },
99 DBIx::Class - Extensible and flexible object <-> relational mapper.
101 =head1 GETTING HELP/SUPPORT
103 The community can be found via:
107 =item * IRC: irc.perl.org#dbix-class
110 <a href="http://chat.mibbit.com/#dbix-class@irc.perl.org">(click for instant chatroom login)</a>
112 =item * Mailing list: L<http://lists.scsys.co.uk/mailman/listinfo/dbix-class>
114 =item * Twitter L<http://www.twitter.com/dbix_class>
116 =item * Web Site: L<http://www.dbix-class.org/>
118 =item * RT Bug Tracker: L<https://rt.cpan.org/Dist/Display.html?Queue=DBIx-Class>
122 The project is maintained in a git repository, accessible from the following sources:
126 =item * git: L<git://git.shadowcat.co.uk/dbsrgits/DBIx-Class.git>
128 =item * gitweb: L<http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/DBIx-Class.git>
130 =item * github mirror: L<https://github.com/dbsrgits/DBIx-Class>
132 =item * authorized committers: L<ssh://dbsrgits@git.shadowcat.co.uk/DBIx-Class.git>
134 =item * Travis-CI log: L<http://travis-ci.org/dbsrgits/dbix-class/builds>
137 <img src="https://secure.travis-ci.org/dbsrgits/dbix-class.png?branch=master"></img>
143 Create a schema class called MyApp/Schema.pm:
145 package MyApp::Schema;
146 use base qw/DBIx::Class::Schema/;
148 __PACKAGE__->load_namespaces();
152 Create a result class to represent artists, who have many CDs, in
153 MyApp/Schema/Result/Artist.pm:
155 See L<DBIx::Class::ResultSource> for docs on defining result classes.
157 package MyApp::Schema::Result::Artist;
158 use base qw/DBIx::Class::Core/;
160 __PACKAGE__->table('artist');
161 __PACKAGE__->add_columns(qw/ artistid name /);
162 __PACKAGE__->set_primary_key('artistid');
163 __PACKAGE__->has_many(cds => 'MyApp::Schema::Result::CD', 'artistid');
167 A result class to represent a CD, which belongs to an artist, in
168 MyApp/Schema/Result/CD.pm:
170 package MyApp::Schema::Result::CD;
171 use base qw/DBIx::Class::Core/;
173 __PACKAGE__->load_components(qw/InflateColumn::DateTime/);
174 __PACKAGE__->table('cd');
175 __PACKAGE__->add_columns(qw/ cdid artistid title year /);
176 __PACKAGE__->set_primary_key('cdid');
177 __PACKAGE__->belongs_to(artist => 'MyApp::Schema::Result::Artist', 'artistid');
181 Then you can use these classes in your application's code:
183 # Connect to your database.
185 my $schema = MyApp::Schema->connect($dbi_dsn, $user, $pass, \%dbi_params);
187 # Query for all artists and put them in an array,
188 # or retrieve them as a result set object.
189 # $schema->resultset returns a DBIx::Class::ResultSet
190 my @all_artists = $schema->resultset('Artist')->all;
191 my $all_artists_rs = $schema->resultset('Artist');
193 # Output all artists names
194 # $artist here is a DBIx::Class::Row, which has accessors
195 # for all its columns. Rows are also subclasses of your Result class.
196 foreach $artist (@all_artists) {
197 print $artist->name, "\n";
200 # Create a result set to search for artists.
201 # This does not query the DB.
202 my $johns_rs = $schema->resultset('Artist')->search(
203 # Build your WHERE using an SQL::Abstract structure:
204 { name => { like => 'John%' } }
207 # Execute a joined query to get the cds.
208 my @all_john_cds = $johns_rs->search_related('cds')->all;
210 # Fetch the next available row.
211 my $first_john = $johns_rs->next;
213 # Specify ORDER BY on the query.
214 my $first_john_cds_by_title_rs = $first_john->cds(
216 { order_by => 'title' }
219 # Create a result set that will fetch the artist data
220 # at the same time as it fetches CDs, using only one query.
221 my $millennium_cds_rs = $schema->resultset('CD')->search(
223 { prefetch => 'artist' }
226 my $cd = $millennium_cds_rs->next; # SELECT ... FROM cds JOIN artists ...
227 my $cd_artist_name = $cd->artist->name; # Already has the data so no 2nd query
229 # new() makes a Result object but doesnt insert it into the DB.
230 # create() is the same as new() then insert().
231 my $new_cd = $schema->resultset('CD')->new({ title => 'Spoon' });
232 $new_cd->artist($cd->artist);
233 $new_cd->insert; # Auto-increment primary key filled in after INSERT
234 $new_cd->title('Fork');
236 $schema->txn_do(sub { $new_cd->update }); # Runs the update in a transaction
238 # change the year of all the millennium CDs at once
239 $millennium_cds_rs->update({ year => 2002 });
243 This is an SQL to OO mapper with an object API inspired by L<Class::DBI>
244 (with a compatibility layer as a springboard for porting) and a resultset API
245 that allows abstract encapsulation of database operations. It aims to make
246 representing queries in your code as perl-ish as possible while still
247 providing access to as many of the capabilities of the database as possible,
248 including retrieving related records from multiple tables in a single query,
249 JOIN, LEFT JOIN, COUNT, DISTINCT, GROUP BY, ORDER BY and HAVING support.
251 DBIx::Class can handle multi-column primary and foreign keys, complex
252 queries and database-level paging, and does its best to only query the
253 database in order to return something you've directly asked for. If a
254 resultset is used as an iterator it only fetches rows off the statement
255 handle as requested in order to minimise memory usage. It has auto-increment
256 support for SQLite, MySQL, PostgreSQL, Oracle, SQL Server and DB2 and is
257 known to be used in production on at least the first four, and is fork-
258 and thread-safe out of the box (although
259 L<your DBD may not be|DBI/Threads and Thread Safety>).
261 This project is still under rapid development, so large new features may be
262 marked EXPERIMENTAL - such APIs are still usable but may have edge bugs.
263 Failing test cases are *always* welcome and point releases are put out rapidly
264 as bugs are found and fixed.
266 We do our best to maintain full backwards compatibility for published
267 APIs, since DBIx::Class is used in production in many organisations,
268 and even backwards incompatible changes to non-published APIs will be fixed
269 if they're reported and doing so doesn't cost the codebase anything.
271 The test suite is quite substantial, and several developer releases
272 are generally made to CPAN before the branch for the next release is
273 merged back to trunk for a major release.
275 =head1 WHERE TO GO NEXT
277 L<DBIx::Class::Manual::DocMap> lists each task you might want help on, and
278 the modules where you will find documentation.
282 mst: Matt S. Trout <mst@shadowcatsystems.co.uk>
284 (I mostly consider myself "project founder" these days but the AUTHOR heading
289 abraxxa: Alexander Hartmaier <abraxxa@cpan.org>
291 acca: Alexander Kuznetsov <acca@cpan.org>
293 aherzog: Adam Herzog <adam@herzogdesigns.com>
295 Alexander Keusch <cpan@keusch.at>
297 alexrj: Alessandro Ranellucci <aar@cpan.org>
299 alnewkirk: Al Newkirk <we@ana.im>
301 amiri: Amiri Barksdale <amiri@metalabel.com>
303 amoore: Andrew Moore <amoore@cpan.org>
305 andyg: Andy Grundman <andy@hybridized.org>
309 arc: Aaron Crane <arc@cpan.org>
311 arcanez: Justin Hunter <justin.d.hunter@gmail.com>
313 ash: Ash Berlin <ash@cpan.org>
315 bert: Norbert Csongradi <bert@cpan.org>
317 blblack: Brandon L. Black <blblack@gmail.com>
319 bluefeet: Aran Deltac <bluefeet@cpan.org>
321 bphillips: Brian Phillips <bphillips@cpan.org>
323 boghead: Bryan Beeley <cpan@beeley.org>
325 brd: Brad Davis <brd@FreeBSD.org>
327 bricas: Brian Cassidy <bricas@cpan.org>
329 brunov: Bruno Vecchi <vecchi.b@gmail.com>
331 caelum: Rafael Kitover <rkitover@cpan.org>
333 caldrin: Maik Hentsche <maik.hentsche@amd.com>
335 castaway: Jess Robinson
337 claco: Christopher H. Laco
341 da5id: David Jack Olrik <djo@cpan.org>
343 debolaz: Anders Nor Berle <berle@cpan.org>
345 dew: Dan Thomas <dan@godders.org>
347 dkubb: Dan Kubb <dan.kubb-cpan@onautopilot.com>
349 dnm: Justin Wheeler <jwheeler@datademons.com>
351 dpetrov: Dimitar Petrov <mitakaa@gmail.com>
353 dwc: Daniel Westermann-Clark <danieltwc@cpan.org>
355 dyfrgi: Michael Leuchtenburg <michael@slashhome.org>
357 edenc: Eden Cardim <edencardim@gmail.com>
359 felliott: Fitz Elliott <fitz.elliott@gmail.com>
361 freetime: Bill Moseley <moseley@hank.org>
363 frew: Arthur Axel "fREW" Schmidt <frioux@gmail.com>
365 goraxe: Gordon Irving <goraxe@cpan.org>
367 gphat: Cory G Watson <gphat@cpan.org>
369 Grant Street Group L<http://www.grantstreet.com/>
371 groditi: Guillermo Roditi <groditi@cpan.org>
373 Haarg: Graham Knop <haarg@haarg.org>
375 hobbs: Andrew Rodland <arodland@cpan.org>
377 ilmari: Dagfinn Ilmari MannsE<aring>ker <ilmari@ilmari.org>
379 initself: Mike Baas <mike@initselftech.com>
381 ironcamel: Naveed Massjouni <naveedm9@gmail.com>
383 jawnsy: Jonathan Yu <jawnsy@cpan.org>
385 jasonmay: Jason May <jason.a.may@gmail.com>
389 jgoulah: John Goulah <jgoulah@cpan.org>
391 jguenther: Justin Guenther <jguenther@cpan.org>
393 jhannah: Jay Hannah <jay@jays.net>
395 jnapiorkowski: John Napiorkowski <jjn1056@yahoo.com>
397 jon: Jon Schutz <jjschutz@cpan.org>
399 jshirley: J. Shirley <jshirley@gmail.com>
401 kaare: Kaare Rasmussen
403 konobi: Scott McWhirter
405 littlesavage: Alexey Illarionov <littlesavage@orionet.ru>
407 lukes: Luke Saunders <luke.saunders@gmail.com>
409 marcus: Marcus Ramberg <mramberg@cpan.org>
411 mattlaw: Matt Lawrence
413 mattp: Matt Phillips <mattp@cpan.org>
415 michaelr: Michael Reddick <michael.reddick@gmail.com>
417 milki: Jonathan Chu <milki@rescomp.berkeley.edu>
419 mjemmeson: Michael Jemmeson <michael.jemmeson@gmail.com>
421 mstratman: Mark A. Stratman <stratman@gmail.com>
423 ned: Neil de Carteret
425 nigel: Nigel Metheringham <nigelm@cpan.org>
427 ningu: David Kamholz <dkamholz@cpan.org>
429 Nniuq: Ron "Quinn" Straight" <quinnfazigu@gmail.org>
431 norbi: Norbert Buchmuller <norbi@nix.hu>
433 nuba: Nuba Princigalli <nuba@cpan.org>
435 Numa: Dan Sully <daniel@cpan.org>
437 ovid: Curtis "Ovid" Poe <ovid@cpan.org>
439 oyse: E<Oslash>ystein Torget <oystein.torget@dnv.com>
441 paulm: Paul Makepeace
443 penguin: K J Cheetham
445 perigrin: Chris Prather <chris@prather.org>
447 peter: Peter Collingbourne <peter@pcc.me.uk>
449 Peter Valdemar ME<oslash>rch <peter@morch.com>
451 phaylon: Robert Sedlacek <phaylon@dunkelheit.at>
453 plu: Johannes Plunien <plu@cpan.org>
455 Possum: Daniel LeWarne <possum@cpan.org>
457 quicksilver: Jules Bean
459 rafl: Florian Ragwitz <rafl@debian.org>
461 rainboxx: Matthias Dietrich <perl@rb.ly>
463 rbo: Robert Bohne <rbo@cpan.org>
465 rbuels: Robert Buels <rmb32@cornell.edu>
467 rdj: Ryan D Johnson <ryan@innerfence.com>
469 ribasushi: Peter Rabbitson <ribasushi@cpan.org>
471 rjbs: Ricardo Signes <rjbs@cpan.org>
473 robkinyon: Rob Kinyon <rkinyon@cpan.org>
475 Robert Olson <bob@rdolson.org>
477 Roman: Roman Filippov <romanf@cpan.org>
479 Sadrak: Felix Antonius Wilhelm Ostmann <sadrak@cpan.org>
481 sc_: Just Another Perl Hacker
483 scotty: Scotty Allen <scotty@scottyallen.com>
485 semifor: Marc Mims <marc@questright.com>
487 SineSwiper: Brendan Byrd <bbyrd@cpan.org>
489 solomon: Jared Johnson <jaredj@nmgi.com>
491 spb: Stephen Bennett <stephen@freenode.net>
493 Squeeks <squeek@cpan.org>
495 sszabo: Stephan Szabo <sszabo@bigpanda.com>
497 talexb: Alex Beamish <talexb@gmail.com>
499 tamias: Ronald J Kimball <rjk@tamias.net>
501 teejay : Aaron Trevena <teejay@cpan.org>
507 tonvoon: Ton Voon <tonvoon@cpan.org>
509 triode: Pete Gamache <gamache@cpan.org>
511 typester: Daisuke Murase <typester@cpan.org>
513 victori: Victor Igumnov <victori@cpan.org>
517 wesm: Wes Malone <wes@mitsi.com>
519 willert: Sebastian Willert <willert@cpan.org>
521 wreis: Wallace Reis <wreis@cpan.org>
523 xenoterracide: Caleb Cushing <xenoterracide@gmail.com>
525 yrlnry: Mark Jason Dominus <mjd@plover.com>
527 zamolxes: Bogdan Lucaciu <bogdan@wiz.ro>
531 Copyright (c) 2005 - 2011 the DBIx::Class L</AUTHOR> and L</CONTRIBUTORS>
536 This library is free software and may be distributed under the same terms