orville-postgresql-1.0.0.0: A Haskell library for PostgreSQL
CopyrightFlipstone Technology Partners 2023
LicenseMIT
StabilityStable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Orville.PostgreSQL.OrvilleState

Description

Since: 1.0.0.0

Synopsis

Documentation

data OrvilleState Source #

OrvilleState is used to manage opening connections to the database, transactions, etc. newOrvilleState should be used to create an appopriate initial state for your monad's context.

Since: 1.0.0.0

newOrvilleState :: ErrorDetailLevel -> ConnectionPool -> OrvilleState Source #

Creates an appropriate initial OrvilleState that will use the connection pool given to initiate connections to the database.

Since: 1.0.0.0

resetOrvilleState :: OrvilleState -> OrvilleState Source #

Creates a new initial OrvilleState using the connection pool from the provided state. You might need to use this if you are spawning one Orville monad from another and they should not share the same connection and transaction state.

Since: 1.0.0.0

orvilleConnectionPool :: OrvilleState -> ConnectionPool Source #

Get the connection pool being used for the OrvilleState.

Since: 1.0.0.0

orvilleErrorDetailLevel :: OrvilleState -> ErrorDetailLevel Source #

The ErrorDetailLevel controls how much information Orville includes in error messages it generates when data cannot be decoded from rows in the database.

Since: 1.0.0.0

orvilleTransactionCallback :: OrvilleState -> TransactionEvent -> IO () Source #

Orville will call the transaction callback any time a transaction event occurs. You can register a callback with addTransactionCallback.

Since: 1.0.0.0

orvilleSqlCommenterAttributes :: OrvilleState -> Maybe SqlCommenterAttributes Source #

The SqlCommenter attributes that Orville will include with queries. These can be modified with addSqlCommenterAttributes. See https://google.github.io/sqlcommenter/.

Since: 1.0.0.0

addTransactionCallback :: (TransactionEvent -> IO ()) -> OrvilleState -> OrvilleState Source #

Registers a callback to be invoked during transactions.

The callback given will be called after the SQL statement corresponding to the given event has finished executing. Callbacks will be called in the order they are added.

Note: There is no specialized error handling for these callbacks. This means that if a callback raises an exception, no further callbacks will be called and the exception will propagate up until it is caught elsewhere. In particular, if an exception is raised by a callback upon opening the transaction, it will cause the transaction to be rolled-back the same as any other exception that might happen during the transaction. In general, we recommend only using callbacks that either raise no exceptions or can handle their own exceptions cleanly.

Since: 1.0.0.0

data TransactionEvent Source #

Describes an event in the lifecycle of a database transaction. You can use addTransactionCallback to register a callback to respond to these events. The callback will be called after the event in question has been successfully executed.

Since: 1.0.0.0

Constructors

BeginTransaction

Indicates a new transaction has been started.

NewSavepoint Savepoint

Indicates that a new savepoint has been saved within a transaction.

ReleaseSavepoint Savepoint

Indicates that a previous savepoint has been released. It can no longer be rolled back to.

RollbackToSavepoint Savepoint

Indicates that rollback was performed to a prior savepoint.

Note: It is possible to rollback to a savepoint prior to the most recent one without releasing or rolling back to intermediate savepoints. Doing so destroys any savepoints created after the given savepoint. Although Orville currently always matches NewSavepoint with either ReleaseSavepoint or RollbackToSavepoint, it is recommended that you do not rely on this behavior.

CommitTransaction

Indicates that the transaction has been committed.

RollbackTransaction

Indicates that the transaction has been rolled back.

data Savepoint Source #

An internal Orville identifier for a savepoint in a PostgreSQL transaction.

Since: 1.0.0.0

Instances

Instances details
Show Savepoint Source # 
Instance details

Defined in Orville.PostgreSQL.Internal.OrvilleState

Eq Savepoint Source # 
Instance details

Defined in Orville.PostgreSQL.Internal.OrvilleState

savepointNestingLevel :: Savepoint -> Int Source #

Indicates how many levels of nested savepoints the given Savepoint identifier represents.

Since: 1.0.0.0

initialSavepoint :: Savepoint Source #

The initial identifier Orville uses to track the first savepoint within a transaction.

Since: 1.0.0.0

nextSavepoint :: Savepoint -> Savepoint Source #

Determines the identifier for the next savepoint in a transaction after the given savepoint.

Since: 1.0.0.0

orvilleSqlExecutionCallback :: OrvilleState -> forall a. QueryType -> RawSql -> IO a -> IO a Source #

The callback Orville will call whenever it wants to run SQL. You can register a callback using addSqlExecutionCallback.

Since: 1.0.0.0

addSqlExecutionCallback :: (forall a. QueryType -> RawSql -> IO a -> IO a) -> OrvilleState -> OrvilleState Source #

Adds a callback to be called when an Orville operation executes a SQL statement. The callback is given the IO action that will perform the query execution and must call that action for the query to be run. In particular, you can use this to time queries and log any that are slow.

Calls to any previously added callbacks will also be executed as part of the IO action passed to the new callback. Thus the newly added callback happens "around" the previously added callback.

There is no special exception handling done for these callbacks beyond what they implement themselves. Any callbacks should allow for the possibility that the IO action they are given may raise an exception.

Since: 1.0.0.0

orvilleBeginTransactionExpr :: OrvilleState -> BeginTransactionExpr Source #

The SQL expression that Orville will use to begin a transaction. You can set this via setBeginTransactionExpr to have fine-grained control over the transaction parameters, such as isolation level.

Since: 1.0.0.0

setBeginTransactionExpr :: BeginTransactionExpr -> OrvilleState -> OrvilleState Source #

Sets the SQL expression that Orville will use to begin transactions. You can control the transaction isolation level by building your own BeginTransactionExpr with the desired isolation level.

Since: 1.0.0.0

setSqlCommenterAttributes :: SqlCommenterAttributes -> OrvilleState -> OrvilleState Source #

Sets the SqlCommenterAttributes that Orville will then add to any following statement executions.

Since: 1.0.0.0

addSqlCommenterAttributes :: SqlCommenterAttributes -> OrvilleState -> OrvilleState Source #

Adds the SqlCommenterAttributes to the already existing attributes that Orville will then add to any following statement executions.

Since: 1.0.0.0