Database::DumpTruck - Relaxing interface to SQLite
my $dt = new Database::DumpTruck; $dt->insert({Hello => 'World'}); $dt->create_index(['Hello']); $dt->upsert({Hello => 'World', Yolo => 8086}); my $data = $dt->dump; $dt->insert([ {Hello => 'World'}, {Hello => 'Hell', Structured => { key => value, array => [ 1, 2, 3, {} ], }}], 'table2'); my $data2 = $dt->dump('table2'); $dt->drop('table2'); $dt->execute('SELECT 666'); my @columns = $dt->column_names(); $dt->save_var('number_of_the_beast', 666); my $number_of_the_beast = $dt->get_var('number_of_the_beast');
This is a simple document-oriented interface to a SQLite database, modelled after Scraperwiki's Python dumptruck module. It allows for easy (and maybe inefficient) storage and retrieval of structured data to and from a database without interfacing with SQL.
dumptruck
Database::DumpTruck attempts to identify the type of the data you're inserting and uses an appropriate SQLite type:
integer
This is used for integer values. Will be used for 8086, but not "8086" or 8086.0.
8086
"8086"
8086.0
real
This is used for numeric values that are not integer. Will be used for 8086.0, but not "8086" or 8086.
bool
This is used for values that look like result of logical statemen. A crude check for values that are both "" and 0 or both "1" and 1 at the same time is in place. This is a result of comparison or a negation.
""
0
"1"
1
To force a value to look like boolean, prepend it with a double negation: e.g. !!0 or !!1.
!!0
!!1
json text
Used for ARRAY and HASH references. Values are converted into and from JSON strings upon insert and dump.
ARRAY
HASH
insert
dump
text
Pretty much everything else.
Initialize the database handle. Accepts optional hash with parameters:
dumptruck.db
The database file.
Name for the default table.
_dumptruckvars
Name of the variables table.
_dumptruckvarstmp
Name of the temporary table used when converting the values for variables table.
Enable automatic commit.
Return a list of names of all columns in given table, or table dumptruck.
Run a raw SQL statement and get structured output. Optional parameters for ? placeholders can be specified.
?
Commit outstanding transaction. Useful when auto_commit is off.
auto_commit
Close the database handle. You should not need to call this explicitly.
Create an optionally unique index on columns in a given table. Can be told to do nothing if the index already exists.
Create a table and optionally error out if it already exists. The data structure will be based on data, though no data will be inserted.
Insert (and optionally replace) data into a given table or dumptruck. Creates the table with proper structure if it does not exist already.
Replace data into a given table or dumptruck. Creates the table with proper structure if it does not exist already.
Equivalent to calling insert with upsert parameter set to 1.
upsert
Retrieve a saved value for given key from the variable database.
Insert a value for given key into the variable database.
Returns a list of names of all tables in the database.
Returns all data from the given table or dumptduck nicely structured.
dumptduck
Drop the given table or dumptruck.
None known.
https://github.com/scraperwiki/dumptruck - Python module this one is heavily inspired by.
Copyright 2014, Lubomir Rintel
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Lubomir Rintel <lkundrak@v3.sk>
To install Database::DumpTruck, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Database::DumpTruck
CPAN shell
perl -MCPAN -e shell install Database::DumpTruck
For more information on module installation, please visit the detailed CPAN module installation guide.