-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Some helpers for using Persistent from Yesod.
--   
--   API docs and the README are available at
--   <a>http://www.stackage.org/package/yesod-persistent</a>
@package yesod-persistent
@version 1.6.0.8


-- | Defines the core functionality of this package. This package is
--   distinguished from Yesod.Persist in that the latter additionally
--   exports the persistent modules themselves.
module Yesod.Persist.Core
class Monad (YesodDB site) => YesodPersist site where {
    type YesodPersistBackend site;
}

-- | Allows you to execute database actions within Yesod Handlers. For
--   databases that support it, code inside the action will run as an
--   atomic transaction.
--   
--   <h4><b>Example Usage</b></h4>
--   
--   <pre>
--   userId &lt;- runDB $ do
--     userId &lt;- insert $ User "username" "email@example.com"
--     insert_ $ UserPreferences userId True
--     pure userId
--   </pre>
runDB :: YesodPersist site => YesodDB site a -> HandlerFor site a

-- | Helper for creating <a>runDB</a>.
--   
--   Since 1.2.0
defaultRunDB :: PersistConfig c => (site -> c) -> (site -> PersistConfigPool c) -> PersistConfigBackend c (HandlerFor site) a -> HandlerFor site a

-- | Since 1.2.0
class YesodPersist site => YesodPersistRunner site

-- | This function differs from <a>runDB</a> 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 <a>runDBSource</a>.
--   
--   It additionally returns a cleanup function to free the connection. If
--   your code finishes successfully, you <i>must</i> 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
getDBRunner :: YesodPersistRunner site => HandlerFor site (DBRunner site, HandlerFor site ())

-- | Helper for implementing <a>getDBRunner</a>.
--   
--   Since 1.2.0
defaultGetDBRunner :: (IsSqlBackend backend, YesodPersistBackend site ~ backend) => (site -> Pool backend) -> HandlerFor site (DBRunner site, HandlerFor site ())
newtype DBRunner site
DBRunner :: (forall a. YesodDB site a -> HandlerFor site a) -> DBRunner site
[runDBRunner] :: DBRunner site -> forall a. YesodDB site a -> HandlerFor site a

-- | Like <a>runDB</a>, but transforms a <tt>Source</tt>. See
--   <a>respondSourceDB</a> for an example, practical use case.
--   
--   Since 1.2.0
runDBSource :: YesodPersistRunner site => ConduitT () a (YesodDB site) () -> ConduitT () a (HandlerFor site) ()

-- | Extends <a>respondSource</a> to create a streaming database response
--   body.
respondSourceDB :: YesodPersistRunner site => ContentType -> ConduitT () (Flush Builder) (YesodDB site) () -> HandlerFor site TypedContent
type YesodDB site = ReaderT (YesodPersistBackend site) (HandlerFor site)

-- | Get the given entity by ID, or return a 404 not found if it doesn't
--   exist.
get404 :: (MonadIO m, PersistStoreRead backend, PersistRecordBackend val backend) => Key val -> ReaderT backend m val

-- | Get the given entity by unique key, or return a 404 not found if it
--   doesn't exist.
getBy404 :: (PersistUniqueRead backend, PersistRecordBackend val backend, MonadIO m) => Unique val -> ReaderT backend m (Entity val)

-- | Create a new record in the database, returning an automatically
--   created key, or raise a 400 bad request if a uniqueness constraint is
--   violated.
insert400 :: (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend val backend, SafeToInsert val) => val -> ReaderT backend m (Key val)

-- | Same as <a>insert400</a>, but doesn’t return a key.
insert400_ :: (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend val backend, SafeToInsert val) => val -> ReaderT backend m ()

module Yesod.Persist
