generated from tpl/purs
Add tests
This commit is contained in:
parent
a1276bc057
commit
64c84351ec
@ -19,5 +19,9 @@
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/rightfold/purescript-postgresql-client.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"purescript-assert": "^3.0.0",
|
||||
"purescript-eff": "^3.1.0"
|
||||
}
|
||||
}
|
||||
|
50
test/Main.purs
Normal file
50
test/Main.purs
Normal file
@ -0,0 +1,50 @@
|
||||
module Test.Main
|
||||
( main
|
||||
) where
|
||||
|
||||
import Control.Monad.Aff (launchAff)
|
||||
import Control.Monad.Eff (Eff)
|
||||
import Control.Monad.Eff.Class (liftEff)
|
||||
import Control.Monad.Eff.Exception (EXCEPTION)
|
||||
import Data.Tuple.Nested ((/\))
|
||||
import Database.PostgreSQL (POSTGRESQL, PoolConfiguration, Query(..), execute, newPool, query, withConnection)
|
||||
import Prelude
|
||||
import Test.Assert (ASSERT, assert)
|
||||
|
||||
main :: ∀ eff. Eff (assert :: ASSERT, exception :: EXCEPTION, postgreSQL :: POSTGRESQL | eff) Unit
|
||||
main = void $ launchAff do
|
||||
pool <- newPool config
|
||||
withConnection pool \conn -> do
|
||||
execute conn (Query """
|
||||
CREATE TEMPORARY TABLE foods (
|
||||
name text NOT NULL,
|
||||
delicious boolean NOT NULL,
|
||||
PRIMARY KEY (name)
|
||||
)
|
||||
""") unit
|
||||
|
||||
execute conn (Query """
|
||||
INSERT INTO foods (name, delicious)
|
||||
VALUES ($1, $2), ($3, $4), ($5, $6)
|
||||
""") ("pork" /\ true /\ "sauerkraut" /\ false /\ "rookworst" /\ true /\ unit)
|
||||
|
||||
query conn (Query """
|
||||
SELECT name
|
||||
FROM foods
|
||||
WHERE delicious
|
||||
ORDER BY name ASC
|
||||
""") unit
|
||||
>>= liftEff <<< assert <<< (==) ["pork" /\ unit, "rookworst" /\ unit]
|
||||
|
||||
pure unit
|
||||
|
||||
config :: PoolConfiguration
|
||||
config =
|
||||
{ user: "postgres"
|
||||
, password: "lol123"
|
||||
, host: "127.0.0.1"
|
||||
, port: 5432
|
||||
, database: "purspg"
|
||||
, max: 10
|
||||
, idleTimeoutMillis: 1000
|
||||
}
|
Loading…
Reference in New Issue
Block a user