Module

Nonbili.Postgres.Pool

Package
purescript-nonbili-postgres
Repository
nonbili/purescript-nonbili-postgres

Bindings to pg.Pool.

#Pool Source

data Pool

pg.Pool object.

#Client Source

data Client

Pooled client boject.

#newPool Source

newPool :: Config -> Effect Pool

Create a new pool with configuration.

#connect Source

connect :: Pool -> Aff Client

Acquire a client from the pool. Remember to release the client after, otherwise pool clients will be exhausted quickly. It's recommend to use withTransaction, which handles releasing client for you.

#end Source

end :: Pool -> Aff Unit

Disconnect all active clients. Useful at the end of a script to exit the process.

#release Source

release :: Client -> Aff Unit

Release a client. When using withTransaction, no need to release manually.

#withTransaction Source

withTransaction :: forall a. Pool -> (Client -> Aff a) -> Aff a

Acquire a client from the pool, then run queries as a transaction.

#execute Source

execute :: forall p. ToQueryParams p => Client -> String -> p -> Aff Unit

Same as query, but ignore all return values.

#Result Source

type Result a = Either String { rowCount :: Int, rows :: Array a }

#query Source

query :: forall a p. ToQueryParams p => DecodeJson a => Client -> String -> p -> Aff (Result a)

pg will construct SQL from provided query string and params. Check ToQueryParams for supported params.