Add 'yesod-persistent/' from commit '17e7ae34d400c8c0bc00a9caa2afe8d06653d7ad'
git-subtree-dir: yesod-persistent git-subtree-mainline:894336a482git-subtree-split:17e7ae34d4
This commit is contained in:
commit
c00259b3fe
25
yesod-persistent/LICENSE
Normal file
25
yesod-persistent/LICENSE
Normal file
@ -0,0 +1,25 @@
|
||||
The following license covers this documentation, and the source code, except
|
||||
where otherwise indicated.
|
||||
|
||||
Copyright 2010, Michael Snoyman. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
0
yesod-persistent/README
Normal file
0
yesod-persistent/README
Normal file
7
yesod-persistent/Setup.lhs
Executable file
7
yesod-persistent/Setup.lhs
Executable file
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env runhaskell
|
||||
|
||||
> module Main where
|
||||
> import Distribution.Simple
|
||||
|
||||
> main :: IO ()
|
||||
> main = defaultMain
|
||||
41
yesod-persistent/Yesod/Persist.hs
Normal file
41
yesod-persistent/Yesod/Persist.hs
Normal file
@ -0,0 +1,41 @@
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
module Yesod.Persist
|
||||
( YesodPersist (..)
|
||||
, get404
|
||||
, getBy404
|
||||
, module Database.Persist
|
||||
, module Database.Persist.TH
|
||||
) where
|
||||
|
||||
import Database.Persist
|
||||
import Database.Persist.TH
|
||||
import Control.Monad.Trans.Class (MonadTrans (..))
|
||||
import Control.Failure (Failure)
|
||||
|
||||
import Yesod.Handler
|
||||
|
||||
class YesodPersist y where
|
||||
type YesodDB y :: (* -> *) -> * -> *
|
||||
runDB :: YesodDB y (GGHandler sub y IO) a -> GHandler sub y a
|
||||
|
||||
-- | Get the given entity by ID, or return a 404 not found if it doesn't exist.
|
||||
get404 :: (PersistBackend (t m), PersistEntity val, Monad (t m),
|
||||
Failure ErrorResponse m, MonadTrans t)
|
||||
=> Key val -> t m val
|
||||
get404 key = do
|
||||
mres <- get key
|
||||
case mres of
|
||||
Nothing -> lift notFound
|
||||
Just res -> return res
|
||||
|
||||
-- | Get the given entity by unique key, or return a 404 not found if it doesn't
|
||||
-- exist.
|
||||
getBy404 :: (PersistBackend (t m), PersistEntity val, Monad (t m),
|
||||
Failure ErrorResponse m, MonadTrans t)
|
||||
=> Unique val -> t m (Key val, val)
|
||||
getBy404 key = do
|
||||
mres <- getBy key
|
||||
case mres of
|
||||
Nothing -> lift notFound
|
||||
Just res -> return res
|
||||
27
yesod-persistent/yesod-persistent.cabal
Normal file
27
yesod-persistent/yesod-persistent.cabal
Normal file
@ -0,0 +1,27 @@
|
||||
name: yesod-persistent
|
||||
version: 0.2.0
|
||||
license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Michael Snoyman <michael@snoyman.com>
|
||||
maintainer: Michael Snoyman <michael@snoyman.com>
|
||||
synopsis: Some helpers for using Persistent from Yesod.
|
||||
category: Web, Yesod, Database
|
||||
stability: Stable
|
||||
cabal-version: >= 1.6
|
||||
build-type: Simple
|
||||
homepage: http://www.yesodweb.com/
|
||||
|
||||
library
|
||||
build-depends: base >= 4 && < 5
|
||||
, yesod-core >= 0.8 && < 0.10
|
||||
, persistent >= 0.6 && < 0.7
|
||||
, persistent-template >= 0.6 && < 0.7
|
||||
, failure >= 0.1 && < 0.2
|
||||
, transformers >= 0.2 && < 0.3
|
||||
, web-routes-quasi >= 0.7.1 && < 0.8
|
||||
exposed-modules: Yesod.Persist
|
||||
ghc-options: -Wall
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
location: git://github.com/snoyberg/yesod-persistent.git
|
||||
Loading…
Reference in New Issue
Block a user