Skip to content

Commit

Permalink
Also export unsafeAcquireConnFromPool
Browse files Browse the repository at this point in the history
Turns out it's needed to do somethings using SQLite and there's no point
in not exporting it and making users reimplement it themselves.
  • Loading branch information
merijn committed Jan 6, 2020
1 parent f79eb87 commit 341c3a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion persistent/Database/Persist/Sql.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Database.Persist
import Database.Persist.Sql.Types
import Database.Persist.Sql.Types.Internal (IsolationLevel (..))
import Database.Persist.Sql.Class
import Database.Persist.Sql.Run hiding (withResourceTimeout, rawAcquireSqlConnFromPool, rawAcquireSqlConn)
import Database.Persist.Sql.Run hiding (withResourceTimeout, rawAcquireSqlConn)
import Database.Persist.Sql.Raw
import Database.Persist.Sql.Migration
import Database.Persist.Sql.Internal
Expand Down
15 changes: 11 additions & 4 deletions persistent/Database/Persist/Sql/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ import Database.Persist.Sql.Types
import Database.Persist.Sql.Types.Internal (IsolationLevel)
import Database.Persist.Sql.Raw

rawAcquireSqlConnFromPool
-- | The returned 'Acquire' gets a connection from the pool, but does __NOT__
-- start a new transaction. Used to implement 'acquireSqlConnFromPool' and
-- 'acquireSqlConnFromPoolWithIsolation', this is useful for performing actions
-- on a connection that cannot be done within a transaction, such as VACUUM in
-- Sqlite.
--
-- @since 2.10.5
unsafeAcquireSqlConnFromPool
:: forall backend m
. (MonadReader (Pool backend) m, BackendCompatible SqlBackend backend)
=> m (Acquire backend)
rawAcquireSqlConnFromPool = do
unsafeAcquireSqlConnFromPool = do
pool <- MonadReader.ask

let freeConn :: (backend, LocalPool backend) -> ReleaseType -> IO ()
Expand Down Expand Up @@ -56,7 +63,7 @@ acquireSqlConnFromPool
:: (MonadReader (Pool backend) m, BackendCompatible SqlBackend backend)
=> m (Acquire backend)
acquireSqlConnFromPool = do
connFromPool <- rawAcquireSqlConnFromPool
connFromPool <- unsafeAcquireSqlConnFromPool
return $ connFromPool >>= acquireSqlConn

-- | Like 'acquireSqlConnFromPool', but lets you specify an explicit isolation
Expand All @@ -67,7 +74,7 @@ acquireSqlConnFromPoolWithIsolation
:: (MonadReader (Pool backend) m, BackendCompatible SqlBackend backend)
=> IsolationLevel -> m (Acquire backend)
acquireSqlConnFromPoolWithIsolation isolation = do
connFromPool <- rawAcquireSqlConnFromPool
connFromPool <- unsafeAcquireSqlConnFromPool
return $ connFromPool >>= acquireSqlConnWithIsolation isolation

-- | Get a connection from the pool, run the given action, and then return the
Expand Down

0 comments on commit 341c3a8

Please sign in to comment.