Add a few calls

This commit is contained in:
2022-12-05 17:45:07 +01:00
parent e908d9dd8e
commit 3e4548dc75
3 changed files with 88 additions and 8 deletions
+22
View File
@@ -1,3 +1,4 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
@@ -69,6 +70,12 @@ locations = all_ garfieldDb.locations
-- Inserts
runIns
:: Connection
-> SqlInsert Postgres table
-> IO ()
runIns conn i = runBeamPostgresDebug putStrLn conn $ runInsert i
transfer
:: InventoryItemId -- ^ to
-> InventoryItemId -- ^ from
@@ -94,6 +101,9 @@ transfer from to amount
type SqlFunction a = Connection -> IO a
runFunction :: Connection -> SqlFunction a -> IO a
runFunction conn f = f conn
snackDelete :: SnackId -> SqlFunction ()
snackDelete snack conn = do
[Only ()] <- query conn "SELECT garfield.snack_delete(?)" (Only $ snack.unSnackId)
@@ -105,6 +115,18 @@ snackCreate name barcode price taxGroup location conn = do
(name, barcode, price, taxGroup.unTaxGroupId, location.unLocationId)
pure $ mkSnackId rawSnackId
snackUpdate
:: SnackId
-> Text -- Name
-> Text -- Barcode
-> Scientific
-> TaxGroupId
-> SqlFunction SnackId
snackUpdate snack name barcode price taxGroup conn = do
[Only rawSnackId] <- query conn "SELECT garfield.snack_update(?, ?, ?, ?, ?)"
(snack.unSnackId, name, barcode, price, taxGroup.unTaxGroupId)
pure $ mkSnackId rawSnackId
inventoryMapSnack :: SnackId -> InventoryItemId -> SqlFunction ()
inventoryMapSnack snack item conn = do
[Only ()] <- query conn "SELECT garfield.inventory_map_snack(?, ?)" (snack.unSnackId, item.unInventoryItemId)