Permalink
Browse files

Work in progress

  • Loading branch information...
0 parents commit 4a6ec6af1191c26cc9345bd1bd07344f70700288 @mightybyte committed Mar 8, 2012
Showing with 115 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +27 −0 LICENSE
  3. 0 README
  4. +3 −0 Setup.hs
  5. +39 −0 snaplet-postgresql-simple.cabal
  6. +44 −0 src/Snap/Snaplet/PostgresqlSimple.hs
2 .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+dist/
27 LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2012, Doug Beardsley
+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 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.
0 README
No changes.
3 Setup.hs
@@ -0,0 +1,3 @@
+import Distribution.Simple
+
+main = defaultMain
39 snaplet-postgresql-simple.cabal
@@ -0,0 +1,39 @@
+name: snaplet-postgresql-simple
+version: 0.1
+synopsis: postgresql-simple snaplet for the Snap Framework
+description: This snaplet contains support for using the Postgresql
+ database with a Snap Framework application via the
+ postgresql-simple package. It also includes an
+ authentication backend.
+license: BSD3
+license-file: LICENSE
+author: Doug Beardsley
+maintainer: mightybyte@gmail.com
+build-type: Simple
+cabal-version: >= 1.6
+homepage: https://github.com/mightybyte/snaplet-postgresql-simple
+category: Web
+
+extra-source-files: LICENSE
+
+source-repository head
+ type: git
+ location: https://github.com/mightybyte/snaplet-postgresql-simple.git
+
+Library
+ hs-source-dirs: src
+
+ exposed-modules:
+ Snap.Snaplet.PostgresqlSimple
+
+ build-depends:
+ base >= 4 && < 5,
+ MonadCatchIO-transformers >= 0.2.1 && < 0.3,
+ postgresql-simple >= 0.0 && < 0.1,
+ resource-pool-catchio >= 0.2 && < 0.3,
+ snap >= 0.6 && < 0.9,
+ text >= 0.11 && < 0.12,
+ transformers >= 0.2 && < 0.3
+
+ ghc-options: -Wall -fwarn-tabs -funbox-strict-fields
+ -fno-warn-orphans -fno-warn-unused-do-bind
44 src/Snap/Snaplet/PostgresqlSimple.hs
@@ -0,0 +1,44 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Snap.Snaplet.PostgresqlSimple
+ ( Postgresql
+ , HasPostgres(..)
+ , pgsInit
+ ) where
+
+import Prelude hiding (catch)
+
+import Control.Exception (SomeException)
+import Control.Monad.CatchIO
+import Control.Monad.IO.Class
+import Data.Pool
+import Database.PostgreSQL.Simple
+import Snap.Snaplet
+
+
+------------------------------------------------------------------------------
+-- |
+data Postgres = Postgres
+ { pgConnection :: Pool Connection
+ }
+
+
+------------------------------------------------------------------------------
+-- | Instantiate this typeclass on 'Handler b YourSnapletState' so this snaplet
+-- can find the connection source.
+class HasPostgres m where
+ getPostgresState :: m Postgres
+
+
+description :: Text
+description = "PostgreSQL abstraction"
+
+
+------------------------------------------------------------------------------
+-- | Initialise the snaplet
+pgsInit :: ConnectInfo -> SnapletInit b Postgres
+pgsInit ci = makeSnaplet "postgresql-simple" description Nothing $ do
+ pool <- createPool (connect ci) close 1 5 20
+ return $ Postgres pool
+
+

0 comments on commit 4a6ec6a

Please sign in to comment.