module Hasql.Transaction.Private.SQL where import Hasql.Transaction.Private.Prelude import Hasql.Transaction.Private.Model import qualified ByteString.TreeBuilder as D beginTransaction :: IsolationLevel -> Mode -> ByteString beginTransaction :: IsolationLevel -> Mode -> ByteString beginTransaction IsolationLevel isolation Mode mode = Builder -> ByteString D.toByteString Builder builder where builder :: Builder builder = Builder "BEGIN " Builder -> Builder -> Builder forall a. Semigroup a => a -> a -> a <> Builder isolationBuilder Builder -> Builder -> Builder forall a. Semigroup a => a -> a -> a <> Builder " " Builder -> Builder -> Builder forall a. Semigroup a => a -> a -> a <> Builder modeBuilder where isolationBuilder :: Builder isolationBuilder = case IsolationLevel isolation of IsolationLevel ReadCommitted -> Builder "ISOLATION LEVEL READ COMMITTED" IsolationLevel RepeatableRead -> Builder "ISOLATION LEVEL REPEATABLE READ" IsolationLevel Serializable -> Builder "ISOLATION LEVEL SERIALIZABLE" modeBuilder :: Builder modeBuilder = case Mode mode of Mode Write -> Builder "READ WRITE" Mode Read -> Builder "READ ONLY" declareCursor :: ByteString -> ByteString -> ByteString declareCursor :: ByteString -> ByteString -> ByteString declareCursor ByteString name ByteString sql = Builder -> ByteString D.toByteString (Builder -> ByteString) -> Builder -> ByteString forall a b. (a -> b) -> a -> b $ Builder "DECLARE " Builder -> Builder -> Builder forall a. Semigroup a => a -> a -> a <> ByteString -> Builder D.byteString ByteString name Builder -> Builder -> Builder forall a. Semigroup a => a -> a -> a <> Builder " NO SCROLL CURSOR FOR " Builder -> Builder -> Builder forall a. Semigroup a => a -> a -> a <> ByteString -> Builder D.byteString ByteString sql