Proper Main

main
xenia 2023-08-15 12:24:19 +02:00
parent c359cdf84a
commit 29039f1c20
1 changed files with 11 additions and 15 deletions

View File

@ -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.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