bare bones haskell
This commit is contained in:
parent
bc45ec5fe0
commit
5848867423
12
backend/DBConfig.hs
Normal file
12
backend/DBConfig.hs
Normal 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
Normal file
24
backend/Main.hs
Normal 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
|
Loading…
Reference in New Issue
Block a user