The monad-persist package

[Tags:library, test]

An mtl-style typeclass and transformer for persistent.


[Skip to Readme]

Properties

Versions 0.0.1.0, 0.0.1.1, 0.0.1.2
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), exceptions (>=0.6), monad-control (>=1.0.0.0 && <2), monad-logger (>=0.3.10), mtl, persistent (>=2.5 && <3), text, transformers-base [details]
License ISC
Copyright 2017 CJ Affiliate by Conversant
Author Alexis King <lexi.lambda@gmail.com>
Maintainer Alexis King <lexi.lambda@gmail.com>
Category Database
Uploaded Thu Apr 27 03:57:03 UTC 2017 by lexi_lambda
Distributions NixOS:0.0.1.2
Downloads 116 total (5 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-04-27 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for monad-persist

Readme for monad-persist-0.0.1.2

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"}}]