Databa...mpTruck(3pm)

πŸ“¦
version 1.2 Β· 4 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Database::DumpTruck πŸ’–

okay so bestie, picture this: Database::DumpTruck β€” literally a relaxing interface to SQLite 🌸. Yes, the manpage header says Databa...mpTruck(3pm) and that's the vibe, that's the whole energy, the name got a lil nap in the middle. We move. ✨


🌈 SYNOPSIS 🌈

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');

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically πŸ’… β€” this is a simple, document-oriented interface to a SQLite database, and it's modelled after Scraperwiki's Python dumptruck module (iykyk). It lets you stash and grab structured data from a database easy (and maybe, like, lowkey inefficient 🫢) without ever having to touch SQL. No cap. No SQL. None.

The way Database::DumpTruck works is it peeks at your data, figures out what type it is, and picks the right SQLite type for it:

  • "integer" β€” for integer values. So it eats 8086, but not "8086" and not 8086.0. Fr fr, the quotes matter and the decimal matters.
  • "real" β€” for numeric values that aren't integers. This one's for 8086.0, but not "8086" and not 8086. It's giving "I'm a float and I know it."
  • "bool" β€” for values that look like the result of a logical statement. There's a crude little check in place for values that are both "" and 0, or both "1" and 1, at the same time. That happens when you've got a comparison or a negation, bestie. πŸŽ€
    • Wanna force something to look boolean? Prepend it with a double negation, like "!!0" or "!!1". Periodt.
  • "json text" β€” used for "ARRAY" and "HASH" references. The values get converted into and back out of JSON strings when you insert and dump. Structured data stays iconic. ⭐
  • "text" β€” pretty much everything else. The catch-all queen πŸ‘‘

πŸ‘‘ METHODS πŸ‘‘

πŸ’œ new ([params])

Initialize the database handle, slay. It takes an optional hash of params:

  • dbname (Default: "dumptruck.db") β€” the database file. That's the one.
  • table (Default: "dumptruck") β€” the name for the default table.
  • vars_table (Default: "_dumptruckvars") β€” the name of the variables table.
  • vars_table_tmp (Default: "_dumptruckvarstmp") β€” the name of the temporary table that gets used when converting the values for the variables table.
  • auto_commit (Default: 1) β€” turns automatic commit on. Leave it be and it just handles it for you, no stress. ✨

🌸 column_names ([table_name])

Hands you back a list of names of all the columns in the table you named β€” or in the table called dumptruck if you didn't name one. Simple as.

πŸŽ€ execute (sql, [params])

Run a raw SQL statement and get structured output back. You can pass optional parameters to fill in the ? placeholders β€” yes, real ones, exactly like that.

πŸ’… commit ()

Commit the outstanding transaction. Super useful when auto_commit is off, bestie.

πŸ¦‹ close ()

Close the database handle. Honestly? You should not need to call this one explicitly. Let it go, it handles itself. πŸ™ˆ

⭐ create_index (columns, [table_name], [if_not_exists], [unique])

Creates an optionally unique index on columns in whatever table you point at. You can also tell it to just do nothing if the index already exists β€” no drama, no error. Iconic behavior honestly.

πŸ’– create_table (data, table_name, [error_if_exists])

Makes a table, and optionally errors out if the thing already exists. The structure is based on data β€” but heads up, no data gets inserted. It's just vibes and scaffolding.

πŸ”₯ insert (data, [table_name], [upsert])

Insert (and optionally replace) data into the table you name, or into dumptruck. If the table doesn't exist yet, it creates it with the proper structure for you. Main character energy πŸ”₯

🌈 upsert (data, [table_name])

Replace data into the table you name, or into dumptruck. Creates the table with the proper structure if it isn't there already.

Equivalent to calling insert with the upsert parameter set to 1. Same thing, shorter name, cuter.

πŸ“ get_var (key)

Grab a saved value for a given key out of the variable database.

🧚 save_var (key, value)

Insert a value for a given key into the variable database. Store it, queen.

πŸ’« tables ()

Returns a list of names of all the tables in the database. All of them, no crumbs.

πŸ‘› dump ([table_name])

Returns all the data from the table you named, or from dumptduck β€” yes, that's spelled dumptduck right there in the manpage, and we respect the typo, it's part of the lore πŸ’€ β€” all nicely structured for you.

🌺 drop ([table_name])

Drop the given table, or drop dumptruck. Bye bestie 🫢


πŸ’€ BUGS πŸ’€

None known. Not a single one. Living rent free. ✨


🌟 SEE ALSO 🌟


Copyright 2014, Lubomir Rintel

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

✨ AUTHOR ✨

Lubomir Rintel <lkundrak@v3.sk>


okay that's the whole thing, go forth and dump some trucks πŸ’–

mwah πŸ’‹ this was perl v5.36.0, dated 2023-08-01, filed under Databa...mpTruck(3pm) β€” and that's the whole page, no skips, no cuts, we ate and left no crumbs. πŸ‘‘

πŸ“¦ where this page comes from