NAME
SQLx::Core - Object Oriented access to DBI
DESCRIPTION
Access the DBI module in a friendly, and OO fashion. Create sub-routines for your results and manipulate them in any way possible by Perl.
SYNOPSIS
# MySchema.pm
package MySchema;
use base 'SQLx::Core';
use MySchema::ResultSet::MyTable;
use MySchema::Result::MyTable;
1;
# MySchema/ResultSet/MyTable.pm
package MySchema::ResultSet::MyTable;
use base 'SQLx::Core::ResultSet';
sub table { 'my_real_table_name'; } # Important!
sub rows { my $self = shift; return $self->count; }
1;
# MySchema/Result/MyTable.pm
package MySchema::Result::MyTable;
use base 'SQLx::Core::Result';
sub name {
my $self = shift;
return $self->{result}->{name};
}
1;
# test.pl
use MySchema;
my $schema = MySchema->connect(
dbi => 'SQLite:test.db',
);
my $rs = $schema->resultset('MyTable');
my $rset = $rs->search([], { status => 'active' });
print "Rows: " . $rset->rows . "\n";
while(my $row = $rset->next) {
print $row->{id};
}
my $rset2 = $rs->find([], { id => 4 });
print $rset2->name . "\n";
connect
Creates the Schema instance using the hash specified. Currently only dbi is mandatory, which tells DBI which engine to use (SQLite, Pg, etc). If you're using SQLite there is no need to set user or pass.
my $dbh = SQLx::Core->connect(
dbi => 'SQLite:/var/db/test.db',
);
my $dbh = SQLx::Core->connect(
dbi => 'Pg:host=myhost;dbname=dbname',
user => 'username',
pass => 'password',
);
AUTHOR
Brad Haywood <brad@geeksware.net>
LICENSE
Same license as Perl