generated from tpl/purs
Use config loader in the README example
This commit is contained in:
parent
4c738fe72f
commit
dd0011687c
@ -1,3 +1,10 @@
|
|||||||
PG_DB="purspg"
|
PG_DB="purspg"
|
||||||
PG_PORT=6432
|
PG_PORT=5432
|
||||||
|
# We want this setup so test runner disconnects quickly
|
||||||
PG_IDLE_TIMEOUT_MILLISECONDS=1000
|
PG_IDLE_TIMEOUT_MILLISECONDS=1000
|
||||||
|
|
||||||
|
# You can provide additional options:
|
||||||
|
# PG_HOST ∷ String
|
||||||
|
# PG_MAX ∷ Int
|
||||||
|
# PG_USER ∷ STring
|
||||||
|
# PG_PASSWORD ∷ String
|
||||||
|
12
README.md
12
README.md
@ -20,16 +20,17 @@ import Prelude
|
|||||||
|
|
||||||
import Control.Monad.Except.Trans (ExceptT, runExceptT)
|
import Control.Monad.Except.Trans (ExceptT, runExceptT)
|
||||||
import Data.Either (Either(..))
|
import Data.Either (Either(..))
|
||||||
import Database.PostgreSQL (Client, Connection, defaultConfiguration, Pool, Query(Query), PGError)
|
import Database.PostgreSQL (Connection, Pool, Query(Query), PGError)
|
||||||
import Database.PostgreSQL.PG (command, execute, query, withTransaction) as PG
|
import Database.PostgreSQL.PG (command, execute, query, withTransaction) as PG
|
||||||
import Database.PostgreSQL.Pool (new) as Pool
|
import Database.PostgreSQL.Pool (new) as Pool
|
||||||
import Database.PostgreSQL.Row (Row0(Row0), Row3(Row3))
|
import Database.PostgreSQL.Row (Row0(Row0), Row3(Row3))
|
||||||
import Data.Decimal as Decimal
|
import Data.Decimal as Decimal
|
||||||
import Data.Maybe (Maybe(..))
|
|
||||||
import Data.Tuple.Nested ((/\))
|
import Data.Tuple.Nested ((/\))
|
||||||
import Effect.Aff (Aff)
|
import Effect.Aff (Aff)
|
||||||
|
import Effect.Aff.Class (liftAff)
|
||||||
import Effect.Class (liftEffect)
|
import Effect.Class (liftEffect)
|
||||||
import Test.Assert (assert)
|
import Test.Assert (assert)
|
||||||
|
import Test.Config (load) as Config
|
||||||
```
|
```
|
||||||
|
|
||||||
The whole API for interaction with PostgreSQL is performed asynchronously in `Aff`
|
The whole API for interaction with PostgreSQL is performed asynchronously in `Aff`
|
||||||
@ -49,6 +50,8 @@ withTransaction :: forall a. Pool -> (Connection -> AppM a) -> AppM a
|
|||||||
withTransaction p = PG.withTransaction runExceptT p
|
withTransaction p = PG.withTransaction runExceptT p
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Our tests runner reads the configuration for the current process environment or from
|
||||||
|
the _.env_ file (please check _.env-example_ for details).
|
||||||
We assume here that Postgres is running on a standard local port
|
We assume here that Postgres is running on a standard local port
|
||||||
with `ident` authentication so configuration can be nearly empty (`defaultConfiguration`).
|
with `ident` authentication so configuration can be nearly empty (`defaultConfiguration`).
|
||||||
It requires only database name which we pass to `newPool` function.
|
It requires only database name which we pass to `newPool` function.
|
||||||
@ -59,9 +62,8 @@ is run by our test suite and we want to exit after its execution quickly ;-)
|
|||||||
```purescript
|
```purescript
|
||||||
run ∷ AppM Unit
|
run ∷ AppM Unit
|
||||||
run = do
|
run = do
|
||||||
|
config ← liftAff $ Config.load
|
||||||
pool <- liftEffect $ Pool.new
|
pool ← liftEffect $ Pool.new config
|
||||||
((defaultConfiguration "purspg") { idleTimeoutMillis = Just 1000 })
|
|
||||||
```
|
```
|
||||||
|
|
||||||
We can now create our temporary table which we are going to query in this example.
|
We can now create our temporary table which we are going to query in this example.
|
||||||
|
Loading…
Reference in New Issue
Block a user