module Pqi.Conformance.Operation.CmdTuples
( spec,
)
where
import qualified Pqi
import Pqi.Conformance.Harness
import Pqi.Conformance.Prelude
import Test.Hspec
spec :: Pqi.Adapter -> SpecWith ByteString
spec :: Adapter -> SpecWith ByteString
spec Adapter
adapter =
String -> SpecWith ByteString -> SpecWith ByteString
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"cmdTuples" do
String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"reports the affected-row count for each command" \ByteString
conninfo ->
Adapter
-> ByteString
-> (Connection
-> IO
(Maybe (Maybe ByteString), Maybe (Maybe ByteString),
Maybe (Maybe ByteString), Maybe (Maybe ByteString),
Maybe (Maybe ByteString)))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
_ <- Connection -> ByteString -> IO (Maybe Result)
Pqi.exec Connection
connection ByteString
"create temporary table conformance_cmd_tuples (id int4, label text)"
let countOf ByteString
sql = Connection -> ByteString -> IO (Maybe Result)
Pqi.exec Connection
connection ByteString
sql IO (Maybe Result)
-> (Maybe Result -> IO (Maybe (Maybe ByteString)))
-> IO (Maybe (Maybe ByteString))
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Result -> IO (Maybe ByteString))
-> Maybe Result -> IO (Maybe (Maybe ByteString))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse Result -> IO (Maybe ByteString)
Pqi.cmdTuples
insert <- countOf "insert into conformance_cmd_tuples values (1, 'a'), (2, 'b')"
update <- countOf "update conformance_cmd_tuples set label = 'c' where id = 1"
delete <- countOf "delete from conformance_cmd_tuples where id = 2"
select <- countOf "select * from conformance_cmd_tuples"
ddl <- countOf "create temporary table conformance_cmd_tuples_2 (id int4)"
pure (insert, update, delete, select, ddl)