diff --git a/src/Core.hs b/src/Core.hs index 5a28daa..96b8120 100644 --- a/src/Core.hs +++ b/src/Core.hs @@ -11,9 +11,7 @@ import Database.PostgreSQL.Simple.FromRow (FromRow, field, fromRow) import Database.PostgreSQL.Simple.ToField (ToField, toField) import Database.PostgreSQL.Simple.ToRow (ToRow, toRow) import Effectful -import Effectful.Dispatch.Dynamic import Effectful.Error.Static (Error, throwError) -import Effectful.FileSystem (FileSystem) import Effectful.Reader.Static (Reader) import GHC.Generics (Generic) import Servant hiding ((:>), throwError) @@ -21,8 +19,7 @@ import Servant hiding ((:>), throwError) -- -- Core data types -- -type AppEff = Eff '[ FileSystem - , Logger +type AppEff = Eff '[ Logger , Database , Reader AppEnv , Error ServerError @@ -51,6 +48,8 @@ instance ToJSON User instance FromJSON User data Database :: Effect where + DatabaseInit + :: Database (Eff es) () DatabaseRead :: (ToField a, Show a, FromRow b) => (Query, a) -> Database (Eff es) [b] DatabaseRead_ diff --git a/src/Database.hs b/src/Database.hs index 708d20b..573e7cf 100644 --- a/src/Database.hs +++ b/src/Database.hs @@ -38,7 +38,7 @@ databaseWrite databaseWrite = send . DatabaseWrite runDatabaseDebug :: DatabaseExeEffects es => Eff (Database : es) a -> Eff es a -runDatabaseDebug = interpret $ \_ -> \case +runDatabaseDebug = interpret $ \ -> \case DatabaseRead (statement, values) -> do liftIOE $ putStrLn $ "Mocked a READ database operation with statement:\n" diff --git a/src/Handlers.hs b/src/Handlers.hs index f6e42ba..2d4f45f 100644 --- a/src/Handlers.hs +++ b/src/Handlers.hs @@ -9,8 +9,6 @@ import Data.List import qualified Data.Text as T import Effectful import Effectful.Error.Static (Error, throwError) -import Effectful.FileSystem -import Effectful.FileSystem.IO.ByteString as EBS import Servant hiding ((:>), throwError) import qualified Servant as S @@ -21,7 +19,7 @@ rootHandler = (writeLog Info "Hit the root!") >>= \_ -> return "Hello, World!" userListHandler :: CRUD es => Eff es [User] -userListHandler = (writeLog Info "Selected all users!") >>= \_ -> +userListHandler = (writeLog Info "Selected all users!") >>= \_ -> databaseRead_ "SELECT id, name FROM users" userGetHandler :: CRUD es => UserId -> Eff es User diff --git a/src/Logger.hs b/src/Logger.hs index 36b2d47..d000d6c 100644 --- a/src/Logger.hs +++ b/src/Logger.hs @@ -7,7 +7,6 @@ import Data.Time (getCurrentTime, UTCTime) import Effectful import Effectful.Dispatch.Dynamic import Effectful.Error.Static (Error, throwError) -import Effectful.FileSystem import Effectful.Reader.Static import GHC.Generics (Generic) import Servant hiding ((:>)) diff --git a/src/Main.hs b/src/Main.hs index 5d513e1..f382abe 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -10,7 +10,6 @@ import Control.Monad.Except (ExceptT (ExceptT)) import Data.List import Effectful import Effectful.Error.Static (Error, runErrorNoCallStack, throwError) -import Effectful.FileSystem import Effectful.Reader.Static import Network.Wai.Handler.Warp (run) import Servant hiding ((:>), throwError) @@ -23,7 +22,7 @@ main :: IO () main = do pool <- createConnectionPool let env = AppEnv { pool = pool } - run port $ serve proxy $ app env + run port . serve proxy $ app env app :: AppEnv -> Server AppAPI app env = transformEff env @@ -42,7 +41,6 @@ transformEff env = hoistServer proxy . runReader env . runDatabaseIO . runLoggerPSQL - . runFileSystem port :: Int port = 8080