Disable transactions for read-only requests

This commit is contained in:
Joe Nelson
2014-11-06 14:19:19 -08:00
parent 0e57bee90d
commit f58e3db924
5 changed files with 33 additions and 18 deletions
+2 -2
View File
@@ -18,7 +18,7 @@ import Text.Regex.TDFA ((=~))
import qualified Data.ByteString.Char8 as BS
import Network.Wai.Middleware.Cors (cors)
import Middleware(clientErrors, withSavepoint, authenticated)
import Middleware(clientErrors, withSavepoint, authenticated, Environment(..))
import Dbapi (app, corsPolicy, AppConfig(..))
import PgQuery(addUser)
@@ -65,7 +65,7 @@ appWithFixture :: ActionWith Application -> IO ()
appWithFixture action = withDatabaseConnection $ \c -> do
runRaw c "begin;"
action $ cors corsPolicy . clientErrors $
(authenticated "dbapi_anonymous" . withSavepoint) app c
(authenticated "dbapi_anonymous" . withSavepoint Test) app c
rollback c
rangeHdrs :: ByteRange -> [Header]
+2 -2
View File
@@ -4,7 +4,7 @@ import Test.Hspec
import Database.HDBC (runRaw, quickQuery, fromSql, SqlError)
import SpecHelper (dbWithSchema)
import Middleware (withSavepoint)
import Middleware (withSavepoint, Environment(..))
import PgQuery (insert)
import Types(SqlRow(..))
import Control.Exception(catch)
@@ -24,7 +24,7 @@ spec = let
describe "withSavepoint" $
it "allows partial rollback of request" $ \c -> do
let app = withSavepoint dbErrApp c
let app = withSavepoint Test dbErrApp c
[[beforeCount]] <- quickQuery c "select count(*) from \"1\".items" []
runRaw c "set role dbapi_anonymous"
_ <- insert "1" "items" (SqlRow []) c