NAME
Nile::Database - SQL database manager.
SYNOPSIS
# set database connection params to connect
# $args{driver}, $args{host}, $args{dsn}, $args{port}, $args{attr}
# $args{name}, $args{user}, $args{pass}
# if called without params, it will try to load from the default config vars.
$dbh = $self->me->db->connect(%args);
DESCRIPTION
Nile::Database - SQL database manager.
dbh()
$self->me->db->dbh;
Current database connection handle.
connect()
$self->me->db->connect(%args);
Connect to the database. If %args empty, it will try to get args from the config object. Returns the database connection handle is success.
disconnect()
$self->me->db->disconnect;
Disconnect from this connection handle.
run()
$self->me->db->run($qry);
Run query using the DBI do command or abort if error.
do()
$self->me->db->do($qry);
Run query using the DBI do command and ignore errors.
exec()
$sth = $self->me->db->exec($qry);
Prepare and execute the query and return the statment handle.
begin_work()
$self->me->db->begin_work;
Enable transactions (by turning AutoCommit off) until the next call to commit or rollback. After the next commit or rollback, AutoCommit will automatically be turned on again.
commit()
$self->me->db->commit;
Commit (make permanent) the most recent series of database changes if the database supports transactions and AutoCommit is off.
rollback()
$self->me->db->rollback;
Rollback (undo) the most recent series of uncommitted database changes if the database supports transactions and AutoCommit is off.
quote()
$self->me->db->quote($value);
$self->me->db->quote($value, $data_type);
Quote a string literal for use as a literal value in an SQL statement, by escaping any special characters (such as quotation marks) contained within the string and adding the required type of outer quotation marks.
col()
# select id from users. return one column array from all rows
@cols = $self->me->db->col($qry);
$cols_ref = $self->me->db->col($qry);
Return one column array from all rows
row()
# select id, email, fname, lname from users
@row = $self->me->db->row($qry);
Returns one row as array.
rows()
# select id, fname, lname, email from users
@rows = $self->me->db->rows($qry);
$rows_ref = $self->me->db->rows($qry);
Returns all matched rows as array or array ref.
hash()
# select * from users where id=$id limit 1
%user = $self->me->db->hash($qry);
$user_ref = $self->me->db->hash($qry);
Returns one row as a hash or hash ref
row_object()
# select * from users where id=$id limit 1
$row_obj = $self->me->db->row_object($qry);
print $row_obj->email;
print $row_obj->fname;
print $row_obj->lname;
Returns one row as object with columns names as object properties.
hashes()
%hashes = $self->me->db->hashes($qry, $col);
$hashes_ref = $self->me->db->hashes($qry, $col);
Returns list or hashes of all rows. Each hash element is a hash of one row
colhash()
# select id, user from users
%hash = $self->me->db->colhash($qry);
Returns all rows as a hash of the first column as the keys and the second column as the values.
value()
# select email from users where id=123. return one column value
$value = $self->me->db->value($qry);
Returns one column value from one row.
insertid()
$id = $self->me->db->insertid;
Returns the last insert id from auto increment.
db_error()
$self->me->db->db_error;
Aborts the application and display the last database error message.
Bugs
This project is available on github at https://github.com/mewsoft/Nile.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Nile.
SOURCE
Source repository is at https://github.com/mewsoft/Nile.
AUTHOR
Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com
COPYRIGHT AND LICENSE
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.