Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

runSqlite

  • Loading branch information...
commit 5ec428f21bd18da1cd7575d39f77c8fa72888075 1 parent cb79b81
@snoyberg snoyberg authored
View
16 persistent-sqlite/Database/Persist/Sqlite.hs
@@ -11,6 +11,7 @@ module Database.Persist.Sqlite
, module Database.Persist
, module Database.Persist.GenericSql
, SqliteConf (..)
+ , runSqlite
) where
import Database.Persist hiding (Entity (..))
@@ -22,6 +23,7 @@ import Database.Persist.GenericSql.Internal
import qualified Database.Sqlite as Sqlite
import Control.Monad.IO.Class (MonadIO (..))
+import Control.Monad.Logger (NoLoggingT, runNoLoggingT)
import Data.List (intercalate)
import Data.IORef
import qualified Data.Map as Map
@@ -72,6 +74,20 @@ open' s = do
reset stmt
ignoreExceptions = E.handle (\(_ :: E.SomeException) -> return ())
+-- | A convenience helper which creates a new database connection and runs the
+-- given block, handling @MonadResource@ and @MonadLogger@ requirements. Note
+-- that all log messages are discarded.
+--
+-- Since 1.1.4
+runSqlite :: (MonadBaseControl IO m, MonadIO m)
+ => Text -- ^ connection string
+ -> SqlPersist (NoLoggingT (ResourceT m)) a -- ^ database action
+ -> m a
+runSqlite connstr = runResourceT
+ . runNoLoggingT
+ . withSqliteConn connstr
+ . runSqlConn
+
prepare' :: Sqlite.Connection -> Text -> IO Statement
prepare' conn sql = do
stmt <- Sqlite.prepare conn sql
View
3  persistent-sqlite/persistent-sqlite.cabal
@@ -1,5 +1,5 @@
name: persistent-sqlite
-version: 1.1.3.1
+version: 1.1.4
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
@@ -26,6 +26,7 @@ library
, text >= 0.7
, aeson >= 0.5
, conduit >= 0.5.3
+ , monad-logger >= 0.2.4
exposed-modules: Database.Sqlite
Database.Persist.Sqlite
ghc-options: -Wall
Please sign in to comment.
Something went wrong with that request. Please try again.