From 4af96da5670566c111fa5c7dac9572eaac021a4b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 18 Jul 2023 00:02:33 +0200 Subject: [haskell] Refactored everything with a ReaderT pattern --- haskell/src/SpaceTraders/Database/Agents.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'haskell/src/SpaceTraders/Database/Agents.hs') diff --git a/haskell/src/SpaceTraders/Database/Agents.hs b/haskell/src/SpaceTraders/Database/Agents.hs index 48cd65b..b34ca04 100644 --- a/haskell/src/SpaceTraders/Database/Agents.hs +++ b/haskell/src/SpaceTraders/Database/Agents.hs @@ -1,13 +1,17 @@ {-# LANGUAGE OverloadedStrings #-} module SpaceTraders.Database.Agents - ( setAgent + ( addAgent ) where +import Control.Monad.Reader import Data.Aeson import qualified Database.SQLite.Simple as S +import SpaceTraders import SpaceTraders.Model.Agent -setAgent :: S.Connection -> Agent -> IO () -setAgent conn agent = S.execute conn "INSERT INTO agents(data) VALUES (json(?));" (S.Only (encode agent)) +addAgent :: (HasDatabaseConn env, MonadIO m, MonadReader env m) => Agent -> m () +addAgent agent = do + env <- ask + liftIO $ S.execute (getConn env) "INSERT INTO agents(data) VALUES (json(?));" (S.Only (encode agent)) -- cgit v1.2.3