bare bones haskell

main
xenia 2023-08-09 23:05:56 +02:00
parent bc45ec5fe0
commit 5848867423
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,12 @@
{-# LANGUAGE OverloadedStrings #-}
module DBConfig where
import qualified Database.PostgreSQL.Typed as PG
import Network.Socket (SockAddr(SockAddrUnix))
myPGDatabase :: PG.PGDatabase
myPGDatabase = PG.defaultPGDatabase
{ PG.pgDBAddr = Left ("localhost", "2137")
, PG.pgDBUser = "matabasare"
, PG.pgDBName = "matabas"
}

24
backend/Main.hs 100644
View File

@ -0,0 +1,24 @@
{-# 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