From a718ab29256822baac3584f425908b97324375fc Mon Sep 17 00:00:00 2001 From: Kei Hibino Date: Sun, 18 Dec 2016 14:35:43 +0900 Subject: [PATCH] add generalized table initializer. --- rr-quickcheck/rr-quickcheck.cabal | 2 ++ .../Test/Relational/QuickCheck/Transaction.hs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 rr-quickcheck/src/Test/Relational/QuickCheck/Transaction.hs diff --git a/rr-quickcheck/rr-quickcheck.cabal b/rr-quickcheck/rr-quickcheck.cabal index 11d0137c..aad4f117 100644 --- a/rr-quickcheck/rr-quickcheck.cabal +++ b/rr-quickcheck/rr-quickcheck.cabal @@ -18,6 +18,7 @@ cabal-version: >=1.10 library exposed-modules: Test.Relational.QuickCheck.Model + Test.Relational.QuickCheck.Transaction Test.Relational.QuickCheck.Arbitrary -- other-modules: other-extensions: TemplateHaskell, MultiParamTypeClasses, FlexibleInstances @@ -25,6 +26,7 @@ library , QuickCheck >=2 , HDBC , HDBC-session + , persistable-record , relational-query , relational-query-HDBC hs-source-dirs: src diff --git a/rr-quickcheck/src/Test/Relational/QuickCheck/Transaction.hs b/rr-quickcheck/src/Test/Relational/QuickCheck/Transaction.hs new file mode 100644 index 00000000..dec486ed --- /dev/null +++ b/rr-quickcheck/src/Test/Relational/QuickCheck/Transaction.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE FlexibleContexts #-} + +module Test.Relational.QuickCheck.Transaction ( + initializeTable, + ) where + +import Database.HDBC (IConnection, SqlValue) +import Database.Record (ToSql) +import Database.Relational.Query +import Database.HDBC.Record (runInsert) + + +initializeTable :: (IConnection conn, TableDerivable a, ToSql SqlValue a) + => conn + -> [a] + -> IO () +initializeTable conn xs = mapM_ (runInsert conn $ derivedInsert id') xs