diff --git a/persistent-sqlite/ChangeLog.md b/persistent-sqlite/ChangeLog.md index fcfbcf3b7..feb1edf49 100644 --- a/persistent-sqlite/ChangeLog.md +++ b/persistent-sqlite/ChangeLog.md @@ -1,5 +1,11 @@ # Changelog for persistent-sqlite +## 2.13.2 + +* [#1488](https://github.com/yesodweb/persistent/pull/1488) + * Add `openRawSqliteConn` for creating `RawSqlite SqlBackend` connections + that aren't automatically cleaned-up. + ## 2.13.1.1 * [#1459](https://github.com/yesodweb/persistent/pull/1459) diff --git a/persistent-sqlite/Database/Persist/Sqlite.hs b/persistent-sqlite/Database/Persist/Sqlite.hs index ccfecd605..e5b1a3701 100644 --- a/persistent-sqlite/Database/Persist/Sqlite.hs +++ b/persistent-sqlite/Database/Persist/Sqlite.hs @@ -48,6 +48,7 @@ module Database.Persist.Sqlite , ForeignKeyViolation(..) , checkForeignKeys , RawSqlite + , openRawSqliteConn , persistentBackend , rawSqliteConnection , withRawSqliteConnInfo @@ -94,8 +95,8 @@ import qualified Data.Conduit.Combinators as C import qualified Data.Conduit.List as CL import Data.Foldable (toList) import qualified Data.HashMap.Lazy as HashMap -import Data.Int (Int64) import Data.IORef (newIORef) +import Data.Int (Int64) import Data.Maybe import Data.Pool (Pool) import Data.Text (Text) @@ -938,6 +939,22 @@ data RawSqlite backend = RawSqlite , _rawSqliteConnection :: Sqlite.Connection -- ^ The underlying `Sqlite.Connection` } +-- | Open a @'RawSqlite' 'SqlBackend'@ connection from a 'SqliteConnectionInfo'. +-- +-- When using this function, the caller has to accept the responsibility of +-- cleaning up the resulting connection. To do this, use 'close' with the +-- 'rawSqliteConnection' - it's enough to simply drop the 'persistBackend' +-- afterwards. +-- +-- @since 2.13.2 +openRawSqliteConn + :: (MonadUnliftIO m, MonadLoggerIO m) + => SqliteConnectionInfo + -> m (RawSqlite SqlBackend) +openRawSqliteConn connInfo = do + logFunc <- askLoggerIO + liftIO $ openWith RawSqlite connInfo logFunc + instance BackendCompatible b (RawSqlite b) where projectBackend = _persistentBackend diff --git a/persistent-sqlite/persistent-sqlite.cabal b/persistent-sqlite/persistent-sqlite.cabal index 8b36b1e18..4ec7f20b5 100644 --- a/persistent-sqlite/persistent-sqlite.cabal +++ b/persistent-sqlite/persistent-sqlite.cabal @@ -1,5 +1,5 @@ name: persistent-sqlite -version: 2.13.1.1 +version: 2.13.2.0 license: MIT license-file: LICENSE author: Michael Snoyman