arbiter-hasql-0.1.0.0
arbiter-hasql
Safe HaskellNone
LanguageGHC2024

Arbiter.Hasql.HasqlDb

Description

The hasql database monad with a built-in MonadArbiter instance:

import Arbiter.Core
import Arbiter.Hasql

myFunction :: HasqlDb MyRegistry IO ()
myFunction = insertJob (defaultJob myPayload)
Synopsis

Database Monad

Source #newtype HasqlDb (registry :: JobPayloadRegistry) (m :: Type -> Type) a

The hasql database monad.

Constructors

HasqlDb 

Fields

Instances

Instances details
Monad m => MonadReader (HasqlEnv registry) (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#ask :: HasqlDb registry m (HasqlEnv registry)

#local :: (HasqlEnv registry -> HasqlEnv registry) -> HasqlDb registry m a -> HasqlDb registry m a

#reader :: (HasqlEnv registry -> a) -> HasqlDb registry m a

MonadUnliftIO m => MonadArbiter (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Associated Types

type RegistryOf (HasqlDb registry m) 
Instance details

Defined in Arbiter.Hasql.HasqlDb

type RegistryOf (HasqlDb registry m) = registry

Methods

#getSchema :: HasqlDb registry m SchemaName

#executeQuery :: Query a -> HasqlDb registry m [a]

#executeQueryPrepared :: Query a -> HasqlDb registry m [a]

#executeStatement :: Query a -> HasqlDb registry m Int64

#withDbTransaction :: HasqlDb registry m a -> HasqlDb registry m a

#runHandlerWithConnection :: JobHandler (HasqlDb registry m) payload (ResultOf (HasqlDb registry m) payload) -> JobRead payload -> HasqlDb registry m (ResultOf (HasqlDb registry m) payload)

#getListener :: HasqlDb registry m (Maybe Listener)

Monad m => HasHasqlPool (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

MonadCatch m => MonadCatch (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#catch :: (HasCallStack, Exception e) => HasqlDb registry m a -> (e -> HasqlDb registry m a) -> HasqlDb registry m a

#catchNoPropagate :: Exception e => HasqlDb registry m a -> (ExceptionWithContext e -> HasqlDb registry m a) -> HasqlDb registry m a

MonadMask m => MonadMask (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#mask :: HasCallStack => ((forall a. HasqlDb registry m a -> HasqlDb registry m a) -> HasqlDb registry m b) -> HasqlDb registry m b

#uninterruptibleMask :: HasCallStack => ((forall a. HasqlDb registry m a -> HasqlDb registry m a) -> HasqlDb registry m b) -> HasqlDb registry m b

#generalBracket :: HasCallStack => HasqlDb registry m a -> (a -> ExitCase b -> HasqlDb registry m c) -> (a -> HasqlDb registry m b) -> HasqlDb registry m (b, c)

MonadThrow m => MonadThrow (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#throwM :: (HasCallStack, Exception e) => e -> HasqlDb registry m a

#rethrowM :: Exception e => ExceptionWithContext e -> HasqlDb registry m a

Applicative m => Applicative (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#pure :: a -> HasqlDb registry m a

#(<*>) :: HasqlDb registry m (a -> b) -> HasqlDb registry m a -> HasqlDb registry m b

#liftA2 :: (a -> b -> c) -> HasqlDb registry m a -> HasqlDb registry m b -> HasqlDb registry m c

#(*>) :: HasqlDb registry m a -> HasqlDb registry m b -> HasqlDb registry m b

#(<*) :: HasqlDb registry m a -> HasqlDb registry m b -> HasqlDb registry m a

Functor m => Functor (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#fmap :: (a -> b) -> HasqlDb registry m a -> HasqlDb registry m b

#(<$) :: a -> HasqlDb registry m b -> HasqlDb registry m a

Monad m => Monad (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#(>>=) :: HasqlDb registry m a -> (a -> HasqlDb registry m b) -> HasqlDb registry m b

#(>>) :: HasqlDb registry m a -> HasqlDb registry m b -> HasqlDb registry m b

#return :: a -> HasqlDb registry m a

MonadFail m => MonadFail (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#fail :: HasCallStack => String -> HasqlDb registry m a

MonadIO m => MonadIO (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#liftIO :: IO a -> HasqlDb registry m a

MonadUnliftIO m => MonadUnliftIO (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#withRunInIO :: ((forall a. HasqlDb registry m a -> IO a) -> IO b) -> HasqlDb registry m b

type RegistryOf (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

type RegistryOf (HasqlDb registry m) = registry
type Handler (HasqlDb registry m) job result Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

type Handler (HasqlDb registry m) job result = Connection -> job -> HasqlDb registry m result

Source #data HasqlEnv (registry :: JobPayloadRegistry)

Schema name and connection pool for HasqlDb.

Constructors

HasqlEnv 

Fields

Instances

Instances details
Monad m => MonadReader (HasqlEnv registry) (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

Methods

#ask :: HasqlDb registry m (HasqlEnv registry)

#local :: (HasqlEnv registry -> HasqlEnv registry) -> HasqlDb registry m a -> HasqlDb registry m a

#reader :: (HasqlEnv registry -> a) -> HasqlDb registry m a

Source #runHasqlDb :: forall (registry :: JobPayloadRegistry) m a. HasqlEnv registry -> HasqlDb registry m a -> m a

Run a HasqlDb action in its env.

Source #inTransaction :: forall (registry :: JobPayloadRegistry) m a. Connection -> SchemaName -> HasqlDb registry m a -> m a

Arguments

:: forall (registry :: JobPayloadRegistry) m a. Connection 
-> SchemaName

Schema name

-> HasqlDb registry m a 
-> m a 

Run a HasqlDb action on one connection without a pool. The connection is pinned as an open transaction. withDbTransaction nests through savepoints. The caller owns the transaction.

_ <- Hasql.use conn (Session.script BEGIN)
inTransaction conn "arbiter" $ do
  Arb.insertJob (Arb.defaultJob myPayload)
_ <- Hasql.use conn (Session.script COMMIT)

Environment Creation

Source #createHasqlEnv :: forall (registry :: JobPayloadRegistry) m. MonadIO m => Proxy registry -> ByteString -> SchemaName -> m (HasqlEnv registry)

Arguments

:: forall (registry :: JobPayloadRegistry) m. MonadIO m 
=> Proxy registry 
-> ByteString

PostgreSQL connection string

-> SchemaName

Schema name

-> m (HasqlEnv registry) 

Create a HasqlEnv with conservative pool defaults. Size worker pools with createHasqlEnvWithConfig and poolConfigForWorkers.

Source #createHasqlEnvWithConfig :: forall (registry :: JobPayloadRegistry) m. MonadIO m => Proxy registry -> ByteString -> SchemaName -> PoolConfig -> m (HasqlEnv registry)

Arguments

:: forall (registry :: JobPayloadRegistry) m. MonadIO m 
=> Proxy registry 
-> ByteString

PostgreSQL connection string

-> SchemaName

Schema name

-> PoolConfig 
-> m (HasqlEnv registry) 

Create a HasqlEnv with custom pool settings.

Source #createHasqlEnvWithPool :: forall (registry :: JobPayloadRegistry) m. MonadIO m => Proxy registry -> Pool Connection -> SchemaName -> m (HasqlEnv registry)

Arguments

:: forall (registry :: JobPayloadRegistry) m. MonadIO m 
=> Proxy registry 
-> Pool Connection 
-> SchemaName

Schema name

-> m (HasqlEnv registry) 

Create a HasqlEnv over a caller's own connection pool. The shared listener holds one pool connection for the env's lifetime. Size the pool for the worker load plus one. disableListener runs poll-only and frees that slot. useDedicatedListener gives the listener its own connection.

Source #destroyHasqlEnv :: forall m (registry :: JobPayloadRegistry). MonadIO m => HasqlEnv registry -> m ()

Release the env's connection pool, closing its open connections.

Source #disableListener :: forall (registry :: JobPayloadRegistry). HasqlEnv registry -> HasqlEnv registry

Turn off the shared LISTEN listener for an env, running poll-only.

Source #useDedicatedListener :: forall m (registry :: JobPayloadRegistry). MonadIO m => ByteString -> HasqlEnv registry -> m (HasqlEnv registry)

Give the env a dedicated LISTEN connection opened from a connection string. The listener takes no pool slot.

Source #setPreparedStatements :: forall (registry :: JobPayloadRegistry). Bool -> HasqlEnv registry -> HasqlEnv registry

Enable or disable prepared hot statements (the claim). Each pooled connection prepares once and reuses the plan. Requires direct connections or a pooler that supports server-side prepared statements.

Hasql Settings

Exceptions