effectful-postgresql
Safe HaskellNone
LanguageHaskell2010

Effectful.PostgreSQL.Effect

Synopsis

Effect

data PostgreSQL (a :: Type -> Type) b where Source #

Dynamic effect representing all the Postgres operations we want to perform.

Constructors

Query :: forall q r (a :: Type -> Type). (ToRow q, FromRow r) => Query -> q -> PostgreSQL a [r]

Lifted query.

QueryWith :: forall q r (a :: Type -> Type). ToRow q => RowParser r -> Query -> q -> PostgreSQL a [r]

Lifted queryWith.

Query_ :: forall r (a :: Type -> Type). FromRow r => Query -> PostgreSQL a [r]

Lifted query_.

QueryWith_ :: forall r (a :: Type -> Type). RowParser r -> Query -> PostgreSQL a [r]

Lifted queryWith_.

Execute :: forall q (a :: Type -> Type). ToRow q => Query -> q -> PostgreSQL a Int64

Lifted execute.

Execute_ :: forall (a :: Type -> Type). Query -> PostgreSQL a Int64

Lifted execute_.

ExecuteMany :: forall q (a :: Type -> Type). ToRow q => Query -> [q] -> PostgreSQL a Int64

Lifted executeMany.

WithTransaction :: forall (a :: Type -> Type) b. a b -> PostgreSQL a b

Lifted withTransaction.

WithTransactionLevel :: forall (a :: Type -> Type) b. IsolationLevel -> a b -> PostgreSQL a b

Lifted withTransactionLevel.

WithTransactionMode :: forall (a :: Type -> Type) b. TransactionMode -> a b -> PostgreSQL a b

Lifted withTransactionMode.

WithTransactionModeRetry :: forall (a :: Type -> Type) b. TransactionMode -> (SqlError -> Bool) -> a b -> PostgreSQL a b

Lifted withTransactionModeRetry.

WithTransactionModeRetry' :: forall e (a :: Type -> Type) b. Exception e => TransactionMode -> (e -> Bool) -> a b -> PostgreSQL a b

Lifted withTransactionModeRetry'.

WithTransactionSerializable :: forall (a :: Type -> Type) b. a b -> PostgreSQL a b

Lifted withTransactionSerializable.

WithSavepoint :: forall (a :: Type -> Type) b. a b -> PostgreSQL a b

Lifted withSavepoint.

Begin :: forall (a :: Type -> Type). PostgreSQL a ()

Lifted begin.

Commit :: forall (a :: Type -> Type). PostgreSQL a ()

Lifted commit.

Rollback :: forall (a :: Type -> Type). PostgreSQL a ()

Lifted rollback.

Fold :: forall row params b (a :: Type -> Type). (FromRow row, ToRow params) => Query -> params -> b -> (b -> row -> a b) -> PostgreSQL a b

Lifted fold.

Fold_ :: forall row b (a :: Type -> Type). FromRow row => Query -> b -> (b -> row -> a b) -> PostgreSQL a b

Lifted fold_.

FoldWithOptions :: forall row params b (a :: Type -> Type). (FromRow row, ToRow params) => FoldOptions -> Query -> params -> b -> (b -> row -> a b) -> PostgreSQL a b

Lifted foldWithOptions.

FoldWithOptions_ :: forall row b (a :: Type -> Type). FromRow row => FoldOptions -> Query -> b -> (b -> row -> a b) -> PostgreSQL a b

Lifted foldWithOptions_.

ForEach :: forall r q (a :: Type -> Type). (FromRow r, ToRow q) => Query -> q -> (r -> a ()) -> PostgreSQL a ()

Lifted forEach.

ForEach_ :: forall r (a :: Type -> Type). FromRow r => Query -> (r -> a ()) -> PostgreSQL a ()

Lifted forEach_.

Returning :: forall q r (a :: Type -> Type). (ToRow q, FromRow r) => Query -> [q] -> PostgreSQL a [r]

Lifted returning.

FoldWith :: forall params row b (a :: Type -> Type). ToRow params => RowParser row -> Query -> params -> b -> (b -> row -> a b) -> PostgreSQL a b

Lifted foldWith.

FoldWithOptionsAndParser :: forall params row b (a :: Type -> Type). ToRow params => FoldOptions -> RowParser row -> Query -> params -> b -> (b -> row -> a b) -> PostgreSQL a b

Lifted foldWithOptionsAndParser.

FoldWith_ :: forall row b (a :: Type -> Type). RowParser row -> Query -> b -> (b -> row -> a b) -> PostgreSQL a b

Lifted foldWith_.

FoldWithOptionsAndParser_ :: forall row b (a :: Type -> Type). FoldOptions -> RowParser row -> Query -> b -> (b -> row -> a b) -> PostgreSQL a b

Lifted foldWithOptionsAndParser_.

ForEachWith :: forall q r (a :: Type -> Type). ToRow q => RowParser r -> Query -> q -> (r -> a ()) -> PostgreSQL a ()

Lifted forEachWith.

ForEachWith_ :: forall r (a :: Type -> Type). RowParser r -> Query -> (r -> a ()) -> PostgreSQL a ()

Lifted forEachWith_.

ReturningWith :: forall q r (a :: Type -> Type). ToRow q => RowParser r -> Query -> [q] -> PostgreSQL a [r]

Lifted returningWith.

Instances

Instances details
type DispatchOf PostgreSQL Source # 
Instance details

Defined in Effectful.PostgreSQL.Effect

Interpreters

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 #