Objects::Collection::AutoSQL - class for collections of data, stored in database.
use Objects::Collection::AutoSQL; my $metaobj = new Objects::Collection::AutoSQL:: dbh => $dbh, #database connect table => 'metadata', #table name field=> 'mid', #key field (IDs), usually primary,autoincrement cut_key =>1, #delete field mid from readed records, #or delete_key=>1 sub_ref => #callback for create objects for readed records sub { my $id = shift; new MyObject:: shift }
Provide simply access to records, with unique field.
For exampe:
HAVE mysql table: mysql> \u orders mysql> select * from beers; +-----+--------+-----------+ | bid | bcount | bname | +-----+--------+-----------+ | 1 | 1 | heineken | | 2 | 1 | broadside | | 3 | 2 | tiger | | 4 | 2 | castel | | 5 | 3 | karhu | +-----+--------+-----------+ 5 rows in set (0.00 sec) my $beers = new Objects::Collection::AutoSQL:: dbh => $dbh, #database connect table => 'beers', #table name field => 'bid', #key field (IDs), usually primary,autoincrement cut_key => 1; #delete field 'bid' from readed records, my $heineken = $beers->fetch_object(1); #SELECT * FROM beers WHERE bid in (1) print Dumper($heineken); ... $VAR1 = { 'bcount' => '1', 'bname' => 'heineken' }; ... $heineken->{bcount}++; my $karhu = $beers->fetch_object(5); #SELECT * FROM beers WHERE bid in (5) $karhu->{bcount}++; $beers->store_changed; #UPDATE beers SET bcount='2',bname='heineken' where bid=1 #UPDATE beers SET bcount='4',bname='karhu' where bid=5 my $hash1 = $beers->fetch_objects({bcount=>[4,1]}); #SELECT * FROM beers WHERE ( bcount in (4,1) ) print Dumper($hash); ... $VAR1 = { '2' => { 'bcount' => '1', 'bname' => 'broadside' }, '5' => { 'bcount' => '4', 'bname' => 'karhu' } }; ...
Return current $dbh.
Return ref to ARRAY of readed IDs.
Objects::Collection::ActiveRecord, Objects::Collection, README
Zahatski Aliaksandr, <zag@cpan.org>
Copyright (C) 2005-2006 by Zahatski Aliaksandr
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install Objects::Collection, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Objects::Collection
CPAN shell
perl -MCPAN -e shell install Objects::Collection
For more information on module installation, please visit the detailed CPAN module installation guide.