Module
Control.Monad.Postgres.Base
- Package
- purescript-postgresql
- Repository
- cakekindel/purescript-postgresql
#PostgresT Source
type PostgresT :: (Type -> Type) -> Type -> Type
type PostgresT = RE Pool
Monad handling pool resource acquisition & release
runPostgres
{connectionString: "postgresql://postgres:postgres@localhost:5432"}
$ session do
exec_ "create table foo (bar int);"
exec_ "insert into foo values (1);"
res <- query "select * from foo"
pure $ res == 1
Is equivalent to:
do
pool <- liftEffect $ Pool.make {connectionString: "postgresql://postgres:postgres@localhost:5432"}
finally (Pool.end pool) do
client <- Pool.connect pool
finally (liftEffect $ Pool.release pool client) do
Client.exec_ "create table foo (bar int);" client
Client.exec_ "insert into foo values (1);" client
res <- Client.query "select * from foo" client
pure $ res == 1
Instances
(MonadAff m, MonadSession (SessionT m), MonadCursor (CursorT t (SessionT m)) t) => MonadPostgres (PostgresT m) (SessionT m) (CursorT ct (SessionT m)) ct
#MonadPostgres Source
class MonadPostgres :: (Type -> Type) -> (Type -> Type) -> (Type -> Type) -> Type -> Constraint
class (Monad m, MonadSession session, MonadCursor cursor ct) <= MonadPostgres m session cursor ct | m -> ct cursor session where
Typeclass generalizing PostgresT
. Allows for dependency-injecting different
implementations of the idea of a postgres connection.
session
- Session monad (forPostgresT
this isSessionT
)cursor
- Cursor session monad (forPostgresT
this isCursorT
)ct
- Open type parameter for cursor type. Don't pin this to a concrete type.
Members
session :: session ~> m
transaction :: session ~> m
Run a session in
m
, wrapped in a transaction.If any errors are raised, the transaction is rolled back and the error rethrown.
cursorWith :: forall q. AsQuery q => (Array Raw -> RepT ct) -> String -> q -> cursor ~> m
cursor
, but using a custom deserialize function for the data yielded by the cursor
Instances
(MonadAff m, MonadSession (SessionT m), MonadCursor (CursorT t (SessionT m)) t) => MonadPostgres (PostgresT m) (SessionT m) (CursorT ct (SessionT m)) ct
#cursor Source
cursor :: forall @cursort t session cursor q a. MonadPostgres t session cursor cursort => AsQuery q => FromRow cursort => String -> q -> cursor a -> t a
Create a server-side cursor for a query in a transaction,
and execute a CursorT
with a view to the new cursor.
#runPostgres Source
runPostgres :: forall m a missing trash r f. MonadBracket Error f m => MonadAff m => Union r missing (Config trash) => Record r -> PostgresT m a -> Except m a
Create a new connection pool from the provided config and execute
the postgres monad, invoking Effect.Aff.Postgres.Pool.end
afterwards.
- Modules
- Control.
Monad. Postgres - Control.
Monad. Postgres. Base - Control.
Monad. Postgres. Cursor - Control.
Monad. Postgres. Session - Data.
Postgres - Data.
Postgres. Custom - Data.
Postgres. Custom. Enum - Data.
Postgres. Interval - Data.
Postgres. Query - Data.
Postgres. Query. Builder - Data.
Postgres. Range - Data.
Postgres. Raw - Data.
Postgres. Result - Data.
Postgres. Unresult - Effect.
Aff. Postgres. Client - Effect.
Aff. Postgres. Pool - Effect.
Postgres. Client - Effect.
Postgres. Error - Effect.
Postgres. Error. Common - Effect.
Postgres. Error. Except - Effect.
Postgres. Error. RE - Effect.
Postgres. Pool - Node.
FS. PinnedVersion - Pipes.
Postgres
Run a session in
m
.