diff options
Diffstat (limited to 'src/server/Model/Database.hs')
-rw-r--r-- | src/server/Model/Database.hs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/server/Model/Database.hs b/src/server/Model/Database.hs new file mode 100644 index 0000000..abf235d --- /dev/null +++ b/src/server/Model/Database.hs @@ -0,0 +1,44 @@ +{-# LANGUAGE EmptyDataDecls #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeFamilies #-} + +module Model.Database where + +import Control.Monad.Logger (NoLoggingT, runNoLoggingT) +import Control.Monad.Trans.Resource (runResourceT, ResourceT) + +import Data.Text +import Data.Time.Clock (UTCTime) + +import Database.Persist.Sqlite +import Database.Persist.TH + +share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| +User + creation UTCTime + email Text + name Text + EmailKey email + deriving Show +Payment + userId UserId + creation UTCTime + name Text + cost Int + deriving Show +|] + +type Persist a = SqlPersistT (ResourceT (NoLoggingT IO)) a + +runDb :: Persist a -> IO a +runDb = runNoLoggingT . runResourceT . withSqliteConn "database" . runSqlConn + +runMigrations :: IO () +runMigrations = runDb $ runMigration migrateAll |