Initial code pull from yesod
This commit is contained in:
parent
8c51e6ced1
commit
d37fce1965
25
LICENSE
Normal file
25
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.
|
||||||
39
Yesod/Persist.hs
Normal file
39
Yesod/Persist.hs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
|
module Yesod.Persist
|
||||||
|
( YesodPersist (..)
|
||||||
|
, get404
|
||||||
|
, getBy404
|
||||||
|
, module Database.Persist
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Database.Persist
|
||||||
|
import Control.Monad.Trans.Class (MonadTrans (..))
|
||||||
|
import Control.Failure (Failure)
|
||||||
|
|
||||||
|
import Yesod
|
||||||
|
|
||||||
|
class YesodPersist y where
|
||||||
|
type YesodDB y :: (* -> *) -> * -> *
|
||||||
|
runDB :: YesodDB y (GHandler sub y) 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
|
||||||
25
yesod-persistent.cabal
Normal file
25
yesod-persistent.cabal
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
name: yesod-persistent
|
||||||
|
version: 0.0.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://docs.yesodweb.com/
|
||||||
|
|
||||||
|
library
|
||||||
|
build-depends: base >= 4 && < 5
|
||||||
|
, yesod >= 0.7 && < 0.8
|
||||||
|
, persistent >= 0.4 && < 0.5
|
||||||
|
, failure >= 0.1 && < 0.2
|
||||||
|
, transformers >= 0.2 && < 0.3
|
||||||
|
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