Use hasql-transaction
Also use hspec before-wrapper
This commit is contained in:
@@ -18,7 +18,6 @@ module PostgREST.QueryBuilder (
|
||||
, callProc
|
||||
, createReadStatement
|
||||
, createWriteStatement
|
||||
, inTransaction
|
||||
, operators
|
||||
, pgFmtIdent
|
||||
, pgFmtLit
|
||||
@@ -27,11 +26,9 @@ module PostgREST.QueryBuilder (
|
||||
, sourceCTEName
|
||||
, unquoted
|
||||
, ResultsWithCount
|
||||
, Isolation(..)
|
||||
) where
|
||||
|
||||
import qualified Hasql.Query as H
|
||||
import qualified Hasql.Session as H
|
||||
import qualified Hasql.Encoders as HE
|
||||
import qualified Hasql.Decoders as HD
|
||||
|
||||
@@ -504,20 +501,3 @@ pgFmtAsJsonPath (Just xx) = " AS " <> last xx
|
||||
|
||||
trimNullChars :: Text -> Text
|
||||
trimNullChars = T.takeWhile (/= '\x0')
|
||||
|
||||
data Isolation = ReadCommitted | RepeatableRead | Serializable
|
||||
|
||||
{- |
|
||||
Wrap a session in a transaction of desired isolation level
|
||||
-}
|
||||
inTransaction :: Isolation -> H.Session a -> H.Session a
|
||||
inTransaction lvl f = do
|
||||
H.sql $ "begin " <> isolate <> ";"
|
||||
r <- f
|
||||
H.sql "commit;"
|
||||
return r
|
||||
where
|
||||
isolate = case lvl of
|
||||
ReadCommitted -> "ISOLATION LEVEL READ COMMITTED"
|
||||
RepeatableRead -> "ISOLATION LEVEL REPEATABLE READ"
|
||||
Serializable -> "ISOLATION LEVEL SERIALIZABLE"
|
||||
|
||||
Reference in New Issue
Block a user