From 8c51e6ced120c6dd33923031862a9f23e455d7c2 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 21 Dec 2010 00:27:49 +0200 Subject: [PATCH 1/9] first commit --- README | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 00000000..e69de29b From d37fce19654f7cef1fe0b24ab6ee5e81479eec9f Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 21 Dec 2010 00:29:25 +0200 Subject: [PATCH 2/9] Initial code pull from yesod --- LICENSE | 25 +++++++++++++++++++++++++ Yesod/Persist.hs | 39 +++++++++++++++++++++++++++++++++++++++ yesod-persistent.cabal | 25 +++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 LICENSE create mode 100644 Yesod/Persist.hs create mode 100644 yesod-persistent.cabal diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..8643e5d8 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/Yesod/Persist.hs b/Yesod/Persist.hs new file mode 100644 index 00000000..fc4a3685 --- /dev/null +++ b/Yesod/Persist.hs @@ -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 diff --git a/yesod-persistent.cabal b/yesod-persistent.cabal new file mode 100644 index 00000000..5628c942 --- /dev/null +++ b/yesod-persistent.cabal @@ -0,0 +1,25 @@ +name: yesod-persistent +version: 0.0.0 +license: BSD3 +license-file: LICENSE +author: Michael Snoyman +maintainer: Michael Snoyman +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 From 12ccd1d5c936be6b86edccc59e3a504ace69faeb Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Fri, 31 Dec 2010 00:58:28 +0200 Subject: [PATCH 3/9] runDB wraps around a GGHandler IO --- Yesod/Persist.hs | 4 ++-- yesod-persistent.cabal | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Yesod/Persist.hs b/Yesod/Persist.hs index fc4a3685..25239a3b 100644 --- a/Yesod/Persist.hs +++ b/Yesod/Persist.hs @@ -11,11 +11,11 @@ import Database.Persist import Control.Monad.Trans.Class (MonadTrans (..)) import Control.Failure (Failure) -import Yesod +import Yesod.Handler class YesodPersist y where type YesodDB y :: (* -> *) -> * -> * - runDB :: YesodDB y (GHandler sub y) a -> GHandler sub y a + 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), diff --git a/yesod-persistent.cabal b/yesod-persistent.cabal index 5628c942..40b80f1b 100644 --- a/yesod-persistent.cabal +++ b/yesod-persistent.cabal @@ -13,7 +13,7 @@ homepage: http://docs.yesodweb.com/ library build-depends: base >= 4 && < 5 - , yesod >= 0.7 && < 0.8 + , yesod-core >= 0.7 && < 0.8 , persistent >= 0.4 && < 0.5 , failure >= 0.1 && < 0.2 , transformers >= 0.2 && < 0.3 From e693cc1d8d831709c8e0339342145156c32da761 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Wed, 19 Jan 2011 23:51:20 +0200 Subject: [PATCH 4/9] Added missing Setup.lhs --- Setup.lhs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 Setup.lhs diff --git a/Setup.lhs b/Setup.lhs new file mode 100755 index 00000000..06e2708f --- /dev/null +++ b/Setup.lhs @@ -0,0 +1,7 @@ +#!/usr/bin/env runhaskell + +> module Main where +> import Distribution.Simple + +> main :: IO () +> main = defaultMain From efe638263de17cf7f0f87422ceebc14b65c2c1ce Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 15 Feb 2011 07:02:19 +0200 Subject: [PATCH 5/9] Version bumps --- yesod-persistent.cabal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yesod-persistent.cabal b/yesod-persistent.cabal index 40b80f1b..24856560 100644 --- a/yesod-persistent.cabal +++ b/yesod-persistent.cabal @@ -1,5 +1,5 @@ name: yesod-persistent -version: 0.0.0 +version: 0.0.0.1 license: BSD3 license-file: LICENSE author: Michael Snoyman @@ -14,7 +14,7 @@ homepage: http://docs.yesodweb.com/ library build-depends: base >= 4 && < 5 , yesod-core >= 0.7 && < 0.8 - , persistent >= 0.4 && < 0.5 + , persistent >= 0.4.1 && < 0.5 , failure >= 0.1 && < 0.2 , transformers >= 0.2 && < 0.3 exposed-modules: Yesod.Persist From 99de493b44cc3eff50f4c52c433afe1cc72deb33 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 5 Apr 2011 00:29:29 +0300 Subject: [PATCH 6/9] Yesod 0.8 --- yesod-persistent.cabal | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yesod-persistent.cabal b/yesod-persistent.cabal index 24856560..a508aaca 100644 --- a/yesod-persistent.cabal +++ b/yesod-persistent.cabal @@ -1,5 +1,5 @@ name: yesod-persistent -version: 0.0.0.1 +version: 0.1.0 license: BSD3 license-file: LICENSE author: Michael Snoyman @@ -13,8 +13,8 @@ homepage: http://docs.yesodweb.com/ library build-depends: base >= 4 && < 5 - , yesod-core >= 0.7 && < 0.8 - , persistent >= 0.4.1 && < 0.5 + , yesod-core >= 0.8 && < 0.9 + , persistent >= 0.5 && < 0.6 , failure >= 0.1 && < 0.2 , transformers >= 0.2 && < 0.3 exposed-modules: Yesod.Persist From 8f636e5be09319bcb751ef4ea059ebafe5669e82 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 7 Apr 2011 23:37:04 +0300 Subject: [PATCH 7/9] Export persistent-template --- Yesod/Persist.hs | 2 ++ yesod-persistent.cabal | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Yesod/Persist.hs b/Yesod/Persist.hs index 25239a3b..0eae7278 100644 --- a/Yesod/Persist.hs +++ b/Yesod/Persist.hs @@ -5,9 +5,11 @@ module Yesod.Persist , 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) diff --git a/yesod-persistent.cabal b/yesod-persistent.cabal index a508aaca..5b4cbad4 100644 --- a/yesod-persistent.cabal +++ b/yesod-persistent.cabal @@ -9,12 +9,13 @@ category: Web, Yesod, Database stability: Stable cabal-version: >= 1.6 build-type: Simple -homepage: http://docs.yesodweb.com/ +homepage: http://www.yesodweb.com/ library build-depends: base >= 4 && < 5 , yesod-core >= 0.8 && < 0.9 , persistent >= 0.5 && < 0.6 + , persistent-template >= 0.5 && < 0.6 , failure >= 0.1 && < 0.2 , transformers >= 0.2 && < 0.3 exposed-modules: Yesod.Persist From c43447185cb01befac2a67b3992b3e188db5f020 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Thu, 9 Jun 2011 20:20:38 +0400 Subject: [PATCH 8/9] Haddock comments --- Yesod/Persist.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Yesod/Persist.hs b/Yesod/Persist.hs index 0eae7278..d534a1cb 100644 --- a/Yesod/Persist.hs +++ b/Yesod/Persist.hs @@ -19,7 +19,7 @@ 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. +-- | 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 @@ -29,8 +29,8 @@ get404 key = do 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. +-- | 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) From 17e7ae34d400c8c0bc00a9caa2afe8d06653d7ad Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 19 Jul 2011 08:54:04 +0300 Subject: [PATCH 9/9] Version bumps --- yesod-persistent.cabal | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/yesod-persistent.cabal b/yesod-persistent.cabal index 5b4cbad4..54d6748f 100644 --- a/yesod-persistent.cabal +++ b/yesod-persistent.cabal @@ -1,5 +1,5 @@ name: yesod-persistent -version: 0.1.0 +version: 0.2.0 license: BSD3 license-file: LICENSE author: Michael Snoyman @@ -13,11 +13,12 @@ homepage: http://www.yesodweb.com/ library build-depends: base >= 4 && < 5 - , yesod-core >= 0.8 && < 0.9 - , persistent >= 0.5 && < 0.6 - , persistent-template >= 0.5 && < 0.6 + , 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