feat: add Sis.Database module with openDatabase
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
{- | SQLite database support for Sis.
|
||||||
|
|
||||||
|
Opens (and creates if missing) a SQLite database with WAL journal
|
||||||
|
mode and foreign keys enabled.
|
||||||
|
-}
|
||||||
|
module Sis.Database (
|
||||||
|
openDatabase,
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Database.SQLite.Simple qualified as SQL
|
||||||
|
|
||||||
|
-- | Open (or create) a SQLite database at the given path.
|
||||||
|
--
|
||||||
|
-- Enables WAL journal mode for concurrent read performance and
|
||||||
|
-- enables foreign key enforcement.
|
||||||
|
openDatabase :: FilePath -> IO SQL.Connection
|
||||||
|
openDatabase path = do
|
||||||
|
conn <- SQL.open path
|
||||||
|
SQL.execute_ conn "PRAGMA journal_mode=WAL"
|
||||||
|
SQL.execute_ conn "PRAGMA foreign_keys=ON"
|
||||||
|
pure conn
|
||||||
Reference in New Issue
Block a user