diff --git a/backend/DBConfig.hs b/backend/DBConfig.hs new file mode 100644 index 0000000..c2ddc17 --- /dev/null +++ b/backend/DBConfig.hs @@ -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" + } \ No newline at end of file diff --git a/backend/Main.hs b/backend/Main.hs new file mode 100644 index 0000000..1e81ad7 --- /dev/null +++ b/backend/Main.hs @@ -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