diff --git a/bower.json b/bower.json index f2ebe90..f33a611 100644 --- a/bower.json +++ b/bower.json @@ -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" } } diff --git a/test/Main.purs b/test/Main.purs new file mode 100644 index 0000000..1e67548 --- /dev/null +++ b/test/Main.purs @@ -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 + }