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/Ships.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'haskell/src/SpaceTraders/Database/Ships.hs') diff --git a/haskell/src/SpaceTraders/Database/Ships.hs b/haskell/src/SpaceTraders/Database/Ships.hs index 81c422d..95b0b5d 100644 --- a/haskell/src/SpaceTraders/Database/Ships.hs +++ b/haskell/src/SpaceTraders/Database/Ships.hs @@ -4,10 +4,14 @@ module SpaceTraders.Database.Ships ( addShip ) where +import Control.Monad.Reader import Data.Aeson import qualified Database.SQLite.Simple as S +import SpaceTraders import SpaceTraders.Model.Ship -addShip :: S.Connection -> Ship -> IO () -addShip conn ship = S.execute conn "INSERT INTO ships(data) VALUES (json(?));" (S.Only (encode ship)) +addShip :: (HasDatabaseConn env, MonadIO m, MonadReader env m) => Ship -> m () +addShip ship = do + env <- ask + liftIO $ S.execute (getConn env) "INSERT INTO ships(data) VALUES (json(?));" (S.Only (encode ship)) -- cgit v1.2.3