@@ -43,19 +43,21 @@ import qualified PostgREST.Query as Query
4343import qualified PostgREST.Response as Response
4444import qualified PostgREST.Unix as Unix (installSignalHandlers )
4545
46- import PostgREST.ApiRequest (Action (.. ), ApiRequest (.. ),
47- Mutation (.. ), Target (.. ))
48- import PostgREST.AppState (AppState )
49- import PostgREST.Auth (AuthResult (.. ))
50- import PostgREST.Config (AppConfig (.. ))
51- import PostgREST.Config.PgVersion (PgVersion (.. ))
52- import PostgREST.Error (Error )
53- import PostgREST.Query (DbHandler )
54- import PostgREST.Response.Performance (ServerTiming (.. ),
55- serverTimingHeader )
56- import PostgREST.SchemaCache (SchemaCache (.. ))
57- import PostgREST.SchemaCache.Routine (Routine (.. ))
58- import PostgREST.Version (docsVersion , prettyVersion )
46+ import PostgREST.ApiRequest (Action (.. ),
47+ ApiRequest (.. ),
48+ Mutation (.. ), Target (.. ))
49+ import PostgREST.AppState (AppState )
50+ import PostgREST.Auth (AuthResult (.. ))
51+ import PostgREST.Config (AppConfig (.. ))
52+ import PostgREST.Config.PgVersion (PgVersion (.. ))
53+ import PostgREST.Error (Error )
54+ import PostgREST.Query (DbHandler )
55+ import PostgREST.Response.Performance (ServerTiming (.. ),
56+ serverTimingHeader )
57+ import PostgREST.SchemaCache (SchemaCache (.. ))
58+ import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (.. ))
59+ import PostgREST.SchemaCache.Routine (Routine (.. ))
60+ import PostgREST.Version (docsVersion , prettyVersion )
5961
6062import qualified Data.ByteString.Char8 as BS
6163import qualified Data.List as L
@@ -170,43 +172,44 @@ handleRequest AuthResult{..} conf appState authenticated prepared pgVer apiReq@A
170172 case (iAction, iTarget) of
171173 (ActionRead headersOnly, TargetIdent identifier) -> do
172174 (planTime', wrPlan) <- withTiming $ liftEither $ Plan. wrappedReadPlan identifier conf sCache apiReq
173- (txTime', resultSet) <- withTiming $ runQuery roleIsoLvl Nothing (Plan. wrTxMode wrPlan) $ Query. readQuery wrPlan conf apiReq
175+ (txTime', resultSet) <- withTiming $ runQuery roleIsoLvl (Plan. wrTxMode wrPlan) mempty $ Query. readQuery wrPlan conf apiReq
174176 (respTime', pgrst) <- withTiming $ liftEither $ Response. readResponse wrPlan headersOnly identifier apiReq resultSet
175177 return $ pgrstResponse (ServerTiming jwtTime parseTime planTime' txTime' respTime') pgrst
176178
177179 (ActionMutate MutationCreate , TargetIdent identifier) -> do
178180 (planTime', mrPlan) <- withTiming $ liftEither $ Plan. mutateReadPlan MutationCreate apiReq identifier conf sCache
179- (txTime', resultSet) <- withTiming $ runQuery roleIsoLvl Nothing (Plan. mrTxMode mrPlan) $ Query. createQuery mrPlan apiReq conf
181+ (txTime', resultSet) <- withTiming $ runQuery roleIsoLvl (Plan. mrTxMode mrPlan) mempty $ Query. createQuery mrPlan apiReq conf
180182 (respTime', pgrst) <- withTiming $ liftEither $ Response. createResponse identifier mrPlan apiReq resultSet
181183 return $ pgrstResponse (ServerTiming jwtTime parseTime planTime' txTime' respTime') pgrst
182184
183185 (ActionMutate MutationUpdate , TargetIdent identifier) -> do
184186 (planTime', mrPlan) <- withTiming $ liftEither $ Plan. mutateReadPlan MutationUpdate apiReq identifier conf sCache
185- (txTime', resultSet) <- withTiming $ runQuery roleIsoLvl Nothing (Plan. mrTxMode mrPlan) $ Query. updateQuery mrPlan apiReq conf
187+ (txTime', resultSet) <- withTiming $ runQuery roleIsoLvl (Plan. mrTxMode mrPlan) mempty $ Query. updateQuery mrPlan apiReq conf
186188 (respTime', pgrst) <- withTiming $ liftEither $ Response. updateResponse mrPlan apiReq resultSet
187189 return $ pgrstResponse (ServerTiming jwtTime parseTime planTime' txTime' respTime') pgrst
188190
189191 (ActionMutate MutationSingleUpsert , TargetIdent identifier) -> do
190192 (planTime', mrPlan) <- withTiming $ liftEither $ Plan. mutateReadPlan MutationSingleUpsert apiReq identifier conf sCache
191- (txTime', resultSet) <- withTiming $ runQuery roleIsoLvl Nothing (Plan. mrTxMode mrPlan) $ Query. singleUpsertQuery mrPlan apiReq conf
193+ (txTime', resultSet) <- withTiming $ runQuery roleIsoLvl (Plan. mrTxMode mrPlan) mempty $ Query. singleUpsertQuery mrPlan apiReq conf
192194 (respTime', pgrst) <- withTiming $ liftEither $ Response. singleUpsertResponse mrPlan apiReq resultSet
193195 return $ pgrstResponse (ServerTiming jwtTime parseTime planTime' txTime' respTime') pgrst
194196
195197 (ActionMutate MutationDelete , TargetIdent identifier) -> do
196198 (planTime', mrPlan) <- withTiming $ liftEither $ Plan. mutateReadPlan MutationDelete apiReq identifier conf sCache
197- (txTime', resultSet) <- withTiming $ runQuery roleIsoLvl Nothing (Plan. mrTxMode mrPlan) $ Query. deleteQuery mrPlan apiReq conf
199+ (txTime', resultSet) <- withTiming $ runQuery roleIsoLvl (Plan. mrTxMode mrPlan) mempty $ Query. deleteQuery mrPlan apiReq conf
198200 (respTime', pgrst) <- withTiming $ liftEither $ Response. deleteResponse mrPlan apiReq resultSet
199201 return $ pgrstResponse (ServerTiming jwtTime parseTime planTime' txTime' respTime') pgrst
200202
201- (ActionInvoke invMethod, TargetProc identifier _) -> do
203+ (ActionInvoke invMethod, TargetProc identifier@ (QualifiedIdentifier _ proname) _) -> do
204+ let setting = [(y,z) | (x,y,z) <- funcSettings, x == encodeUtf8 proname]
202205 (planTime', cPlan) <- withTiming $ liftEither $ Plan. callReadPlan identifier conf sCache apiReq invMethod
203- (txTime', resultSet) <- withTiming $ runQuery (fromMaybe roleIsoLvl $ pdIsoLvl (Plan. crProc cPlan)) (pdTimeout $ Plan. crProc cPlan) ( Plan. crTxMode cPlan) $ Query. invokeQuery (Plan. crProc cPlan) cPlan apiReq conf pgVer
206+ (txTime', resultSet) <- withTiming $ runQuery (fromMaybe roleIsoLvl $ pdIsoLvl (Plan. crProc cPlan)) (Plan. crTxMode cPlan) setting $ Query. invokeQuery (Plan. crProc cPlan) cPlan apiReq conf pgVer
204207 (respTime', pgrst) <- withTiming $ liftEither $ Response. invokeResponse cPlan invMethod (Plan. crProc cPlan) apiReq resultSet
205208 return $ pgrstResponse (ServerTiming jwtTime parseTime planTime' txTime' respTime') pgrst
206209
207210 (ActionInspect headersOnly, TargetDefaultSpec tSchema) -> do
208211 (planTime', iPlan) <- withTiming $ liftEither $ Plan. inspectPlan apiReq
209- (txTime', oaiResult) <- withTiming $ runQuery roleIsoLvl Nothing (Plan. ipTxmode iPlan) $ Query. openApiQuery sCache pgVer conf tSchema
212+ (txTime', oaiResult) <- withTiming $ runQuery roleIsoLvl (Plan. ipTxmode iPlan) mempty $ Query. openApiQuery sCache pgVer conf tSchema
210213 (respTime', pgrst) <- withTiming $ liftEither $ Response. openApiResponse (T. decodeUtf8 prettyVersion, docsVersion) headersOnly oaiResult conf sCache iSchema iNegotiatedByProfile
211214 return $ pgrstResponse (ServerTiming jwtTime parseTime planTime' txTime' respTime') pgrst
212215
@@ -230,9 +233,10 @@ handleRequest AuthResult{..} conf appState authenticated prepared pgVer apiReq@A
230233 where
231234 roleSettings = fromMaybe mempty (HM. lookup authRole $ configRoleSettings conf)
232235 roleIsoLvl = HM. findWithDefault SQL. ReadCommitted authRole $ configRoleIsoLvl conf
233- runQuery isoLvl timeout mode query =
236+ funcSettings = dbFuncSettings sCache
237+ runQuery isoLvl mode funcSet query =
234238 runDbHandler appState conf isoLvl mode authenticated prepared $ do
235- Query. setPgLocals conf authClaims authRole (HM. toList roleSettings) apiReq timeout
239+ Query. setPgLocals conf authClaims authRole (HM. toList roleSettings) funcSet apiReq
236240 Query. runPreReq conf
237241 query
238242
0 commit comments