groundhog-sqlite 0.4.0.1 → 0.4.0.2
raw patch · 2 files changed
+22/−17 lines, 2 filesdep ~groundhog
Dependency ranges changed: groundhog
Files
- Database/Groundhog/Sqlite.hs +19/−14
- groundhog-sqlite.cabal +3/−3
Database/Groundhog/Sqlite.hs view
@@ -2,6 +2,7 @@ module Database.Groundhog.Sqlite ( withSqlitePool , withSqliteConn+ , createSqlitePool , runDbConn , Sqlite(..) , module Database.Groundhog@@ -53,13 +54,13 @@ type PhantomDb (DbPersist Sqlite m) = Sqlite insert v = insert' v insert_ v = insert_' v- insertBy u v = H.insertBy escapeS queryRawTyped u v- insertByAll v = H.insertByAll escapeS queryRawTyped v+ insertBy u v = H.insertBy escapeS queryRawTyped " IS ?" u v+ insertByAll v = H.insertByAll escapeS queryRawTyped " IS ?" v replace k v = H.replace escapeS queryRawTyped executeRawCached' insertIntoConstructorTable k v select options = H.select escapeS queryRawTyped "LIMIT -1" renderCond' options -- select' options selectAll = H.selectAll escapeS queryRawTyped get k = H.get escapeS queryRawTyped k- getBy k = H.getBy escapeS queryRawTyped k+ getBy k = H.getBy escapeS queryRawTyped " IS ?" k update upds cond = H.update escapeS executeRawCached' renderCond' upds cond delete cond = H.delete escapeS executeRawCached' renderCond' cond deleteByKey k = H.deleteByKey escapeS executeRawCached' k@@ -88,33 +89,37 @@ analyzeFunction = error "analyzeFunction: is not supported by Sqlite" withSqlitePool :: (MonadBaseControl IO m, MonadIO m)- => String+ => String -- ^ connection string -> Int -- ^ number of connections to open -> (Pool Sqlite -> m a) -> m a-withSqlitePool s connCount f = liftIO (createPool (open' s) close' 1 20 connCount) >>= f+withSqlitePool s connCount f = createSqlitePool s connCount >>= f withSqliteConn :: (MonadBaseControl IO m, MonadIO m)- => String+ => String -- ^ connection string -> (Sqlite -> m a) -> m a withSqliteConn s = bracket (liftIO $ open' s) (liftIO . close') +createSqlitePool :: MonadIO m+ => String -- ^ connection string+ -> Int -- ^ number of connections to open+ -> m (Pool Sqlite)+createSqlitePool s connCount = liftIO $ createPool (open' s) close' 1 20 connCount+ instance Savepoint Sqlite where withConnSavepoint name m (Sqlite c _) = do- let runStmt query = S.prepare c query >>= \stmt -> S.step stmt >> S.finalize stmt let name' = fromString name- liftIO $ runStmt $ "SAVEPOINT " <> name'- x <- onException m (liftIO $ runStmt $ "ROLLBACK TO " <> name')- liftIO $ runStmt $ "RELEASE " <> name'+ liftIO $ S.exec c $ "SAVEPOINT " <> name'+ x <- onException m (liftIO $ S.exec c $ "ROLLBACK TO " <> name')+ liftIO $ S.exec c $ "RELEASE " <> name' return x instance ConnectionManager Sqlite Sqlite where withConn f conn@(Sqlite c _) = do- let runStmt query = S.prepare c query >>= \stmt -> S.step stmt >> S.finalize stmt- liftIO $ runStmt "BEGIN"- x <- onException (f conn) (liftIO $ runStmt "ROLLBACK")- liftIO $ runStmt "COMMIT"+ liftIO $ S.exec c "BEGIN"+ x <- onException (f conn) (liftIO $ S.exec c "ROLLBACK")+ liftIO $ S.exec c "COMMIT" return x withConnNoTransaction f conn = f conn
groundhog-sqlite.cabal view
@@ -1,5 +1,5 @@ name: groundhog-sqlite-version: 0.4.0.1+version: 0.4.0.2 license: BSD3 license-file: LICENSE author: Boris Lykah <lykahb@gmail.com>@@ -7,7 +7,7 @@ synopsis: Sqlite3 backend for the groundhog library description: It depends on direct-sqlite library which includes Sqlite C sources, so there are no system dependencies. category: Database-stability: Non-stable+stability: Stable cabal-version: >= 1.6 build-type: Simple @@ -15,7 +15,7 @@ build-depends: base >= 4 && < 5 , bytestring >= 0.9 , transformers >= 0.2.1- , groundhog >= 0.4.0 && < 0.5.0+ , groundhog >= 0.4.0.2 && < 0.5.0 , monad-control >= 0.3 , monad-logger >= 0.3 , containers >= 0.2