generated from tpl/purs
Minor refactoring
This commit is contained in:
parent
631fef38f8
commit
91504c4e86
@ -53,7 +53,7 @@ Our tests runner reads the configuration for the current process environment or
|
|||||||
the _.env_ file (please check _.env-example_ for details).
|
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 the `newPool` function.
|
||||||
Additionally we pass `idleTimeoutMillis` value because this code
|
Additionally we pass `idleTimeoutMillis` value because this code
|
||||||
is run by our test suite and we want to exit after its execution quickly ;-)
|
is run by our test suite and we want to exit after its execution quickly ;-)
|
||||||
|
|
||||||
|
@ -49,13 +49,23 @@ import Unsafe.Coerce (unsafeCoerce)
|
|||||||
-- | PostgreSQL connection.
|
-- | PostgreSQL connection.
|
||||||
foreign import data Client :: Type
|
foreign import data Client :: Type
|
||||||
|
|
||||||
|
newtype Connection = Connection (Either Pool Client)
|
||||||
|
derive instance newtypeConnection :: Newtype Connection _
|
||||||
|
|
||||||
|
fromPool :: Pool -> Connection
|
||||||
|
fromPool pool = Connection (Left pool)
|
||||||
|
|
||||||
|
fromClient :: Client -> Connection
|
||||||
|
fromClient client = Connection (Right client)
|
||||||
|
|
||||||
|
|
||||||
-- | PostgreSQL query with parameter (`$1`, `$2`, …) and return types.
|
-- | PostgreSQL query with parameter (`$1`, `$2`, …) and return types.
|
||||||
newtype Query i o
|
newtype Query i o
|
||||||
= Query String
|
= Query String
|
||||||
|
|
||||||
derive instance newtypeQuery :: Newtype (Query i o) _
|
derive instance newtypeQuery :: Newtype (Query i o) _
|
||||||
|
|
||||||
-- | Run an action with a connection. The connection is released to the pool
|
-- | Run an action with a client. The client is released to the pool
|
||||||
-- | when the action returns.
|
-- | when the action returns.
|
||||||
withClient ::
|
withClient ::
|
||||||
forall a.
|
forall a.
|
||||||
@ -152,17 +162,8 @@ withClientTransaction client action =
|
|||||||
|
|
||||||
rollback = execute conn (Query "ROLLBACK TRANSACTION") Row0
|
rollback = execute conn (Query "ROLLBACK TRANSACTION") Row0
|
||||||
|
|
||||||
newtype Connection = Connection (Either Pool Client)
|
|
||||||
derive instance newtypeConnection :: Newtype Connection _
|
|
||||||
|
|
||||||
fromPool :: Pool -> Connection
|
|
||||||
fromPool pool = Connection (Left pool)
|
|
||||||
|
|
||||||
fromClient :: Client -> Connection
|
|
||||||
fromClient client = Connection (Right client)
|
|
||||||
|
|
||||||
-- | APIs of the `Pool.query` and `Client.query` are the same.
|
-- | APIs of the `Pool.query` and `Client.query` are the same.
|
||||||
-- | We can dse this polyformphis to simplify ffi.
|
-- | We can use this polyformphis to simplify ffi.
|
||||||
foreign import data UntaggedConnection :: Type
|
foreign import data UntaggedConnection :: Type
|
||||||
|
|
||||||
-- | Execute a PostgreSQL query and discard its results.
|
-- | Execute a PostgreSQL query and discard its results.
|
||||||
|
Loading…
Reference in New Issue
Block a user