CallBackery::Database - database access helpers
use CallBackery::Database; my $db = CallBackery::Database->new(app=>$self->config); my ($fields,$values) = $self->map2sql(table,data); my $selWhere = $self->map2where(table,data); my $rowHash = $self->fetchRow(table,{field=>val,field=>val},selExpression?); my $value = $self->fetchValue(table,{field=>val,field=>val},column); my $id = $self->matchData(table,{field=>val,field=>val}); my $id = $self->lookUp(table,field,value); my $id = $self->updateOrInsertData(table,{dataField=>val,...},{matchField=>val,...}?); my $id = $self->insertIfNew(table,{field=>val,field=>val});
Database access helpers.
object needs access to the system config to get access to the database
a dbi database handle
map2sql(table,data)
Provide two hash pointers and quote the field names for inclusion into an SQL expression. Build field names according to the table_field rule.
map2where(table,data)
build a where statement Find a record matching the given data in a table the data is a map. Quote field names and values. Build field names according to the table_field rule.
getMap(table,column)
Get an array of hashes with model and label tags:
[{model: x, label: y},{id ...},...]
getRowHash(table,{key=
Get a hash with record index as key. Optionally with a list of columns to return.
{ 2 => { a=>x, b=>y }, 3 => { a=>k, b=>r } }
fetchRow(table,{key=
Find a record matching the given data in a table and return a hash of the matching record.
fetchValue(table,{key=
Find a record matching the given data in a table and returns the value in column.
matchData(table,data)
Find a record matching the given data in a table the data is a map.
lookUp(table,column,value)
Lookup the value in table in table_column and return table_id. Throw an exception if this fails. Use matchData if you are just looking.
updateOrInsertData(table,data,match?)
Insert the given data into the table. If a match map is given, try an update first with the given match only insert when update has 0 hits.
insertIfNew(table,data)
Lookup the given data. If it is new, insert a record. Returns the matching Id.
deleteData(table,id)
Delete data from table. Given the record id. Returns true if the record was deleted.
deleteDataWhere(table,{key=
Delete data from table. Given the column title and the matching value. Returns true if the record was deleted.
return a raw data value from the config table
write a config value
Copyright (c) 2015 by OETIKER+PARTNER AG. All rights reserved.
Tobi Oetiker <tobi@oetiker.ch>
2010-06-12 to 1.0 initial 2013-11-19 to 1.1 converted to mojo
To install CallBackery, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CallBackery
CPAN shell
perl -MCPAN -e shell install CallBackery
For more information on module installation, please visit the detailed CPAN module installation guide.