25 lines
718 B
Haskell
25 lines
718 B
Haskell
|
{-# LANGUAGE DataKinds #-}
|
||
|
{-# LANGUAGE QuasiQuotes #-}
|
||
|
{-# LANGUAGE TemplateHaskell #-}
|
||
|
|
||
|
import Control.Exception (bracket)
|
||
|
import Control.Monad (void, unless)
|
||
|
import Data.Int (Int32)
|
||
|
import Data.Maybe (listToMaybe)
|
||
|
import qualified Database.PostgreSQL.Typed as PG
|
||
|
|
||
|
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
|