monad-persist 0.0.2.0 → 0.0.3.0
raw patch · 6 files changed
+44/−24 lines, 6 filesdep ~persistentPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: persistent
API changes (from Hackage documentation)
+ Control.Monad.Persist: Entity :: Key record -> record -> Entity record
+ Control.Monad.Persist: [entityKey] :: Entity record -> Key record
+ Control.Monad.Persist: [entityVal] :: Entity record -> record
+ Control.Monad.Persist: class (PersistStoreWrite backend, PersistEntity record, BaseBackend backend ~ PersistEntityBackend record) => DeleteCascade record backend
+ Control.Monad.Persist: class HasPersistBackend backend => IsPersistBackend backend
+ Control.Monad.Persist: class (PersistCore backend, PersistStoreRead backend) => PersistQueryRead backend
+ Control.Monad.Persist: class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite backend
+ Control.Monad.Persist: class (Show BackendKey backend, Read BackendKey backend, Eq BackendKey backend, Ord BackendKey backend, PersistCore backend, PersistField BackendKey backend, ToJSON BackendKey backend, FromJSON BackendKey backend) => PersistStoreRead backend
+ Control.Monad.Persist: class (Show BackendKey backend, Read BackendKey backend, Eq BackendKey backend, Ord BackendKey backend, PersistStoreRead backend, PersistField BackendKey backend, ToJSON BackendKey backend, FromJSON BackendKey backend) => PersistStoreWrite backend
+ Control.Monad.Persist: class (PersistCore backend, PersistStoreRead backend) => PersistUniqueRead backend
+ Control.Monad.Persist: class (PersistUniqueRead backend, PersistStoreWrite backend) => PersistUniqueWrite backend
+ Control.Monad.Persist: class RawSql a
+ Control.Monad.Persist: data Entity record
+ Control.Monad.Persist: data Filter record
+ Control.Monad.Persist: data PersistValue
+ Control.Monad.Persist: data SelectOpt record
+ Control.Monad.Persist: data SqlBackend
+ Control.Monad.Persist: data Update record
+ Control.Monad.Persist: runSqlConn :: (MonadUnliftIO m, IsSqlBackend backend) => ReaderT backend m a -> backend -> m a
+ Control.Monad.Persist: runSqlPool :: (MonadUnliftIO m, IsSqlBackend backend) => ReaderT backend m a -> Pool backend -> m a
+ Control.Monad.Persist: type CautiousMigration = [(Bool, Sql)]
+ Control.Monad.Persist: type ConnectionPool = Pool SqlBackend
+ Control.Monad.Persist: type Migration = WriterT [Text] WriterT CautiousMigration ReaderT SqlBackend IO ()
+ Control.Monad.Persist: type PersistRecordBackend record backend = (PersistEntity record, PersistEntityBackend record ~ BaseBackend backend)
+ Control.Monad.Persist: type Sql = Text
- Control.Monad.Persist: class Monad m => MonadPersist backend m | m -> backend where get a = lift $ get a insert a = lift $ insert a insert_ a = lift $ insert_ a insertMany a = lift $ insertMany a insertMany_ a = lift $ insertMany_ a insertEntityMany a = lift $ insertEntityMany a insertKey a b = lift $ insertKey a b repsert a b = lift $ repsert a b replace a b = lift $ replace a b delete a = lift $ delete a update a b = lift $ update a b updateGet a b = lift $ updateGet a b getJust a = lift $ getJust a belongsTo a b = lift $ belongsTo a b belongsToJust a b = lift $ belongsToJust a b insertEntity a = lift $ insertEntity a getBy a = lift $ getBy a deleteBy a = lift $ deleteBy a insertUnique a = lift $ insertUnique a upsert a b = lift $ upsert a b getByValue a = lift $ getByValue a insertBy a = lift $ insertBy a replaceUnique a b = lift $ replaceUnique a b checkUnique a = lift $ checkUnique a onlyUnique a = lift $ onlyUnique a selectFirst a b = lift $ selectFirst a b count a = lift $ count a updateWhere a b = lift $ updateWhere a b deleteWhere a = lift $ deleteWhere a selectList a b = lift $ selectList a b selectKeysList a b = lift $ selectKeysList a b deleteCascade a = lift $ deleteCascade a deleteCascadeWhere a = lift $ deleteCascadeWhere a parseMigration a = lift $ parseMigration a parseMigration' a = lift $ parseMigration' a printMigration a = lift $ printMigration a showMigration a = lift $ showMigration a getMigration a = lift $ getMigration a runMigration a = lift $ runMigration a runMigrationSilent a = lift $ runMigrationSilent a runMigrationUnsafe a = lift $ runMigrationUnsafe a rawExecute a b = lift $ rawExecute a b rawExecuteCount a b = lift $ rawExecuteCount a b rawSql a b = lift $ rawSql a b transactionSave = lift transactionSave transactionUndo = lift transactionUndo upsertBy a b c = lift $ upsertBy a b c getJustEntity a = lift $ getJustEntity a getEntity a = lift $ getEntity a insertRecord a = lift $ insertRecord a
+ Control.Monad.Persist: class Monad m => MonadPersist backend m | m -> backend
Files
- CHANGELOG.md +4/−0
- library/Control/Monad/Persist.hs +10/−2
- monad-persist.cabal +17/−14
- package.yaml +3/−2
- stack.yaml +1/−1
- test-suite/Control/Monad/PersistSpec.hs +9/−5
CHANGELOG.md view
@@ -1,3 +1,7 @@+## 0.0.3.0 (September 18th, 2018)++- Added support for `persistent` version 2.8.0 and above.+ ## 0.0.2.0 (November 9th, 2017) - Added lifting instance for `MonadPersist` for `IdentityT`.
library/Control/Monad/Persist.hs view
@@ -5,6 +5,7 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-}@@ -57,6 +58,7 @@ , defaultLiftWith , defaultRestoreM , defaultRestoreT+ , control ) import Control.Monad.Trans.Identity (IdentityT) import Control.Monad.Writer (MonadWriter, WriterT)@@ -113,14 +115,20 @@ -- | Runs a 'SqlPersistT' computation against a SQL database. __Unlike__ -- 'runPersistT', the computation is run inside a transaction. runSqlPersistT :: MonadBaseControl IO m => SqlPersistT m a -> SqlBackend -> m a-runSqlPersistT (PersistT m) = runSqlConn m+runSqlPersistT (PersistT m) r = liftBaseRunReaderT (flip runSqlConn r) m {-# INLINE runSqlPersistT #-} -- | Runs a 'SqlPersistT' computation against a SQL database using a pool of -- connections. The computation is run inside a transaction. runSqlPoolPersistT :: MonadBaseControl IO m => SqlPersistT m a -> ConnectionPool -> m a-runSqlPoolPersistT (PersistT m) = runSqlPool m+runSqlPoolPersistT (PersistT m) r = liftBaseRunReaderT (flip runSqlPool r) m {-# INLINE runSqlPoolPersistT #-}++-- Helper function for runSqlPersistT and runSqlPoolPersistT to adapt runSqlConn+-- and runSqlPool to use MonadBaseControl instead of MonadUnliftIO. For more+-- details, see cjdev/monad-persist#4.+liftBaseRunReaderT :: MonadBaseControl b m => (forall c. ReaderT r b c -> b c) -> ReaderT r m a -> m a+liftBaseRunReaderT f m = control $ \runInBase -> f (mapReaderT runInBase m) instance MonadTransControl (PersistT backend) where type StT (PersistT backend) a = StT (ReaderT SqlBackend) a
monad-persist.cabal view
@@ -1,9 +1,11 @@--- This file has been generated from package.yaml by hpack version 0.18.1.+-- This file has been generated from package.yaml by hpack version 0.28.2. -- -- see: https://github.com/sol/hpack+--+-- hash: 58cf23e0f8e24c96c91c1a1b4d326164fcc139652890ce28de144149541c30c2 name: monad-persist-version: 0.0.2.0+version: 0.0.3.0 synopsis: An mtl-style typeclass and transformer for persistent. description: An mtl-style typeclass and transformer for persistent. category: Database@@ -16,7 +18,6 @@ license-file: LICENSE build-type: Simple cabal-version: >= 1.10- extra-source-files: CHANGELOG.md package.yaml@@ -28,28 +29,31 @@ location: https://github.com/cjdev/monad-persist library+ exposed-modules:+ Control.Monad.Persist+ other-modules:+ Paths_monad_persist hs-source-dirs: library ghc-options: -Wall build-depends:- base >= 4.7 && < 5- , exceptions >= 0.6- , monad-control >= 1.0.0.0 && < 2- , monad-logger >= 0.3.10+ base >=4.8 && <5+ , exceptions >=0.6+ , monad-control >=1.0.0.0 && <2+ , monad-logger >=0.3.10 , mtl- , persistent >= 2.5 && < 3+ , persistent >=2.5 && <3 , text , transformers , transformers-base- exposed-modules:- Control.Monad.Persist- other-modules:- Paths_monad_persist default-language: Haskell2010 test-suite monad-persist-test-suite type: exitcode-stdio-1.0 main-is: Main.hs+ other-modules:+ Control.Monad.PersistSpec+ Paths_monad_persist hs-source-dirs: test-suite ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N@@ -63,6 +67,5 @@ , persistent-sqlite , persistent-template , text- other-modules:- Control.Monad.PersistSpec+ , transformers default-language: Haskell2010
package.yaml view
@@ -1,5 +1,5 @@ name: monad-persist-version: 0.0.2.0+version: 0.0.3.0 category: Database synopsis: An mtl-style typeclass and transformer for persistent. description: An mtl-style typeclass and transformer for persistent.@@ -19,7 +19,7 @@ library: dependencies:- - base >= 4.7 && < 5+ - base >= 4.8 && < 5 - exceptions >= 0.6 - monad-control >= 1.0.0.0 && < 2 - monad-logger >= 0.3.10@@ -42,6 +42,7 @@ - persistent-sqlite - persistent-template - text+ - transformers ghc-options: - -rtsopts - -threaded
stack.yaml view
@@ -1,4 +1,4 @@-resolver: lts-8.11+resolver: lts-12.10 packages: - '.'
test-suite/Control/Monad/PersistSpec.hs view
@@ -13,11 +13,12 @@ import qualified Test.Hspec as Hspec -import Control.Monad.Logger (NoLoggingT, runNoLoggingT)+import Control.Monad.Logger (runNoLoggingT) import Control.Monad.IO.Class (MonadIO, liftIO)-import Control.Monad.Trans.Control (MonadBaseControl)+import Control.Monad.Trans.Class (lift)+import Control.Monad.Trans.Control (MonadBaseControl, control) import Data.Text (Text)-import Database.Persist.Sqlite (withSqliteConn)+import Database.Persist.Sqlite (IsSqlBackend, withSqliteConn) import Database.Persist.TH import Test.Hspec hiding (shouldBe) @@ -33,8 +34,11 @@ deriving Eq Show |] -runSqlite :: (MonadIO m, MonadBaseControl IO m) => SqlPersistT (NoLoggingT m) a -> m a-runSqlite x = runNoLoggingT $ withSqliteConn ":memory:" (runSqlPersistT (runMigrationSilent migrateAll >> x))+runSqlite :: (MonadIO m, MonadBaseControl IO m) => SqlPersistT m a -> m a+runSqlite x = liftedWithSqliteConn ":memory:" (runSqlPersistT (runMigrationSilent migrateAll >> x))+ where+ liftedWithSqliteConn :: (MonadBaseControl IO m, IsSqlBackend backend) => Text -> (backend -> m a) -> m a+ liftedWithSqliteConn txt f = control $ \runInBase -> runNoLoggingT (withSqliteConn txt (lift . runInBase . f)) shouldBe :: (Eq a, Show a, MonadIO m) => a -> a -> m () shouldBe x y = liftIO $ Hspec.shouldBe x y