monad-persist

An mtl-style typeclass and transformer for persistent. https://github.com/cjdev/monad-persist#readme

Latest on Hackage:0.0.3.0

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

ISC licensed and maintained by Alexis King

monad-persist Build Status

This module provides an mtl-style MonadPersist typeclass for persistent, as well as a PersistT monad transformer that implements it. This makes it easier to use persistent in an arbitrary monad transformer stack, rather than one that must be ReaderT over MonadIO.

import Control.Monad.Logger (runNoLoggingT)
import Control.Monad.Persist
import Data.Text (Text)
import Database.Persist.Sqlite (withSqliteConn)
import Database.Persist.TH

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
User
  name Text
  email Text

  UniqueEmail email

  deriving Eq Show
|]


ghci> runNoLoggingT $ withSqliteConn ":memory:" $ \conn -> flip runSqlPersistT conn $ do
        runMigration migrateAll
        insert_ User { userName = "Alyssa", userEmail = "alyssa@example.com" }
        users <- selectList [] []
        return (users :: [Entity User])

Migrating: CREATE TABLE "user"("id" INTEGER PRIMARY KEY,"name" VARCHAR NOT NULL,"email" VARCHAR NOT NULL,CONSTRAINT "unique_email" UNIQUE ("email"))
[Entity {entityKey = UserKey {unUserKey = SqlBackendKey {unSqlBackendKey = 1}}, entityVal = User {userName = "Alyssa", userEmail = "alyssa@example.com"}}]

For more information, see the documentation on Hackage.

Changes

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.

0.0.1.4 (October 10th, 2017)

  • Fixed package dependencies for GHC 7.8 and 7.10.

0.0.1.3 (October 10th, 2017)

  • Added runSqlPoolPersistT (#2).

0.0.1.2 (April 26th, 2017)

  • Removed the need for MonadIO when running PersistT, since MonadBaseControl IO is already enough.

0.0.1.1 (April 24th, 2017)

  • Added instances for MonadThrow, MonadCatch, and MonadMask to PersistT.

0.0.1.0 (April 20th, 2017)

  • Initial release
comments powered byDisqus