diff --git a/backend/Main.hs b/backend/Main.hs index 1e81ad7..c7939eb 100644 --- a/backend/Main.hs +++ b/backend/Main.hs @@ -1,24 +1,20 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE LambdaCase #-} -import Control.Exception (bracket) -import Control.Monad (void, unless) -import Data.Int (Int32) -import Data.Maybe (listToMaybe) + +import Control.Exception (bracket) +import Control.Monad.Except import qualified Database.PostgreSQL.Typed as PG +import ICAFocus +import ICAFocus.Get + import DBConfig PG.useTPGDatabase myPGDatabase -data Ingredient = Ingredient Int32 - deriving (Eq) - -createThing :: PG.PGConnection -> Ingredient -> IO () -createThing pg (Ingredient product_id) = - void $ PG.pgExecute pg [PG.pgSQL|INSERT INTO ingredient (product_id) VALUES (${product_id})|] - main = bracket (PG.pgConnect myPGDatabase) PG.pgDisconnect $ \pg -> do - let ing = Ingredient 10 - createThing pg ing + let lök_id = 1282116 + (runExceptT $ getProduct pg lök_id) >>= \case + Right lök -> putStrLn $ "Lökat " ++ show lök + Left löklös -> putStrLn $ "Löklös? " ++ show löklös