{-# LANGUAGE OverloadedStrings #-}

module Hasql.Private.Statements where

-- bytestring-tree-builder
import ByteString.TreeBuilder (toByteString)

-- hasql
import Hasql.Statement
import Hasql.Encoders
import Hasql.Decoders

-- hasql-transaction-io
import Hasql.Private.Types

startTransaction :: IsolationLevel -> Mode -> Deferrable -> Bool -> Statement () ()
startTransaction :: IsolationLevel -> Mode -> Deferrable -> Bool -> Statement () ()
startTransaction IsolationLevel
isolation Mode
mode Deferrable
deferrable = 
  ByteString -> Params () -> Result () -> Bool -> Statement () ()
forall params result.
ByteString
-> Params params
-> Result result
-> Bool
-> Statement params result
Statement ByteString
stmt Params ()
noParams Result ()
noResult
  where
    stmt :: ByteString
stmt = Builder -> ByteString
toByteString (Builder -> ByteString) -> Builder -> ByteString
forall a b. (a -> b) -> a -> b
$
      Builder
"START TRANSACTION ISOLATION LEVEL " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
      IsolationLevel -> Builder
isolationLevelToSQL IsolationLevel
isolation Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
      Mode -> Builder
modeToSQL Mode
mode Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
      Deferrable -> Builder
deferrableToSQL Deferrable
deferrable

commitTransaction :: Bool -> Statement () ()
commitTransaction :: Bool -> Statement () ()
commitTransaction = ByteString -> Params () -> Result () -> Bool -> Statement () ()
forall params result.
ByteString
-> Params params
-> Result result
-> Bool
-> Statement params result
Statement ByteString
"COMMIT" Params ()
noParams Result ()
noResult

rollbackTransaction :: Bool -> Statement () ()
rollbackTransaction :: Bool -> Statement () ()
rollbackTransaction = ByteString -> Params () -> Result () -> Bool -> Statement () ()
forall params result.
ByteString
-> Params params
-> Result result
-> Bool
-> Statement params result
Statement ByteString
"ROLLBACK" Params ()
noParams Result ()
noResult