| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Effectful.PostgreSQL
Synopsis
- data WithConnection (a :: Type -> Type) b
- withConnection :: forall a (es :: [Effect]). (HasCallStack, WithConnection :> es) => (Connection -> Eff es a) -> Eff es a
- data PostgreSQL (a :: Type -> Type) b
- runWithConnection :: forall (es :: [(Type -> Type) -> Type -> Type]) a. HasCallStack => Connection -> Eff (WithConnection ': es) a -> Eff es a
- runWithConnectionPool :: forall (es :: [Effect]) a. (HasCallStack, IOE :> es) => Pool Connection -> Eff (WithConnection ': es) a -> Eff es a
- runPostgreSQL :: forall (es :: [Effect]) a. (HasCallStack, WithConnection :> es, IOE :> es) => Eff (PostgreSQL ': es) a -> Eff es a
- runPostgreSQLOT :: forall (es :: [Effect]) a. (HasCallStack, WithConnection :> es, IOE :> es) => Eff (PostgreSQL ': es) a -> Eff es a
- query :: forall q r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q, FromRow r) => Query -> q -> Eff es [r]
- query_ :: forall r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow r) => Query -> Eff es [r]
- queryWith :: forall q r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q) => RowParser r -> Query -> q -> Eff es [r]
- queryWith_ :: forall r (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => RowParser r -> Query -> Eff es [r]
- execute :: forall q (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q) => Query -> q -> Eff es Int64
- execute_ :: forall (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Query -> Eff es Int64
- executeMany :: forall q (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q) => Query -> [q] -> Eff es Int64
- withTransaction :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es a -> Eff es a
- withTransactionLevel :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => IsolationLevel -> Eff es a -> Eff es a
- data IsolationLevel
- withTransactionMode :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => TransactionMode -> Eff es a -> Eff es a
- data TransactionMode = TransactionMode {}
- data ReadWriteMode
- withTransactionModeRetry :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => TransactionMode -> (SqlError -> Bool) -> Eff es a -> Eff es a
- withTransactionModeRetry' :: forall e a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, Exception e) => TransactionMode -> (e -> Bool) -> Eff es a -> Eff es a
- withTransactionSerializable :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es a -> Eff es a
- withTransactionSerialisable :: forall (es :: [Effect]) a. (HasCallStack, PostgreSQL :> es) => Eff es a -> Eff es a
- withSavepoint :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es a -> Eff es a
- begin :: forall (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es ()
- commit :: forall (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es ()
- rollback :: forall (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es ()
- fold :: forall row params a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow row, ToRow params) => Query -> params -> a -> (a -> row -> Eff es a) -> Eff es a
- foldWithOptions :: forall row params a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow row, ToRow params) => FoldOptions -> Query -> params -> a -> (a -> row -> Eff es a) -> Eff es a
- fold_ :: forall row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow row) => Query -> a -> (a -> row -> Eff es a) -> Eff es a
- foldWithOptions_ :: forall row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow row) => FoldOptions -> Query -> a -> (a -> row -> Eff es a) -> Eff es a
- forEach :: forall r q (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow r, ToRow q) => Query -> q -> (r -> Eff es ()) -> Eff es ()
- forEach_ :: forall r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow r) => Query -> (r -> Eff es ()) -> Eff es ()
- returning :: forall q r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q, FromRow r) => Query -> [q] -> Eff es [r]
- foldWith :: forall params row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow params) => RowParser row -> Query -> params -> a -> (a -> row -> Eff es a) -> Eff es a
- foldWithOptionsAndParser :: forall params row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow params) => FoldOptions -> RowParser row -> Query -> params -> a -> (a -> row -> Eff es a) -> Eff es a
- foldWith_ :: forall row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => RowParser row -> Query -> a -> (a -> row -> Eff es a) -> Eff es a
- foldWithOptionsAndParser_ :: forall row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => FoldOptions -> RowParser row -> Query -> a -> (a -> row -> Eff es a) -> Eff es a
- forEachWith :: forall q r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q) => RowParser r -> Query -> q -> (r -> Eff es ()) -> Eff es ()
- forEachWith_ :: forall r (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => RowParser r -> Query -> (r -> Eff es ()) -> Eff es ()
- returningWith :: forall q r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q) => RowParser r -> Query -> [q] -> Eff es [r]
- isSerializationError :: SqlError -> Bool
- isNoActiveTransactionError :: SqlError -> Bool
- isFailedTransactionError :: SqlError -> Bool
Effects
data WithConnection (a :: Type -> Type) b Source #
A dynamic effect that lets us use a database Connection,
without specifying how that connection is supplied.
For example, we might want to just provide a connection and let the interpreter
use that for the whole procedure (see runWithConnection).
Or, we might want to create a connection pool which provides connections when the interpreter asks for them (see Effectful.PostgreSQL.Connection.Pool).
Instances
| type DispatchOf WithConnection Source # | |
Defined in Effectful.PostgreSQL.Connection | |
withConnection :: forall a (es :: [Effect]). (HasCallStack, WithConnection :> es) => (Connection -> Eff es a) -> Eff es a Source #
Use a Connection provided by an interpreter.
data PostgreSQL (a :: Type -> Type) b Source #
Dynamic effect representing all the Postgres operations we want to perform.
Instances
| type DispatchOf PostgreSQL Source # | |
Defined in Effectful.PostgreSQL.Effect | |
Interpreters
runWithConnection :: forall (es :: [(Type -> Type) -> Type -> Type]) a. HasCallStack => Connection -> Eff (WithConnection ': es) a -> Eff es a Source #
Run a WithConnection effect by simply supplying a Connection.
The connection will be kept alive for the whole duration of the procedure,
which might not be want you want for long-running processes. If so, see
Effectful.PostgreSQL.Connection.Pool.
runWithConnectionPool :: forall (es :: [Effect]) a. (HasCallStack, IOE :> es) => Pool Connection -> Eff (WithConnection ': es) a -> Eff es a Source #
Rather than keeping one connection alive and re-using it for the whole
process, we might want to create a Pool of connections and only "ask" for
one when we need it. This function uses UnliftIO.Pool to do just that.
runPostgreSQL :: forall (es :: [Effect]) a. (HasCallStack, WithConnection :> es, IOE :> es) => Eff (PostgreSQL ': es) a -> Eff es a Source #
Obvious interepreter for PostgreSQL. Just gets a Connection from WithConnection and calls the
corresponding function from Database.PostgreSQL.Simple.
runPostgreSQLOT :: forall (es :: [Effect]) a. (HasCallStack, WithConnection :> es, IOE :> es) => Eff (PostgreSQL ': es) a -> Eff es a Source #
An interpreter for the PostgreSQL effect that runs database operations using OpenTelemetry instrumentation.
Basically the same as runPostgreSQL except it uses the functions from
OpenTelemetry.Instrumentation.PostgresqlSimple.
Note that the enable-opentel cabal flag must be set to enable this functionality.
Lifted versions of functions from Database.PostgreSQL.Simple
Queries that return results
query :: forall q r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q, FromRow r) => Query -> q -> Eff es [r] Source #
Lifted query.
query_ :: forall r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow r) => Query -> Eff es [r] Source #
Lifted query_.
queryWith :: forall q r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q) => RowParser r -> Query -> q -> Eff es [r] Source #
Lifted queryWith.
queryWith_ :: forall r (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => RowParser r -> Query -> Eff es [r] Source #
Lifted queryWith_.
Statements that do not return results
execute :: forall q (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q) => Query -> q -> Eff es Int64 Source #
Lifted execute.
execute_ :: forall (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Query -> Eff es Int64 Source #
Lifted execute_.
executeMany :: forall q (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q) => Query -> [q] -> Eff es Int64 Source #
Lifted executeMany.
Transaction handling
withTransaction :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es a -> Eff es a Source #
Lifted withTransaction.
withTransactionLevel :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => IsolationLevel -> Eff es a -> Eff es a Source #
Lifted withTransactionLevel.
data IsolationLevel #
Of the four isolation levels defined by the SQL standard,
these are the three levels distinguished by PostgreSQL as of version 9.0.
See https://www.postgresql.org/docs/9.5/static/transaction-iso.html
for more information. Note that prior to PostgreSQL 9.0, RepeatableRead
was equivalent to Serializable.
Constructors
| DefaultIsolationLevel | the isolation level will be taken from
PostgreSQL's per-connection
|
| ReadCommitted | |
| RepeatableRead | |
| Serializable |
Instances
withTransactionMode :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => TransactionMode -> Eff es a -> Eff es a Source #
Lifted withTransactionMode.
data TransactionMode #
Constructors
| TransactionMode | |
Fields | |
Instances
| Show TransactionMode | |
Defined in Database.PostgreSQL.Simple.Transaction Methods showsPrec :: Int -> TransactionMode -> ShowS # show :: TransactionMode -> String # showList :: [TransactionMode] -> ShowS # | |
| Eq TransactionMode | |
Defined in Database.PostgreSQL.Simple.Transaction Methods (==) :: TransactionMode -> TransactionMode -> Bool # (/=) :: TransactionMode -> TransactionMode -> Bool # | |
data ReadWriteMode #
Constructors
| DefaultReadWriteMode | the read-write mode will be taken from
PostgreSQL's per-connection
|
| ReadWrite | |
| ReadOnly |
Instances
withTransactionModeRetry :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => TransactionMode -> (SqlError -> Bool) -> Eff es a -> Eff es a Source #
Lifted withTransactionModeRetry.
withTransactionModeRetry' :: forall e a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, Exception e) => TransactionMode -> (e -> Bool) -> Eff es a -> Eff es a Source #
Lifted withTransactionModeRetry'.
withTransactionSerializable :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es a -> Eff es a Source #
Lifted withTransactionSerializable.
withTransactionSerialisable :: forall (es :: [Effect]) a. (HasCallStack, PostgreSQL :> es) => Eff es a -> Eff es a Source #
British alias of withTransactionSerializable.
withSavepoint :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es a -> Eff es a Source #
Lifted withSavepoint.
begin :: forall (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es () Source #
Lifted begin.
commit :: forall (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es () Source #
Lifted commit.
rollback :: forall (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => Eff es () Source #
Lifted rollback.
Queries that stream results
fold :: forall row params a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow row, ToRow params) => Query -> params -> a -> (a -> row -> Eff es a) -> Eff es a Source #
Lifted fold.
foldWithOptions :: forall row params a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow row, ToRow params) => FoldOptions -> Query -> params -> a -> (a -> row -> Eff es a) -> Eff es a Source #
Lifted foldWithOptions.
fold_ :: forall row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow row) => Query -> a -> (a -> row -> Eff es a) -> Eff es a Source #
Lifted fold_.
foldWithOptions_ :: forall row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow row) => FoldOptions -> Query -> a -> (a -> row -> Eff es a) -> Eff es a Source #
Lifted foldWithOptions_.
forEach :: forall r q (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow r, ToRow q) => Query -> q -> (r -> Eff es ()) -> Eff es () Source #
Lifted forEach.
forEach_ :: forall r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, FromRow r) => Query -> (r -> Eff es ()) -> Eff es () Source #
Lifted forEach_.
returning :: forall q r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q, FromRow r) => Query -> [q] -> Eff es [r] Source #
Lifted returning.
foldWith :: forall params row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow params) => RowParser row -> Query -> params -> a -> (a -> row -> Eff es a) -> Eff es a Source #
Lifted foldWith.
foldWithOptionsAndParser :: forall params row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow params) => FoldOptions -> RowParser row -> Query -> params -> a -> (a -> row -> Eff es a) -> Eff es a Source #
Lifted foldWithOptionsAndParser.
foldWith_ :: forall row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => RowParser row -> Query -> a -> (a -> row -> Eff es a) -> Eff es a Source #
Lifted foldWith_.
foldWithOptionsAndParser_ :: forall row a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => FoldOptions -> RowParser row -> Query -> a -> (a -> row -> Eff es a) -> Eff es a Source #
Lifted foldWithOptionsAndParser_.
forEachWith :: forall q r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q) => RowParser r -> Query -> q -> (r -> Eff es ()) -> Eff es () Source #
Lifted forEachWith.
forEachWith_ :: forall r (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => RowParser r -> Query -> (r -> Eff es ()) -> Eff es () Source #
Lifted forEachWith_.
returningWith :: forall q r (es :: [Effect]). (HasCallStack, PostgreSQL :> es, ToRow q) => RowParser r -> Query -> [q] -> Eff es [r] Source #
Lifted returningWith.
Error predicates
isSerializationError :: SqlError -> Bool #