Sql.hs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. module Database.Persist.Sql
  2. ( module Database.Persist.Sql.Types
  3. , module Database.Persist.Sql.Class
  4. , module Database.Persist.Sql.Run
  5. , module Database.Persist.Sql.Migration
  6. , module Database.Persist
  7. , module Database.Persist.Sql.Orphan.PersistStore
  8. , rawQuery
  9. , rawQueryRes
  10. , rawExecute
  11. , rawExecuteCount
  12. , rawSql
  13. , deleteWhereCount
  14. , updateWhereCount
  15. , transactionSave
  16. , transactionSaveWithIsolation
  17. , transactionUndo
  18. , transactionUndoWithIsolation
  19. , IsolationLevel (..)
  20. , getStmtConn
  21. -- * Internal
  22. , module Database.Persist.Sql.Internal
  23. , decorateSQLWithLimitOffset
  24. ) where
  25. import Control.Monad.IO.Class
  26. import Control.Monad.Trans.Reader (ReaderT, ask)
  27. import Database.Persist
  28. import Database.Persist.Sql.Types
  29. import Database.Persist.Sql.Types.Internal (IsolationLevel (..))
  30. import Database.Persist.Sql.Class
  31. import Database.Persist.Sql.Run hiding (withResourceTimeout)
  32. import Database.Persist.Sql.Raw
  33. import Database.Persist.Sql.Migration
  34. import Database.Persist.Sql.Internal
  35. import Database.Persist.Sql.Orphan.PersistQuery
  36. import Database.Persist.Sql.Orphan.PersistStore
  37. import Database.Persist.Sql.Orphan.PersistUnique ()
  38. -- | Commit the current transaction and begin a new one.
  39. --
  40. -- @since 1.2.0
  41. transactionSave :: MonadIO m => ReaderT SqlBackend m ()
  42. transactionSave = do
  43. conn <- ask
  44. let getter = getStmtConn conn
  45. liftIO $ connCommit conn getter >> connBegin conn getter Nothing
  46. -- | Commit the current transaction and begin a new one with the specified isolation level.
  47. --
  48. -- @since 2.9.0
  49. transactionSaveWithIsolation :: MonadIO m => IsolationLevel -> ReaderT SqlBackend m ()
  50. transactionSaveWithIsolation isolation = do
  51. conn <- ask
  52. let getter = getStmtConn conn
  53. liftIO $ connCommit conn getter >> connBegin conn getter (Just isolation)
  54. -- | Roll back the current transaction and begin a new one.
  55. --
  56. -- @since 1.2.0
  57. transactionUndo :: MonadIO m => ReaderT SqlBackend m ()
  58. transactionUndo = do
  59. conn <- ask
  60. let getter = getStmtConn conn
  61. liftIO $ connRollback conn getter >> connBegin conn getter Nothing
  62. -- | Roll back the current transaction and begin a new one with the specified isolation level.
  63. --
  64. -- @since 2.9.0
  65. transactionUndoWithIsolation :: MonadIO m => IsolationLevel -> ReaderT SqlBackend m ()
  66. transactionUndoWithIsolation isolation = do
  67. conn <- ask
  68. let getter = getStmtConn conn
  69. liftIO $ connRollback conn getter >> connBegin conn getter (Just isolation)