NAME
Helix::Driver::DB - Helix Framework generic database driver.
SYNOPSIS
Example database driver:
package Helix::Driver::DB::Example;
use base qw/Helix::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 HXError::Driver::DB::SQL($function);
# never will reach here
return $self->execute($query, @params);
}
DESCRIPTION
The Helix::Driver::DB is a generic database driver for Helix Framework. 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, Helix Framework 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
Private methods are prefixed with _ symbol and placed in the end of the list.
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.
_init()
Class initialization. Performs a connection to database engine.
SEE ALSO
Helix, Helix::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