From 49887e6ce64d8eaf8d674fd81779b0f505464d68 Mon Sep 17 00:00:00 2001 From: Isaac van Bakel Date: Fri, 24 Mar 2023 12:43:11 +0000 Subject: [PATCH 1/4] Add openRawSqliteConn to Database.Persist.Sqlite This new function allows for creating a `RawSqlite SqlBackend` manually (without exposing the `RawSqlite` constructor) for code that wants to open such a connection without having to opt-in to the resource management of `withRawSqliteConnInfo` and co. This is useful in my particular use case for creating a custom pool, since I am not constrained by the `resource-pool` API re-exposed by `persistent-sqlite`. --- persistent-sqlite/Database/Persist/Sqlite.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/persistent-sqlite/Database/Persist/Sqlite.hs b/persistent-sqlite/Database/Persist/Sqlite.hs index ccfecd605..01bb6093d 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 @@ -938,6 +939,20 @@ 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. +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 From 0b705a768fcf26bb2d61f374cc50f6f74e456695 Mon Sep 17 00:00:00 2001 From: Isaac van Bakel Date: Fri, 24 Mar 2023 12:43:11 +0000 Subject: [PATCH 2/4] Bump persistent-sqlite version, add @since tags --- persistent-sqlite/Database/Persist/Sqlite.hs | 2 ++ persistent-sqlite/persistent-sqlite.cabal | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/persistent-sqlite/Database/Persist/Sqlite.hs b/persistent-sqlite/Database/Persist/Sqlite.hs index 01bb6093d..fe833fcb7 100644 --- a/persistent-sqlite/Database/Persist/Sqlite.hs +++ b/persistent-sqlite/Database/Persist/Sqlite.hs @@ -945,6 +945,8 @@ data RawSqlite backend = RawSqlite -- 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 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 From 2c990bd505b7f6e32a3e052a2a63bb54b76d0938 Mon Sep 17 00:00:00 2001 From: Isaac van Bakel Date: Fri, 24 Mar 2023 12:43:11 +0000 Subject: [PATCH 3/4] Run stylish-haskell on Database.Persist.Sqlite --- persistent-sqlite/Database/Persist/Sqlite.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistent-sqlite/Database/Persist/Sqlite.hs b/persistent-sqlite/Database/Persist/Sqlite.hs index fe833fcb7..e5b1a3701 100644 --- a/persistent-sqlite/Database/Persist/Sqlite.hs +++ b/persistent-sqlite/Database/Persist/Sqlite.hs @@ -95,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) From 7258495cbf2ecfe2bafe0f8464fbd8bacdc8cc5c Mon Sep 17 00:00:00 2001 From: Isaac van Bakel Date: Fri, 24 Mar 2023 12:43:11 +0000 Subject: [PATCH 4/4] Add openRawSqliteConn to persistent-sqlite ChangeLog.md --- persistent-sqlite/ChangeLog.md | 6 ++++++ 1 file changed, 6 insertions(+) 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)