1Database::DumpTruck(3)User Contributed Perl DocumentationDatabase::DumpTruck(3)
2
3
4

NAME

6       Database::DumpTruck - Relaxing interface to SQLite
7

SYNOPSIS

9         my $dt = new Database::DumpTruck;
10
11         $dt->insert({Hello => 'World'});
12         $dt->create_index(['Hello']);
13         $dt->upsert({Hello => 'World', Yolo => 8086});
14         my $data = $dt->dump;
15
16         $dt->insert([
17             {Hello => 'World'},
18             {Hello => 'Hell', Structured => {
19                 key => value,
20                 array => [ 1, 2, 3, {} ],
21             }}], 'table2');
22         my $data2 = $dt->dump('table2');
23         $dt->drop('table2');
24         $dt->execute('SELECT 666');
25
26         my @columns = $dt->column_names();
27
28         $dt->save_var('number_of_the_beast', 666);
29         my $number_of_the_beast = $dt->get_var('number_of_the_beast');
30

DESCRIPTION

32       This is a simple document-oriented interface to a SQLite database,
33       modelled after Scraperwiki's Python "dumptruck" module. It allows for
34       easy (and maybe inefficient) storage and retrieval of structured data
35       to and from a database without interfacing with SQL.
36
37       Database::DumpTruck attempts to identify the type of the data you're
38       inserting and uses an appropriate SQLite type:
39
40       "integer"
41           This is used for integer values. Will be used for 8086, but not
42           "8086" or 8086.0.
43
44       "real"
45           This is used for numeric values that are not integer. Will be used
46           for 8086.0, but not "8086" or 8086.
47
48       "bool"
49           This is used for values that look like result of logical statemen.
50           A crude check for values that are both "" and 0 or both "1" and 1
51           at the same time is in place. This is a result of comparison or a
52           negation.
53
54           To force a value to look like boolean, prepend it with a double
55           negation: e.g.  "!!0" or "!!1".
56
57       "json text"
58           Used for "ARRAY" and "HASH" references. Values are converted into
59           and from JSON strings upon "insert" and "dump".
60
61       "text"
62           Pretty much everything else.
63

METHODS

65       new ([params])
66           Initialize the database handle. Accepts optional hash with
67           parameters:
68
69           dbname (Default: "dumptruck.db")
70                   The database file.
71
72           table (Default: "dumptruck")
73                   Name for the default table.
74
75           vars_table (Default: "_dumptruckvars")
76                   Name of the variables table.
77
78           vars_table_tmp (Default: "_dumptruckvarstmp")
79                   Name of the temporary table used when converting the values
80                   for variables table.
81
82           auto_commit (Default: 1)
83                   Enable automatic commit.
84
85       column_names ([table_name])
86           Return a list of names of all columns in given table, or table
87           "dumptruck".
88
89       execute (sql, [params])
90           Run a raw SQL statement and get structured output. Optional
91           parameters for "?"  placeholders can be specified.
92
93       commit ()
94           Commit outstanding transaction. Useful when "auto_commit" is off.
95
96       close ()
97           Close the database handle. You should not need to call this
98           explicitly.
99
100       create_index (columns, [table_name], [if_not_exists], [unique])
101           Create an optionally unique index on columns in a given table. Can
102           be told to do nothing if the index already exists.
103
104       create_table (data, table_name, [error_if_exists])
105           Create a table and optionally error out if it already exists. The
106           data structure will be based on data, though no data will be
107           inserted.
108
109       insert (data, [table_name], [upsert])
110           Insert (and optionally replace) data into a given table or
111           "dumptruck".  Creates the table with proper structure if it does
112           not exist already.
113
114       upsert (data, [table_name])
115           Replace data into a given table or "dumptruck". Creates the table
116           with proper structure if it does not exist already.
117
118           Equivalent to calling "insert" with "upsert" parameter set to 1.
119
120       get_var (key)
121           Retrieve a saved value for given key from the variable database.
122
123       save_var (key, value)
124           Insert a value for given key into the variable database.
125
126       tables ()
127           Returns a list of names of all tables in the database.
128
129       dump ([table_name])
130           Returns all data from the given table or "dumptduck" nicely
131           structured.
132
133       drop ([table_name])
134           Drop the given table or "dumptruck".
135

BUGS

137       None known.
138

SEE ALSO

140       ยท   <https://github.com/scraperwiki/dumptruck> - Python module this one
141           is heavily inspired by.
142
144       Copyright 2014, Lubomir Rintel
145
146       This program is free software; you can redistribute it and/or modify it
147       under the same terms as Perl itself.
148

AUTHOR

150       Lubomir Rintel <lkundrak@v3.sk>
151
152
153
154perl v5.28.1                      2019-02-02            Database::DumpTruck(3)
Impressum