refactor: inline txVarQuery and preReqQuery
This way it's easier to see which queries are being executed. Also use whenJust instead of traverse_.
This commit is contained in:
committed by
Steve Chavez
parent
19ac284f25
commit
966a611d7f
+10
-23
@@ -17,8 +17,7 @@ module PostgREST.Query
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Lens ((^?))
|
import Control.Lens ((^?))
|
||||||
import qualified Data.Aeson as JSON
|
import Control.Monad.Extra (whenJust)
|
||||||
import qualified Data.Aeson.KeyMap as KM
|
|
||||||
import qualified Data.Aeson.Lens as L
|
import qualified Data.Aeson.Lens as L
|
||||||
import qualified Data.ByteString as BS hiding
|
import qualified Data.ByteString as BS hiding
|
||||||
(break)
|
(break)
|
||||||
@@ -107,17 +106,19 @@ data ResultSet
|
|||||||
|
|
||||||
query :: AppConfig -> AuthResult -> ApiRequest -> ActionPlan -> SchemaCache -> Query
|
query :: AppConfig -> AuthResult -> ApiRequest -> ActionPlan -> SchemaCache -> Query
|
||||||
query _ _ _ (NoDb x) _ = NoDbQuery $ NoDbResult x
|
query _ _ _ (NoDb x) _ = NoDbQuery $ NoDbResult x
|
||||||
query config AuthResult{..} apiReq (Db plan) sCache =
|
query conf@AppConfig{..} AuthResult{..} apiReq (Db plan) sCache =
|
||||||
DbQuery isoLvl txMode dbHandler transaction mainSQLQuery
|
DbQuery isoLvl txMode dbHandler transaction mainSQLQuery
|
||||||
where
|
where
|
||||||
transaction = if prepared then SQL.transaction else SQL.unpreparedTransaction
|
transaction = if configDbPreparedStatements then SQL.transaction else SQL.unpreparedTransaction
|
||||||
prepared = configDbPreparedStatements config
|
isoLvl = planIsoLvl conf authRole plan
|
||||||
isoLvl = planIsoLvl config authRole plan
|
|
||||||
txMode = planTxMode plan
|
txMode = planTxMode plan
|
||||||
(mainActionQuery, mainSQLQuery) = actionQuery plan config apiReq sCache
|
(mainActionQuery, mainSQLQuery) = actionQuery plan conf apiReq sCache
|
||||||
dbHandler = do
|
dbHandler = do
|
||||||
runTxVarQuery plan config authClaims authRole apiReq
|
lift $ SQL.statement mempty $ SQL.dynamicallyParameterized
|
||||||
runPreReqQuery config
|
(PreQuery.txVarQuery plan conf authClaims authRole apiReq)
|
||||||
|
HD.noResult configDbPreparedStatements
|
||||||
|
lift $ whenJust configDbPreRequest $ \prereq -> do
|
||||||
|
SQL.statement mempty $ SQL.dynamicallyParameterized (PreQuery.preReqQuery prereq) HD.noResult configDbPreparedStatements
|
||||||
mainActionQuery
|
mainActionQuery
|
||||||
|
|
||||||
planTxMode :: DbActionPlan -> SQL.Mode
|
planTxMode :: DbActionPlan -> SQL.Mode
|
||||||
@@ -303,20 +304,6 @@ optionalRollback AppConfig{..} ApiRequest{iPreferences=Preferences{..}} = do
|
|||||||
shouldRollback =
|
shouldRollback =
|
||||||
preferTransaction == Just Rollback
|
preferTransaction == Just Rollback
|
||||||
|
|
||||||
runTxVarQuery :: DbActionPlan -> AppConfig -> KM.KeyMap JSON.Value -> BS.ByteString -> ApiRequest -> DbHandler ()
|
|
||||||
runTxVarQuery dbActPlan conf@AppConfig{..} claims role apireq = lift $
|
|
||||||
SQL.statement mempty $ SQL.dynamicallyParameterized
|
|
||||||
(PreQuery.txVarQuery dbActPlan conf claims role apireq)
|
|
||||||
HD.noResult configDbPreparedStatements
|
|
||||||
|
|
||||||
runPreReqQuery :: AppConfig -> DbHandler ()
|
|
||||||
runPreReqQuery conf = lift $ traverse_ (SQL.statement mempty . stmt) (configDbPreRequest conf)
|
|
||||||
where
|
|
||||||
stmt req = SQL.dynamicallyParameterized
|
|
||||||
(PreQuery.preReqQuery req)
|
|
||||||
HD.noResult
|
|
||||||
(configDbPreparedStatements conf)
|
|
||||||
|
|
||||||
getSQLQuery :: Query -> ByteString
|
getSQLQuery :: Query -> ByteString
|
||||||
getSQLQuery DbQuery{dqSQL} = dqSQL
|
getSQLQuery DbQuery{dqSQL} = dqSQL
|
||||||
getSQLQuery _ = mempty
|
getSQLQuery _ = mempty
|
||||||
|
|||||||
Reference in New Issue
Block a user