SQL::DB

Perl interface to SQL Databases
Download

SQL::DB Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Mark Lawrence
  • Publisher web site:
  • http://search.cpan.org/~mlawren/

SQL::DB Tags


SQL::DB Description

SQL::DB is a Perl module that provides a low-level interface to SQL databases, using Perl objects and logic operators. It is NOT an Object Relational Mapper like Class::DBI and neither is it an abstraction such as SQL::Abstract. It falls somewhere inbetween.After using define_tables() to specify your schema and creating an SQL::DB object, the typical workflow is as follows:* connect() to the database* deploy() the schema (CREATE TABLEs etc)* Using one or more "abstract rows" obtained via arow() you can do() insert, update or delete queries.* Using one or more "abstract rows" obtained via arow() you can fetch() (select) data to work with (and possibly modify).* Repeat the above three steps as needed. Further queries (with a higher level of automation) are possible with the objects returned by fetch().* disconnect() from the database.SQL::DB is capable of generating just about any kind of query, including, but not limited to, JOINs, nested SELECTs, UNIONs, database-side operator invocations, function calls, aggregate expressions, etc. However this package is still quite new, and nowhere near complete. Feedback, testing, and (even better) patches are all welcome.SYNOPSIS use SQL::DB qw(define_tables count max); define_tables( , column => , column => , ], , column => , column => , column => , column => , index => 'name', ] ); my $db = SQL::DB->new(); $db->connect('dbi:SQLite:/tmp/sqldbtest.db', 'user', 'pass', {}); $db->deploy; my $persons = $db->arow('persons'); my $addresses = $db->arow('addresses'); $db->do( insert => , values => , ); $db->do( insert => , values => , # Pg: , where => $persons->name == 'Homer', ); my $ans = $db->fetch1( select => , from => $persons, where => $persons->age > 40, ); # The following prints "Head count: 1 Max age:43" print 'Head count: '. $ans->count_name . ' Max age: '. $ans->max_age ."\n"; my @items = $db->fetch( select => , from => $persons, left_join => $addresses, on => $addresses->id == $persons->address, where => ($addresses->city == 'Springfield') & ($persons->age > 40), order_by => $persons->age->desc, limit => 10, ); # Give me "Homer(43) lives in Springfield" foreach my $item (@items) { print $item->name, '(',$item->age,') lives in ', $item->city, "\n"; }Product's homepage


SQL::DB Related Software