SQLite User Forum

Save in memory db to hd
Login

Save in memory db to hd

(1) By Wøødy (Woody.033) on 2022-03-30 21:44:47 [link] [source]

Hello,
I would like to create a in memory db in PowerShell v5
That I have figured out, but for the like of me, saving that db to a HD eludes me
Any assistance would be appreciated
Wøødy

(2) By Warren Young (wyoung) on 2022-03-30 22:04:38 in reply to 1 [link] [source]

(3) By Simon Slavin (slavin) on 2022-03-31 02:26:39 in reply to 1 [link] [source]

Warran posted the favourite reply. If you can't use that for some reason, there's another one:

https://www.sqlite.org/c3ref/serialize.html

(4) By Larry Brasfield (larrybr) on 2022-03-31 04:10:49 in reply to 1 [source]

Let's not overlook the Backup API.

(5) By midijohnny on 2022-03-31 07:30:06 in reply to 1 [link] [source]

Using the CLI - you can use the '.save' dot-command. Example below (Note Linux Bash - not Powershell - but should be the same).

Create objects in-memory, then save:

dbuser@myhost:~$ sqlite3
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> create table my_table(a,b,c);
sqlite> .tables
my_table
sqlite> .save my_database.db
sqlite> .quit

Load from file:

dbuser@myhost:~$ sqlite3 my_database.db
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> .tables
my_table

(6) By Larry Brasfield (larrybr) on 2022-03-31 09:06:05 in reply to 5 [link] [source]

The CLI's .save (along with its alias, .backup) is the write-out portion of the backup API, with human-typable input. Similarly, .restore is the read-in portion of that API.