diff options
author | Joris Guyonvarch | 2015-07-06 00:16:45 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-07-06 00:16:45 +0200 |
commit | 4ce9751c9e645916fdde71874c2cdadd252f32a0 (patch) | |
tree | 1014c58787231cbdc3ae2799f32127b40ab393ab /src/server/Model/Database.hs |
Setting up Scotty, Persistent, Clay, Blaze, Esqueleto, Elm
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 |