SeeAlso::DBI - Store SeeAlso::Response objects in database.
version 0.71
# use database as SeeAlso::Source my $dbh = DBI->connect( ... ); my $dbi = SeeAlso::DBI->new( dbh => $dbh ); print SeeAlso::Server->new->query( $dbi );
A SeeAlso::DBI object manages a store of SeeAlso::Response objects that are stored in a database. By default that database must contain a table named seealso with rows named key, label, database, and uri. A query for identifier $id of type SeeAlso::Identifier will result in an SQL query such as
SeeAlso::DBI
seealso
key
label
database
uri
$id
SELECT label, description, uri FROM seealso WHERE key=?
With the hashed identifier ($id<gthash>) used as key parameter. By default a database table accessed with this class stores the four values key, label, description, and uri in each row - but you can also use other schemas.
$id<gt
Create a new database store. You must specify either a database handle in form or a DBI object with parameter dbh parameter, or a dbi parameter that is passed to DBI->connect, or a config parameter to read setting from the DBI section of a configuration hash reference.
dbh
dbi
DBI->connect
config
DBI
my $dbh = DBI->new( "dbi:mysql:database=$d;host=$host", $user, $password ); my $db = SeeAlso::DBI->new( dbh => $dbh ); my $db = SeeAlso::DBI->new( dbi => "dbi:mysql:database=$database;host=$host", user => $user, passwort => $password ); use YAML::Any qw(LoadFile); my $config = LoadFile("dbiconnect.yml"); my $db = SeeAlso::DBI->new( config => $config ); my $db = SeeAlso::DBI->new( $%{$config->{DBI}} ); # same
The configuration hash can be stored in a configuration file (INI, YAML, etc.) and must contains a section named DBI. All values specified in this section are added to the constructor's parameter list. A configuration file could look like this (replace uppercase values with real values):
DBI: dbi : mysql:database=DBNAME;host=HOST user : USER password : PWD
The following parameters are recognized:
Database Handle of type DBI.
Database Handle of type DBI that will be used for all read access. Usefull for master-slave database settings.
Source parameter to create a DBI object. "dbi:" is prepended if the parameter does not start with this prefix.
"dbi:"
Username if parameter dbi is given.
Password if parameter dbi is given.
SQL table name for default SQL statements (default: seealso).
SQL statement to select rows.
SQL statement to delete rows.
SQL statement to insert rows.
SQL statement to clear the database table.
Newly create the SQL table with the create statement.
Do not store the label in the database but use this value instead.
Do not store the description in the database but use this value instead.
Do not store the uri in the database but use this value instead.
One of 'hash' (default), 'value', 'canonical' or a code that the identifier is passed to before beeing used as key. Only useful when used together with parameter idtype.
idtype
Subclass of SeeAlso::Identifier to be use when creating an identifier.
Configuration settings as hash reference or as configuration file that will be read into a hash reference. Afterwarrds the The DBI section of the configuration is added to the other parameters (existing parameters are not overridden).
Fetch from DB, uses the key value ($identifier->hash by default).
Get a key value for a given SeeAlso::Identifier.
Create the database table.
Delete all content in the database. Be sure not to call this by accident!
Delete the whole database table. Be sure not to call this by accident!
Removes all rows associated with a given identifier.
Replace all rows associated with the the identifier of a given response with the new response.
Add a SeeAlso::Response to the database (unless the response is empty). Returns the number of affected rows or -1 if the database driver cannot determine this number.
Add a set of quadrupels to the database. The subroutine $fetch_quadruple_sub is called unless without any parameters, until it returns a false value. It is expected to return a reference to an array with four values (key, label, description, uri) which will be added to the database. Returns the number of affected rows or -1 if the database driver cannot determine this number.
TODO: remove enrichment!
This package was partly inspired by on CHI::Driver::DBI by Justin DeVuyst and Perrin Harkins.
Jakob Voss
This software is copyright (c) 2013 by Jakob Voss.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install SeeAlso::Server, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SeeAlso::Server
CPAN shell
perl -MCPAN -e shell install SeeAlso::Server
For more information on module installation, please visit the detailed CPAN module installation guide.