effectful-postgresql
Safe HaskellNone
LanguageHaskell2010

Effectful.PostgreSQL

Synopsis

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

Instances details
type DispatchOf WithConnection Source # 
Instance details

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

Instances details
type DispatchOf PostgreSQL Source # 
Instance details

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 #

withTransactionLevel :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => IsolationLevel -> Eff es a -> Eff es a Source #

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 default_transaction_isolation variable, which is initialized according to the server's config. The default configuration is ReadCommitted.

ReadCommitted 
RepeatableRead 
Serializable 

Instances

Instances details
Bounded IsolationLevel 
Instance details

Defined in Database.PostgreSQL.Simple.Transaction

Enum IsolationLevel 
Instance details

Defined in Database.PostgreSQL.Simple.Transaction

Show IsolationLevel 
Instance details

Defined in Database.PostgreSQL.Simple.Transaction

Eq IsolationLevel 
Instance details

Defined in Database.PostgreSQL.Simple.Transaction

Ord IsolationLevel 
Instance details

Defined in Database.PostgreSQL.Simple.Transaction

withTransactionMode :: forall a (es :: [Effect]). (HasCallStack, PostgreSQL :> es) => TransactionMode -> Eff es a -> Eff es a Source #

data ReadWriteMode #

Constructors

DefaultReadWriteMode

the read-write mode will be taken from PostgreSQL's per-connection default_transaction_read_only variable, which is initialized according to the server's config. The default configuration is ReadWrite.

ReadWrite 
ReadOnly 

Instances

Instances details
Bounded ReadWriteMode 
Instance details

Defined in Database.PostgreSQL.Simple.Transaction

Enum ReadWriteMode 
Instance details

Defined in Database.PostgreSQL.Simple.Transaction

Show ReadWriteMode 
Instance details

Defined in Database.PostgreSQL.Simple.Transaction

Eq ReadWriteMode 
Instance details

Defined in Database.PostgreSQL.Simple.Transaction

Ord ReadWriteMode 
Instance details

Defined in Database.PostgreSQL.Simple.Transaction

withTransactionModeRetry' :: forall e a (es :: [Effect]). (HasCallStack, PostgreSQL :> es, Exception e) => TransactionMode -> (e -> Bool) -> Eff es a -> Eff es a Source #

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 #

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 #

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 #

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 #

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 #

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 #

Error predicates