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

Orville.PostgreSQL.Monad.HasOrvilleState

Description

Since: 1.0.0.0

Synopsis

Documentation

class HasOrvilleState m where Source #

HasOrvilleState is the typeclass that Orville uses to access and manange the connection pool and state tracking when it is being executed inside an unknown Monad. It is a specialized version of the Reader interface so that it can be easily implemented by application Monads that already have a Reader context and want to simply add OrvilleState as an attribute to that context, like so

   data MyApplicationState =
     MyApplicationState
       { appConfig :: MyAppConfig
       , appOrvilleState :: OrvilleState
       }

   newtype MyApplicationMonad a =
     MyApplicationMonad (ReaderT MyApplicationState IO) a

   instance HasOrvilleState MyApplicationMonad where
     askOrvilleState =
       MyApplicationMonad (asks appOrvilleState)

     localOrvilleState f (MyApplicationMonad reader) =
       MyApplicationMonad $
         local
           (\state -> state { appOrvilleState = f (appOrvilleState state))
           reader
 

An instance for 'ReaderT OrvilleState m' is provided as a convenience in the case that your application has no extra context to track.

Since: 1.0.0.0

Methods

askOrvilleState :: m OrvilleState Source #

Fetches the current OrvilleState from the host Monad context. The equivalent of ask for 'ReaderT OrvilleState'.

Since: 1.0.0.0

localOrvilleState Source #

Arguments

:: (OrvilleState -> OrvilleState)

The function to modify the OrvilleState.

-> m a

The monad operation to execute with the modified state.

-> m a 

Applies a modification to the OrvilleState that is local to the given monad operation. Calls to askOrvilleState made within the 'm a' provided must return the modified state. The modified state must only apply to the given 'm a' and not be persisted beyond it. The equivalent of local for 'ReaderT OrvilleState'.

Since: 1.0.0.0