http://www.perlmonks.org?node_id=1172586


in reply to Putting an SQLite DB file into memory

Hi, stevieb. I do this all the time, connect to a memory db as
$dbh=DBI->connect('dbi:SQLite:database=:memory:','','',{ PrintError=>0 +,RaiseError=>1 });
then use
$dbh->sqlite_backup_from_file( $filename ) or $dbh->sqlite_backup_to_file( $filename )
as desired.

Replies are listed 'Best First'.
Re^2: Putting an SQLite DB file into memory
by stevieb (Canon) on Oct 04, 2016 at 13:35 UTC

    This works brilliantly, and the feature is built right in! This is more than what I was looking for. Thanks clueless newbie :)

    I'm finally writing the tests for my app, and this works perfectly for testing, instead of copying a db file then removing it in each test file.

    I keep all configuration inside of the db as well as the data (generated every five seconds), so I think what I'm going to do is have the config aspect in a separate db on disk, and the streaming data in memory which I back up with a timed event.

    For those wondering, this is an application that gathers grow room environment information (temp, humidity so far, to also include water level, pH, EC/PPM etc for hydroponics, and soil moisture content data for soil) and writes it to what could be a volatile database. However, the configuration aspect of the system turns on/off electrical systems (lights, fans, humidifiers), so that part of the db must be reliably on disk, in case of a system crash/reboot, it needs to remember everything (timing, on/off configuration etc).