| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.PostgreSQL.PQTypes.Class
Synopsis
- class (Applicative m, Monad m) => MonadDB (m :: Type -> Type) where
- runQuery :: (HasCallStack, IsSQL sql) => sql -> m Int
- runPreparedQuery :: (HasCallStack, IsSQL sql) => QueryName -> sql -> m Int
- getLastQuery :: m (BackendPid, SomeSQL)
- withFrozenLastQuery :: m a -> m a
- getConnectionStats :: m ConnectionStats
- getQueryResult :: FromRow row => m (Maybe (QueryResult row))
- clearQueryResult :: m ()
- getConnectionAcquisitionMode :: m ConnectionAcquisitionMode
- acquireAndHoldConnection :: IsolationLevel -> Permissions -> m ()
- unsafeAcquireOnDemandConnection :: m ()
- getNotification :: Int -> m (Maybe Notification)
- withNewConnection :: HasCallStack => m a -> m a
- newtype BackendPid = BackendPid Int
- newtype QueryName = QueryName Text
Class
class (Applicative m, Monad m) => MonadDB (m :: Type -> Type) where Source #
Methods
runQuery :: (HasCallStack, IsSQL sql) => sql -> m Int Source #
Run SQL query and return number of affected/returned rows. Note that
for a given connection, only one thread may be executing runQuery at
a given time. If simultaneous call is made from another thread, it
will block until currently running runQuery finishes.
runPreparedQuery :: (HasCallStack, IsSQL sql) => QueryName -> sql -> m Int Source #
Similar to runQuery, but it prepares and executes a statement under a
given name.
getLastQuery :: m (BackendPid, SomeSQL) Source #
Get last SQL query that was executed and ID of the server process attached to the session that executed it.
withFrozenLastQuery :: m a -> m a Source #
Subsequent queries in the callback do not alter the result of
getLastQuery.
getConnectionStats :: m ConnectionStats Source #
Get current connection statistics.
getQueryResult :: FromRow row => m (Maybe (QueryResult row)) Source #
Get current query result.
clearQueryResult :: m () Source #
Clear current query result.
getConnectionAcquisitionMode :: m ConnectionAcquisitionMode Source #
Get current connection acquisition mode.
acquireAndHoldConnection :: IsolationLevel -> Permissions -> m () Source #
Acquire and hold a connection with a given isolation level and permissions.
If the connection is already held, a check is performed if the isolation level and permissions are the same as the ones currently in place. If so, nothing happens, otherwise an error is thrown.
unsafeAcquireOnDemandConnection :: m () Source #
Unsafely switch to the AcquireOnDemand mode.
This function is unsafe because if a connection is already held, the transaction in progress is commited, so atomicity guarantee is lost.
getNotification :: Int -> m (Maybe Notification) Source #
Attempt to receive a notification from the server. This function waits until a notification arrives or specified number of microseconds has passed. If a negative number of microseconds is passed as an argument, it will wait indefinitely. In addition, there are a couple of things to be aware of:
- A lock on the underlying database connection is acquired for the duration of the function.
- Notifications can be received only between transactions
(see http://www.postgresql.org/docs/current/static/sql-notify.html
for further info), therefore calling this function within
a transaction block will return
Justonly if notifications were received before the transaction began.
withNewConnection :: HasCallStack => m a -> m a Source #
Execute supplied monadic action with new connection using current connection source and transaction settings.
Particularly useful when you want to spawn a new thread, but do not want the connection in child thread to be shared with the parent one.
Instances
Misc
newtype BackendPid Source #
Process ID of the server process attached to the current session.
Constructors
| BackendPid Int |
Instances
| Show BackendPid Source # | |
Defined in Database.PostgreSQL.PQTypes.Internal.BackendPid Methods showsPrec :: Int -> BackendPid -> ShowS # show :: BackendPid -> String # showList :: [BackendPid] -> ShowS # | |
| Eq BackendPid Source # | |
| Ord BackendPid Source # | |
Defined in Database.PostgreSQL.PQTypes.Internal.BackendPid Methods compare :: BackendPid -> BackendPid -> Ordering # (<) :: BackendPid -> BackendPid -> Bool # (<=) :: BackendPid -> BackendPid -> Bool # (>) :: BackendPid -> BackendPid -> Bool # (>=) :: BackendPid -> BackendPid -> Bool # max :: BackendPid -> BackendPid -> BackendPid # min :: BackendPid -> BackendPid -> BackendPid # | |
Name of a prepared query.
Instances
| IsString QueryName Source # | |
Defined in Database.PostgreSQL.PQTypes.Internal.Connection Methods fromString :: String -> QueryName # | |
| Show QueryName Source # | |
| Eq QueryName Source # | |
| Ord QueryName Source # | |