Use pooling and add a general Reader record to the stack by default

This commit is contained in:
James Eversole
2024-10-13 10:40:51 -05:00
parent 303c923552
commit d8f5110b02
5 changed files with 49 additions and 26 deletions

View File

@@ -9,6 +9,7 @@ import Data.List
import Effectful
import Effectful.Error.Static (Error, runError, runErrorNoCallStack, throwError)
import Effectful.FileSystem
import Effectful.Reader.Static
import Network.Wai.Handler.Warp (run)
import Servant hiding ((:>), throwError)
import qualified Servant as S
@@ -17,22 +18,27 @@ import qualified Servant as S
-- Application
--
main :: IO ()
main = run port $ serve proxy app
main = do
pool <- createConnectionPool
let env = AppEnv { pool = pool }
run port $ serve proxy $ app env
app :: Server AppAPI
app = α $ rootHandler
app :: AppEnv -> Server AppAPI
app env = transformEff env
$ rootHandler
:<|> userListHandler
:<|> userGetHandler
:<|> userPostHandler
α :: ServerT AppAPI AppEff -> ServerT AppAPI Handler
α = hoistServer proxy
transformEff :: AppEnv -> ServerT AppAPI AppEff -> ServerT AppAPI Handler
transformEff env = hoistServer proxy
$ Handler
. ExceptT
. runEff
. runErrorNoCallStack
. runLoggerIO
. runFileSystem
. runReader env
. runDatabaseIO
port :: Int