packages feed

snaplet-postgresql-simple 0.1 → 0.1.1

raw patch · 2 files changed

+34/−13 lines, 2 filesdep ~postgresql-simple

Dependency ranges changed: postgresql-simple

Files

snaplet-postgresql-simple.cabal view
@@ -1,5 +1,5 @@ name:           snaplet-postgresql-simple-version:        0.1+version:        0.1.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@@ -12,7 +12,7 @@ build-type:     Simple cabal-version:  >= 1.6 homepage:       https://github.com/mightybyte/snaplet-postgresql-simple-category:       Web+category:       Web, Snap  extra-source-files:  LICENSE @@ -41,7 +41,7 @@     configurator               >= 0.2     && < 0.3,     MonadCatchIO-transformers  >= 0.3     && < 0.4,     mtl                        >= 2       && < 3,-    postgresql-simple          >= 0.1     && < 0.2,+    postgresql-simple          >= 0.1     && < 0.3,     resource-pool-catchio      >= 0.2     && < 0.3,     snap                       >= 0.9     && < 0.10,     text                       >= 0.11    && < 0.12,
src/Snap/Snaplet/PostgresqlSimple.hs view
@@ -6,8 +6,9 @@  This snaplet makes it simple to use a PostgreSQL database from your Snap application and is based on the excellent postgresql-simple library-(<http://hackage.haskell.org/package/postgresql-simple>) by Bryan O'Sullivan.-Now, adding a database to your web app takes just two simple steps.+(<http://hackage.haskell.org/package/postgresql-simple>) by Leon Smith+(adapted from Bryan O\'Sullivan\'s mysql-simple).  Now, adding a database+to your web app takes just two simple steps.  First, include this snaplet in your application's state. @@ -44,10 +45,10 @@ >     ...  The first time you run an application with the postgresql-simple snaplet, a-configuration file @snaplet.cfg@ in the @snaplets/postgresql-simple@ directory-underneath your project root.  It specifies how to connect to your PostgreSQL-server and what user, password, and database to use.  Edit this file and modify-the values appropriately and you'll be off and running.+configuration file @devel.cfg@ is created in the @snaplets/postgresql-simple@+directory underneath your project root.  It specifies how to connect to your+PostgreSQL server and what user, password, and database to use.  Edit this+file and modify the values appropriately and you'll be off and running.  If you want to have out-of-the-box authentication, look at the documentation for the "Snap.Snaplet.Auth.Backends.PostgresqlSimple" module.@@ -96,6 +97,7 @@   , P.TransactionMode(..)   , P.IsolationLevel(..)   , P.ReadWriteMode(..)+  , (P.:.)(..)   , ToRow(..)   , FromRow(..) @@ -103,6 +105,7 @@   , P.defaultTransactionMode   , P.defaultIsolationLevel   , P.defaultReadWriteMode+  , field    ) where @@ -112,6 +115,7 @@ import           Control.Monad.CatchIO hiding (Handler) import           Control.Monad.IO.Class import           Control.Monad.State+import           Control.Monad.Trans.Reader import           Control.Monad.Trans.Writer import           Data.ByteString (ByteString) import qualified Data.Configurator as C@@ -122,7 +126,7 @@ import           Database.PostgreSQL.Simple.ToRow import           Database.PostgreSQL.Simple.FromRow import qualified Database.PostgreSQL.Simple as P-import           Snap.Snaplet+import           Snap import           Paths_snaplet_postgresql_simple  @@ -138,7 +142,10 @@  ------------------------------------------------------------------------------ -- | Instantiate this typeclass on 'Handler b YourAppState' so this snaplet--- can find the connection source.+-- can find the connection source.  If you need to have multiple instances of+-- the postgres snaplet in your application, then don't provide this instance+-- and leverage the default instance by using \"@with dbLens@\" in front of calls+-- to snaplet-postgresql-simple functions. class (MonadCatchIO m) => HasPostgres m where     getPostgresState :: m Postgres @@ -149,6 +156,19 @@     getPostgresState = get  +------------------------------------------------------------------------------+-- | A convenience instance to make it easier to use this snaplet in monads+-- other than Handler.  It allows you to get database access in initializers+-- like this:+--+-- > d <- nestSnaplet "db" db pgsInit+-- > count <- liftIO $ runReaderT (execute "INSERT ..." params) d+instance (MonadCatchIO m) => HasPostgres (ReaderT (Snaplet Postgres) m) where+    getPostgresState = asks (getL snapletValue)+++------------------------------------------------------------------------------+-- | Convenience function allowing easy collection of config file errors. logErr :: MonadIO m        => t -> IO (Maybe a) -> WriterT [t] m (Maybe a) logErr err m = do@@ -156,6 +176,7 @@     when (isNothing res) (tell [err])     return res + ------------------------------------------------------------------------------ -- | Initialize the snaplet pgsInit :: SnapletInit b Postgres@@ -323,8 +344,8 @@  withTransactionLevel :: (HasPostgres m, MonadCatchIO m)                      => P.IsolationLevel -> m a -> m a-withTransactionLevel lvl-    = withTransactionMode P.defaultTransactionMode { P.isolationLevel = lvl }+withTransactionLevel lvl =+    withTransactionMode P.defaultTransactionMode { P.isolationLevel = lvl }   withTransactionMode :: (HasPostgres m, MonadCatchIO m)