sql-simple 0.1.0.0 → 0.2.0
raw patch · 4 files changed
+77/−26 lines, 4 files
Files
- Database/Sql/Simple.hs +63/−19
- Database/Sql/Simple/Internal.hs +11/−4
- README.md +2/−2
- sql-simple.cabal +1/−1
Database/Sql/Simple.hs view
@@ -1,29 +1,31 @@ {-# LANGUAGE ExplicitNamespaces #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE NoMonomorphismRestriction #-} module Database.Sql.Simple ( -- * data type -- ** query- Query- , specify+ I.Query+ , I.specify -- ** parameter- , ToRow- , FromRow- , Only(..)- , (:.)((:.))+ , I.ToRow+ , I.FromRow+ , I.Only(..)+ , (I.:.)((:.)) -- ** other- , Sql- , Elem- , Backend+ , I.Sql+ , I.Elem+ , I.Backend -- * connection- , ConnectInfo- , withConnection+ , I.ConnectInfo+ , I.withConnection , connect , close -- * execute query- , execute- , execute_- , query- , query_+ , execute, execute_+ , query, query_+ , fold, fold_+ , forEach, forEach_ -- ** transaction , begin , commit@@ -34,9 +36,51 @@ -- @ -- sql (sqlite +:+ postgresql) $ query -- @- , sql- , (+:+)- , type (++)+ , I.sql+ , (I.+:+)+ , type (I.++) ) where -import Database.Sql.Simple.Internal+import qualified Database.Sql.Simple.Internal as I++connect :: I.Backend b => I.ConnectInfo b -> IO b+connect = I.connect++close :: I.Backend b => b -> IO ()+close = I.close++execute :: (I.ToRow b q, I.Backend b) => b -> I.Query -> q -> I.Sql bs ()+execute = I.execute++execute_ :: I.Backend b => b -> I.Query -> I.Sql bs ()+execute_ = I.execute_++query :: (I.Backend b, I.FromRow b r, I.ToRow b q) => b -> I.Query -> q -> I.Sql bs [r]+query = I.query++query_ :: (I.FromRow b r, I.Backend b) => b -> I.Query -> I.Sql bs [r]+query_ = I.query_++fold :: (I.Backend b, I.FromRow b r, I.ToRow b q)+ => b -> I.Query -> q -> a -> (a -> r -> IO a) -> IO a+fold = I.fold++fold_ :: (I.Backend b, I.FromRow b r)+ => b -> I.Query -> a -> (a -> r -> IO a) -> IO a+fold_ = I.fold_++forEach :: (I.Backend b, I.FromRow b r, I.ToRow b q)+ => b -> I.Query -> q -> (r -> IO ()) -> IO ()+forEach = I.forEach++forEach_ :: (I.Backend b, I.FromRow b r)+ => b -> I.Query -> (r -> IO ()) -> IO ()+forEach_ = I.forEach_++begin, commit, rollback :: I.Backend b => b -> I.Sql bs ()+begin = I.begin+commit = I.commit+rollback = I.rollback++withTransaction :: I.Backend b => b -> I.Sql bs a -> I.Sql bs a+withTransaction = I.withTransaction
Database/Sql/Simple/Internal.hs view
@@ -58,14 +58,22 @@ type ToRow b :: * -> Constraint type FromRow b :: * -> Constraint - connect :: ConnectInfo b -> IO b- close :: b -> IO ()+ connect :: ConnectInfo b -> IO b+ close :: b -> IO () execute :: ToRow b q => b -> Query -> q -> Sql c () execute_ :: b -> Query -> Sql c () query :: (FromRow b r, ToRow b q) => b -> Query -> q -> Sql c [r] query_ :: FromRow b r => b -> Query -> Sql c [r]++ fold :: (FromRow b r, ToRow b q) => b -> Query -> q -> a -> (a -> r -> IO a) -> IO a+ fold_ :: FromRow b r => b -> Query -> a -> (a -> r -> IO a) -> IO a++ forEach :: (FromRow b r, ToRow b q) => b -> Query -> q -> (r -> IO ()) -> IO ()+ forEach c q qs = fold c q qs () . const+ forEach_ :: FromRow b r => b -> Query -> (r -> IO ()) -> IO ()+ forEach_ c q = fold_ c q () . const begin :: b -> Sql c () commit :: b -> Sql c ()@@ -90,11 +98,10 @@ -- example: -- -- @--- q = specify sqlite "sqlite query" "common query"+-- q = specify sqlite \"sqlite query\" \"common query\" -- @ specify :: Backend b => proxy ((b :: *) ': '[]) -> T.Text -> Query -> Query specify p q (Query t h) = Query t (H.insert (headt p) q h) where headt :: forall proxy a as. Typeable a => proxy ((a :: *) ': as) -> TypeRep headt _ = typeOf (undefined :: a)-
README.md view
@@ -24,14 +24,14 @@ execute c "INSERT INTO test VALUES (?)" (Only (1 :: Int)) map fromOnly <$> query_ c "SELECT * FROM test" --- or sql function(testQuery' equivalent to testQuery).+-- or sql function(testQuery' is equivalent to testQuery). testQuery' c = sql (sqlite +:+ postgreSQL) $ do execute_ c "CREATE TABLE test (id int)" execute c "INSERT INTO test VALUES (?)" (Only (1 :: Int)) i <- map fromOnly <$> query_ c "SELECT * FROM test" return (i :: [Int]) --- you can specify backend specific Query.+-- you can set backend specific Query. specificQuery :: Backend conn => conn -> Sql '[SQLite, PostgreSQL] () specificQuery c = execute_ c (specify sqlite "[sqlite query]" "[common query]")
sql-simple.cabal view
@@ -1,5 +1,5 @@ name: sql-simple-version: 0.1.0.0+version: 0.2.0 synopsis: common middle-level sql client. description: please read README.md <https://github.com/philopon/sql-simple/blob/master/README.md> license: MIT