NAME
Eidolon::Driver::DB - Eidolon generic database driver.
SYNOPSIS
Example database driver:
package Eidolon::Driver::DB::Example;
use base qw/Eidolon::Driver::DB/;
sub new
{
my ($class, $self);
$class = shift;
$self = $class->SUPER::new("Example", @_);
return $self;
}
sub call
{
my ($self, $function, @params, $query);
($self, $function, @params) = @_;
throw DriverError::DB::SQL($function);
# never will reach here
return $self->execute($query, @params);
}
DESCRIPTION
The Eidolon::Driver::DB is a generic database driver for Eidolon. It declares some functions that are common for all driver types and some abstract methods, that must be overloaded in ancestor classes. All database drivers should subclass this package.
Actually, Eidolon database stack is more high-level abstraction over the DBI package. However, this abstraction is not ORM-like but makes SQL syntax differences between different DBMSs less visible.
To use database drivers you must have DBI and needed DBD packages installed.
METHODS
new($dbd, $db, $user, $password, $host, $port, $cfg)
Class constructor. Sets initial class data: $dbd
- DBI driver name, $db
- database name, $user
- database user name, $password
- database password, $host
- database host, $port
- database port, $cfg
- configuration hashref:
- auto_fetch
-
Automatically fetch all query results right after query execution. Default value is
0
. - auto_commit
-
Automatically commit transaction after each SQL query. Default value is
1
.
execute($query, @params)
Query execution. Given $query
executed with binded @params
. If any error occurs, exception is thrown.
execute_prepared(@params)
Prepared query execution. Previously executed query will be executed again with new @params
.
fetch()
Returns one row fetched from database or undef
if no results remained.
fetch_all()
Returns reference to array of all rows fetched from database after query execution.
free()
Clear in-memory cache of fetched data.
call($function, @params)
Call stored procedure or function with $function
as name and @params
as parameters. Abstract method, should be overloaded in ancestors.
SEE ALSO
Eidolon, Eidolon::Driver::DB::Exceptions
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Anton Belousov, <abel@cpan.org>
COPYRIGHT
Copyright (c) 2009, Atma 7, http://www.atma7.com