Search code examples
sqlitecommon-lispclsql

Write sqlite3 in-memory database into file using clsql


As the question indicates. I created an in-memory database using ":memory:" and clsql:with-database to increase write/insert-query performance. But in the end I do want to have a permanent copy of the filled database on my hard drive.

It should look something like this:

(clsql:with-database (db (":memory:") :database-type :sqlite3)
  ;;entering db-scheme
  ;;entering a bunch of data
  (magically-write-database-to-file db file-path))

How can I achieve this?


Solution

  • If you do not care about data consistency before the database creation has finished, just use a normal database file and configure it to disable transactions and disk synchronization:

    (execute-command "PRAGMA journal_mode = OFF")
    (execute-command "PRAGMA synchronous = OFF")