Proper Main
This commit is contained in:
parent
c359cdf84a
commit
29039f1c20
|
@ -1,24 +1,20 @@
|
||||||
{-# LANGUAGE DataKinds #-}
|
|
||||||
{-# LANGUAGE QuasiQuotes #-}
|
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
{-# LANGUAGE LambdaCase #-}
|
||||||
|
|
||||||
import Control.Exception (bracket)
|
|
||||||
import Control.Monad (void, unless)
|
import Control.Exception (bracket)
|
||||||
import Data.Int (Int32)
|
import Control.Monad.Except
|
||||||
import Data.Maybe (listToMaybe)
|
|
||||||
import qualified Database.PostgreSQL.Typed as PG
|
import qualified Database.PostgreSQL.Typed as PG
|
||||||
|
|
||||||
|
import ICAFocus
|
||||||
|
import ICAFocus.Get
|
||||||
|
|
||||||
import DBConfig
|
import DBConfig
|
||||||
|
|
||||||
PG.useTPGDatabase myPGDatabase
|
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
|
main = bracket (PG.pgConnect myPGDatabase) PG.pgDisconnect $ \pg -> do
|
||||||
let ing = Ingredient 10
|
let lök_id = 1282116
|
||||||
createThing pg ing
|
(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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user