snaplet-haxl (empty) → 0.0.0.1
raw patch · 4 files changed
+103/−0 lines, 4 filesdep +MonadCatchIO-transformersdep +asyncdep +basesetup-changed
Dependencies added: MonadCatchIO-transformers, async, base, hashable, haxl, mtl, postgresql-simple, snap, text, transformers
Files
- LICENSE +27/−0
- Setup.hs +2/−0
- snaplet-haxl.cabal +39/−0
- src/Snap/Snaplet/Haxl.hs +35/−0
+ LICENSE view
@@ -0,0 +1,27 @@+Copyright (c) 2014, Snaplet-Haxl authors (see CONTRIBUTORS)+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.++Neither the name of the Snaplet-Haxl authors nor the names of its+contributors may be used to endorse or promote products derived from this+software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 HOLDER OR CONTRIBUTORS 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ snaplet-haxl.cabal view
@@ -0,0 +1,39 @@+-- Initial snaplet-haxl.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++name: snaplet-haxl+version: 0.0.0.1+synopsis: Snaplet for Facebook's Haxl+description: A Snaplet for the integration of Haxl DataSources with Snap.+homepage: https://github.com/ChristopherBiscardi/snaplet-haxl+license: BSD3+license-file: LICENSE+author: Christopher Biscardi+maintainer: chris@christopherbiscardi.com+category: Web, Snap+build-type: Simple+-- extra-source-files: +cabal-version: >=1.10++library+ exposed-modules:+ Snap.Snaplet.Haxl+ -- other-modules: + -- other-extensions: + build-depends:+ base >= 4.6 && <4.7,+ haxl >= 0.1.0.0 && < 0.2.0.0,+ text >= 1.1.1.3,+ hashable >= 1.2.2.0,+ postgresql-simple >= 0.4.2.2,+ async >= 2.0.1.4,+ snap >= 0.10,+ MonadCatchIO-transformers >= 0.3.1.1,+ transformers >= 0.3.0.0,+ mtl >= 2.1.2+ hs-source-dirs: src+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/ChristopherBiscardi/snaplet-haxl.git
+ src/Snap/Snaplet/Haxl.hs view
@@ -0,0 +1,35 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE OverloadedStrings #-}++module Snap.Snaplet.Haxl+ (haxlInit+ ,withHaxl+ ,HaxlEnv(..)+ ,HasHaxl(..)) where++import Control.Monad.CatchIO (MonadCatchIO)+import Control.Monad.Trans.Reader (ReaderT, ask)+import Haxl.Core+import qualified Haxl.Core.Env as E+import Snap++data HaxlEnv u = HaxlEnv {en :: E.Env u}++class (MonadCatchIO m) => HasHaxl m where+ getHaxlState :: m (HaxlEnv ())++instance HasHaxl (Handler b (HaxlEnv ())) where+ getHaxlState = get++instance (MonadCatchIO m) => HasHaxl (ReaderT (HaxlEnv ()) m) where+ getHaxlState = ask+++haxlInit :: E.Env e -> SnapletInit b (HaxlEnv e)+haxlInit e = makeSnaplet "haxl" "Simple Haxl Snaplet" Nothing $ do+ return $ HaxlEnv e++withHaxl :: (HasHaxl m) => GenHaxl () b -> m (b)+withHaxl f = do+ envir <- getHaxlState+ liftIO $ runHaxl (en envir) $ do f