packages feed

multipool-postgresql-simple 0.1.0.2 → 0.2.0.0

raw patch · 2 files changed

+18/−10 lines, 2 files

Files

multipool-postgresql-simple.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: e42319132652ad23030c5f6a93f113a4b36f2ca1a07bd8bdd2e3dab102c9b922+-- hash: 39b87d51ca23fd8005d4fb7bc4a7899f7b8c90c501434f88e101144678f35196  name:           multipool-postgresql-simple-version:        0.1.0.2+version:        0.2.0.0 description:    Please see the README on GitHub at <https://github.com/iand675/multipool-postgresql-simple#readme> homepage:       https://github.com/iand675/multipool#readme bug-reports:    https://github.com/iand675/multipool/issues
src/Data/MultiPool/PostgreSQLSimple.hs view
@@ -38,15 +38,15 @@ initMultiPool' ::      (MonadUnliftIO m)   => (MultiPool Connection -> IO (Maybe (InstanceName Connection))) -- Strategy for selectin the replica instance when calling 'runReadAny'. 'roundRobin' is the current default.-  -> ByteString -- ^ Master connection string+  -> ByteString -- ^ Primary connection string   -> Int -- ^ Max number of connections to master instance   -> [(InstanceName Connection, ByteString, Int)] -- ^ Replica connection details   -> m (MultiPool Connection) initMultiPool' multiPoolAnyReplicaSelector str n is = do-  multiPoolMaster <- liftIO $ createPool (connectPostgreSQL str) close n 15 1+  multiPoolPrimary <- liftIO $ createPool (connectPostgreSQL str) close n 15 1   replicas <- liftIO $ mapM (\(inst, connStr, numConns) -> (,) <$> pure inst <*> createPool (connectPostgreSQL connStr) close numConns 15 1) is   let multiPoolReplica = HM.fromList replicas-      multiPoolAnyMasterSelector = const $ pure ()+      multiPoolAnyPrimarySelector = const $ pure ()   return $ MultiPool {..}  withResource' :: MonadUnliftIO m => Pool a -> (a -> m b) -> m b@@ -56,20 +56,28 @@       io $ action a  instance MonadUnliftIO m => MultiPoolBackend m Connection where-  type MasterConnection Connection = Connection+  type PrimaryConnection Connection = Connection   type ReplicaConnection Connection = Connection   type ReplicaIdentifier Connection = InstanceName Connection    runWriteAny b m = runWrite b () m-  runWrite b () m = withResource' (multiPoolMaster b) $ runReaderT m+  runWrite b () m = withResource' (multiPoolPrimary b) $ runReaderT m -  runReadMaster b () m = runReadAnyMaster b m-  runReadAnyMaster b m = withResource' (multiPoolMaster b) $ runReaderT m+  runReadPrimary b () m = runReadAnyPrimary b m+  runReadAnyPrimary b m = withResource' (multiPoolPrimary b) $ runReaderT m   runReadAny b m = do     mident <- liftIO $ multiPoolAnyReplicaSelector b b     case mident of-      Nothing -> runReadAnyMaster b m+      Nothing -> runReadAnyPrimary b m       Just ident -> runRead b ident m   runRead b ident m = case HM.lookup ident (multiPoolReplica b) of     Nothing -> throw (InstanceDoesNotExist ident)     Just repl -> withResource' repl $ runReaderT m++  takePrimary b () = liftIO $ takeResource $ multiPoolPrimary b+  putPrimary _ l c = liftIO $ putResource l c++  takeReplica b ident = case HM.lookup ident (multiPoolReplica b) of+    Nothing -> throw (InstanceDoesNotExist ident)+    Just repl -> liftIO $ takeResource repl+  putReplica _ l c = liftIO $ putResource l c