NAME

NNexus::DB - DBI interface for NNexus, provides one DBI handle per NNexus::DB object.

SYNOPSIS

use NNexus::DB;
my $db = NNexus::DB(dbuser=>'nnexus',dbpass=>'pass',dbname=>"nnexus",dbhost=>"localhost", dbms=>"mysql");
my $connection_alive = $db->ping;
my $statement_handle = $db->prepare('DBI sql statement');
$db->execute('DBI sql statement');
my $disconnect_successful = $db->done;

DESCRIPTION

Interface to DBI's SQL logic. Provides an Object-oriented approach, where each NNexus::DB object contains a single DBI handle, together with a cache of prepared statements.

The documentation assumes basic familiarity with DBI.

METHODS

my $db = NNexus::Job->new(%options);

Creates a new NNexus::DB object. Required options are dbuser, dbpass, dbname, dbhost and dbms, so that the database connection can be successfully created.

my $response = $db->DBI_handle_command;

The NNexus::DB methods are interfaces to their counterparts in DBI, with the addition of a query cache and a safety mechanism that auto-vivifies the connection when needed.

The "safe" adverb returns a DBI handle, taking extra care that the handle is properly connected to the respective DB backend. While you could take the DBI handle and use it directly (it is the return value of the do method), avoid that approach.

Instead, always invoke DBI commands through NNexus::DB (or use the "safe" adverb to get a handle),
e.g. C<$db->execute>, C<$db->prepare> or C<$sth = $db->safe>
The cache of prepared statements is also rejuvenated whenever a new DBI handle is auto-created.
my $disconnect_successful = $db->done;

Disconnects from the backend and destroys the DBI handle. Note that the cache of prepared statements will be kept and rejuvenated when a new DBI handle is initialized.

my $statement_handle = $db->prepare;

Cached preparation of SQL statements. Internally uses the do adverb, to ensure robustness. Each SQL query and its DBI statement handle is cached, to avoid multiple prepare calls on the same query string.

AUTHOR

Deyan Ginev <d.ginev@jacobs-university.de>

COPYRIGHT

Research software, produced as part of work done by the KWARC group at Jacobs University Bremen. Released under the MIT license (MIT)