packages feed

yam-app 0.1.6 → 0.1.7

raw patch · 2 files changed

+13/−5 lines, 2 files

Files

src/Yam/Transaction.hs view
@@ -14,6 +14,7 @@   , DataSourceConnector   , DataSourceProvider   , HasDataSource(..)+  , DataSourceException(..)   , runTrans   , selectValue   , selectNow@@ -74,7 +75,14 @@ class HasDataSource ds where   connector :: MonadTransaction m => Proxy ds -> DataSourceConnector m a -initDataSource :: MonadTransaction m => [DataSourceProvider m a] -> DataSource -> Maybe DataSource -> m a -> m a+data DataSourceException = DataSourcePoolNotFound Text+                         | DataSourceNotSupported Text+                         | DataSourceConfigNotFound Text+                         deriving Show++instance Exception DataSourceException++initDataSource :: (MonadTransaction m) => [DataSourceProvider m a] -> DataSource -> Maybe DataSource -> m a -> m a initDataSource maps ds ds2nd action = let map = M.fromList maps in go map ds ds2nd action   where go map ds ds2 action = do           logger <- toMonadLogger@@ -83,7 +91,7 @@               Nothing -> setConnectionPool p Nothing >> action               Just s2 -> getConnector map logger s2 $ \v -> setConnectionPool p (Just v) >> action         getConnector map logger ds = case M.lookup (dbtype ds) map of-            Nothing -> error $ "Datasource " <> cs (dbtype ds) <> " not supported"+            Nothing -> \_ -> throwM $ DataSourceNotSupported $ cs $ dbtype ds             Just db -> db logger ds  runTrans :: MonadTransaction m => Transaction a -> m a@@ -95,7 +103,7 @@ runSecondaryTrans trans = do   pool <- secondaryPool   case pool of-    Nothing -> error "Secondary Pool not exists"+    Nothing -> throwM $ DataSourcePoolNotFound "Secondary Pool"     Just p  -> withLoggerName "Backup" $ executePool trans p  class FromPersistValue a where@@ -118,7 +126,7 @@         dbNow "sqlite"     = selectValue "SELECT CURRENT_TIMESTAMP"         dbNow "postgresql" = selectValue "SELECT CURRENT_TIMESTAMP"         dbNow "oracle"     = selectValue "SELECT SYSDATE FROM DUAL"-        dbNow dbms         = error $ "Datasource " <> cs dbms <> " not supported"+        dbNow dbms         = throwM $ DataSourceNotSupported $ cs $ dbms  selectValue :: (PersistField a) => Text -> Transaction [a] selectValue sql = fmap unSingle <$> rawSql sql []
yam-app.cabal view
@@ -1,5 +1,5 @@ name:                yam-app-version:             0.1.6+version:             0.1.7 synopsis:            Yam App description:         Base Module for Yam homepage:            https://github.com/leptonyu/yam/tree/master/yam-app#readme