diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index 1d9b69b4e..ac1be60ea 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -196,8 +196,8 @@ postgrestResponse appState conf@AppConfig{..} maybeSchemaCache jwtTime authResul (txTime, txResult) <- withTiming conf $ do case tx of MainTx.NoDbTx r -> pure r - MainTx.DbTx{..} -> do - dbRes <- lift $ AppState.usePool appState (dqTransaction dqIsoLevel dqTxMode $ runExceptT dqDbHandler) + MainTx.DbTx dbSession -> do + dbRes <- lift $ AppState.usePool appState dbSession let eitherResp = join $ mapLeft (Error.PgErr . Error.PgError (Just authRole /= configDbAnonRole)) dbRes -- TODO: we use obsQuery twice, one here and one below because in case of an error with the usePool above, the request will finish here and return an error message. diff --git a/src/PostgREST/MainTx.hs b/src/PostgREST/MainTx.hs index e5b314671..4a6d753ae 100644 --- a/src/PostgREST/MainTx.hs +++ b/src/PostgREST/MainTx.hs @@ -59,12 +59,7 @@ import Protolude hiding (Handler) type DbHandler = ExceptT Error SQL.Transaction data MainTx - = DbTx { - dqIsoLevel :: SQL.IsolationLevel - , dqTxMode :: SQL.Mode - , dqDbHandler :: DbHandler DbResult - , dqTransaction :: SQL.IsolationLevel -> SQL.Mode -> SQL.Transaction (Either Error DbResult) -> SQL.Session (Either Error DbResult) - } + = DbTx (SQL.Session (Either Error DbResult)) | NoDbTx DbResult data DbResult @@ -96,7 +91,7 @@ data ResultSet mainTx :: MainQuery -> AppConfig -> AuthResult -> ApiRequest -> ActionPlan -> SchemaCache -> MainTx mainTx _ _ _ _ (NoDb x) _ = NoDbTx $ NoDbResult x mainTx genQ@MainQuery{..} conf@AppConfig{..} AuthResult{..} apiReq (Db plan) sCache = - DbTx isoLvl txMode dbHandler SQL.transactionNoRetry + DbTx $ SQL.transactionNoRetry isoLvl txMode $ runExceptT dbHandler where isoLvl = planIsoLvl conf authRole plan txMode = planTxMode plan