refactor: move isolation/settings logic to Plan.hs

This commit is contained in:
steve-chavez
2024-03-28 18:31:42 -05:00
committed by Steve Chavez
parent c33ca4e60c
commit 06ff56d323
3 changed files with 24 additions and 27 deletions
+12 -4
View File
@@ -22,7 +22,8 @@ module PostgREST.Plan
, InspectPlan(..)
, inspectPlan
, callReadPlan
, actionPlanTxMode
, planTxMode
, planIsoLvl
) where
import qualified Data.ByteString.Lazy as LBS
@@ -127,9 +128,16 @@ data InspectPlan = InspectPlan {
data ActionPlan = Db DbActionPlan | MaybeDb InspectPlan
actionPlanTxMode :: ActionPlan -> SQL.Mode
actionPlanTxMode (Db x) = pTxMode x
actionPlanTxMode (MaybeDb x) = ipTxmode x
planTxMode :: ActionPlan -> SQL.Mode
planTxMode (Db x) = pTxMode x
planTxMode (MaybeDb x) = ipTxmode x
planIsoLvl :: AppConfig -> ByteString -> ActionPlan -> SQL.IsolationLevel
planIsoLvl AppConfig{configRoleIsoLvl} role actPlan = case actPlan of
Db CallReadPlan{crProc} -> fromMaybe roleIsoLvl $ pdIsoLvl crProc
_ -> roleIsoLvl
where
roleIsoLvl = HM.findWithDefault SQL.ReadCommitted role configRoleIsoLvl
actionPlan :: DbAction -> AppConfig -> ApiRequest -> SchemaCache -> Either Error ActionPlan
actionPlan dbAct conf apiReq sCache = case dbAct of