yesod-persistent-1.4.0.5: Some helpers for using Persistent from Yesod.

Safe HaskellNone
LanguageHaskell98

Yesod.Persist.Core

Description

Defines the core functionality of this package. This package is distinguished from Yesod.Persist in that the latter additionally exports the persistent modules themselves.

Synopsis

Documentation

class Monad (YesodDB site) => YesodPersist site where Source #

Minimal complete definition

runDB

Associated Types

type YesodPersistBackend site Source #

Methods

runDB :: YesodDB site a -> HandlerT site IO a Source #

defaultRunDB :: PersistConfig c => (site -> c) -> (site -> PersistConfigPool c) -> PersistConfigBackend c (HandlerT site IO) a -> HandlerT site IO a Source #

Helper for creating runDB.

Since 1.2.0

class YesodPersist site => YesodPersistRunner site where Source #

Since 1.2.0

Minimal complete definition

getDBRunner

Methods

getDBRunner :: HandlerT site IO (DBRunner site, HandlerT site IO ()) Source #

This function differs from runDB in that it returns a database runner function, as opposed to simply running a single action. This will usually mean that a connection is taken from a pool and then reused for each invocation. This can be useful for creating streaming responses; see runDBSource.

It additionally returns a cleanup function to free the connection. If your code finishes successfully, you must call this cleanup to indicate changes should be committed. Otherwise, for SQL backends at least, a rollback will be used instead.

Since 1.2.0

defaultGetDBRunner :: (IsSqlBackend backend, YesodPersistBackend site ~ backend) => (site -> Pool backend) -> HandlerT site IO (DBRunner site, HandlerT site IO ()) Source #

Helper for implementing getDBRunner.

Since 1.2.0

newtype DBRunner site Source #

Constructors

DBRunner 

Fields

runDBSource :: YesodPersistRunner site => Source (YesodDB site) a -> Source (HandlerT site IO) a Source #

Like runDB, but transforms a Source. See respondSourceDB for an example, practical use case.

Since 1.2.0

respondSourceDB :: YesodPersistRunner site => ContentType -> Source (YesodDB site) (Flush Builder) -> HandlerT site IO TypedContent Source #

Extends respondSource to create a streaming database response body.

get404 :: (MonadIO m, PersistStore backend, PersistRecordBackend val backend) => Key val -> ReaderT backend m val Source #

Get the given entity by ID, or return a 404 not found if it doesn't exist.

getBy404 :: (PersistUnique backend, PersistRecordBackend val backend, MonadIO m) => Unique val -> ReaderT backend m (Entity val) Source #

Get the given entity by unique key, or return a 404 not found if it doesn't exist.