diff options
| author | adambrangenberg <adabran06@gmail.com> | 2025-12-24 03:40:10 +0100 |
|---|---|---|
| committer | adambrangenberg <adabran06@gmail.com> | 2025-12-24 03:40:10 +0100 |
| commit | a0886694f73fc382d78da79ab8bfb27475757bab (patch) | |
| tree | 652ba9b603a1acaf4dfca188f7bb2c29c6bccfd0 /src/Database.hs | |
| parent | 2b48a574e8b9fed03a5c1969af4bb1e338f1be26 (diff) | |
Implemented basic auth, refactor
Diffstat (limited to 'src/Database.hs')
| -rw-r--r-- | src/Database.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Database.hs b/src/Database.hs new file mode 100644 index 0000000..1bc7a6b --- /dev/null +++ b/src/Database.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Database (runDb, runMigrations) where + +import Control.Monad.Logger (runStderrLoggingT, LoggingT) +import Database.Persist.Sqlite (createSqlitePool, SqlBackend, runSqlPool, runMigration) +import Control.Monad.Reader (ReaderT) +import Data.User (migrateAll) + +-- | Run a database query in the IO monad. +runDb :: ReaderT SqlBackend (LoggingT IO) a -> IO a +runDb query = runStderrLoggingT $ do + pool <- createSqlitePool "jamaa.db" 10 + runSqlPool query pool + +-- | Run database migrations. +runMigrations :: IO () +runMigrations = runDb $ runMigration migrateAll |