haskellsqlitereadonlyyesodpersistent

How to open a Sqlite3 database in read-only mode with persistent?


I currently use createSqlitePool from persistent-sqlite:

import Database.Persist.Sqlite

createSqlitePool "mydb.db" 10

According to Sqlite3 documentation I can pass additional parameters in connection strings, e.g.

"Data Source=c:\mydb.db;Version=3;Read Only=True;"

Cf. https://www.connectionstrings.com/sqlite-net-provider/read-only-connection/

Apparently, it's not possible to simply pass this connection string to createSqlitePool. Is there a way to tell persistent-sqlite to open my database read-only?


Solution

  • Persistent now supports Sqlite3-URI-syntax in connection strings, as documented here:

    https://github.com/yesodweb/persistent/wiki/Database-Configuration

    Thus, for read-only something like this works:

    URI filename style, relative path, read-only:

    file:sqlite3.db?mode=ro