Set role locally in a tx to ensure it is reset after error

This commit is contained in:
Joe Nelson
2015-08-26 20:49:23 -07:00
parent 480800edbd
commit 594327924c
3 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -53,14 +53,14 @@ checkPass :: Text -> Text -> Bool
checkPass = (. cs) . validatePassword . cs
setRole :: Text -> H.Tx P.Postgres s ()
setRole role = H.unitEx $ B.Stmt ("set role " <> cs (pgFmtLit role)) V.empty True
setRole role = H.unitEx $ B.Stmt ("set local role " <> cs (pgFmtLit role)) V.empty True
resetRole :: H.Tx P.Postgres s ()
resetRole = H.unitEx [H.stmt|reset role|]
setUserId :: Text -> H.Tx P.Postgres s ()
setUserId uid = if uid /= "" then
H.unitEx $ B.Stmt ("set user_vars.user_id = " <> cs (pgFmtLit uid)) V.empty True
H.unitEx $ B.Stmt ("set local user_vars.user_id = " <> cs (pgFmtLit uid)) V.empty True
else
resetUserId
+1 -1
View File
@@ -73,7 +73,7 @@ main = do
runSettings appSettings $ middle $ \req respond -> do
body <- strictRequestBody req
resOrError <- liftIO $ H.session pool $ H.tx Nothing $
resOrError <- liftIO $ H.session pool $ H.tx (Just (H.ReadUncommitted, Just True)) $
authenticated conf (app conf body) req
either (respond . errResponse) respond resOrError
+1 -1
View File
@@ -54,7 +54,7 @@ withApp perform = do
perform $ middle $ \req resp -> do
body <- strictRequestBody req
result <- liftIO $ H.session pool $ H.tx Nothing
result <- liftIO $ H.session pool $ H.tx (Just (H.ReadUncommitted, Just True))
$ authenticated cfg (app cfg body) req
either (resp . errResponse) resp result