multipool-persistent-postgresql-0.2.0.0: Read and write appropriately from both master and replicated postgresql instances.

Safe HaskellNone
LanguageHaskell2010

Data.MultiPool.Persist.Postgresql

Synopsis

Documentation

initMultiPool' Source #

Arguments

:: (MonadLogger m, MonadUnliftIO m) 
=> (MultiPool SqlBackend -> IO (Maybe (InstanceName SqlReadBackend))) 
-> ConnectionString

Primary connection string

-> Int

Max number of connections to primary instance

-> [(InstanceName SqlReadBackend, ConnectionString, Int)]

Replica connection details

-> m (MultiPool SqlBackend) 

runReadCurrent :: MonadUnliftIO m => MultiPool SqlBackend -> HashMap (InstanceName SqlReadBackend) LSN -> LSN -> ReaderT SqlReadBackend m a -> m a Source #

Performs a read on the first replica found that sufficiently up-to-date with the given LSN. This function can be combined with gatherLSNs and some sort of caching mechanism to provide a simple way to scale out reads. An great article on this concept can be found here

If no replica is up-to-date with the given LSN, the primary instance will be used to run the query.