snaplet-postgresql-simple 0.4 → 0.4.1
raw patch · 3 files changed
+29/−11 lines, 3 filesdep ~snap
Dependency ranges changed: snap
Files
- snaplet-postgresql-simple.cabal +2/−2
- src/Snap/Snaplet/Auth/Backends/PostgresqlSimple.hs +6/−6
- src/Snap/Snaplet/PostgresqlSimple.hs +21/−3
snaplet-postgresql-simple.cabal view
@@ -1,5 +1,5 @@ name: snaplet-postgresql-simple-version: 0.4+version: 0.4.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@@ -44,7 +44,7 @@ mtl >= 2 && < 3, postgresql-simple >= 0.3 && < 0.4, resource-pool-catchio >= 0.2 && < 0.3,- snap >= 0.10 && < 0.13,+ snap >= 0.10 && < 0.14, text >= 0.11.2 && < 0.12, transformers >= 0.2 && < 0.4, unordered-containers >= 0.2 && < 0.3
src/Snap/Snaplet/Auth/Backends/PostgresqlSimple.hs view
@@ -8,7 +8,7 @@ in a PostgreSQL database. When you run your application with this snaplet, a config file will be copied into the the @snaplets/postgresql-auth@ directory. This file contains all of the configurable options for the snaplet and allows-you to change them without recompiling your application. +you to change them without recompiling your application. To use this snaplet in your application enable the session, postgres, and auth snaplets as follows:@@ -110,9 +110,9 @@ where schemaless = T.reverse . T.takeWhile (/='.') . T.reverse q = T.concat- [ "CREATE TABLE "+ [ "CREATE TABLE \"" , tblName pamTable- , " ("+ , "\" (" , T.intercalate "," (map (fDesc . ($pamTable) . (fst)) colDef) , ")" ]@@ -295,13 +295,13 @@ cols = map (fst . ($at) . fst) $ tail colDef vals = map (const "?") cols params = map (($u) . snd) $ tail colDef- + onFailure :: Monad m => E.SomeException -> m (Either AuthFailure a) onFailure e = return $ Left $ AuthError $ show e --------------------------------------------------------------------------------- | +-- | instance IAuthBackend PostgresAuthManager where save PostgresAuthManager{..} u@AuthUser{..} = do let (qstr, params) = saveQuery pamTable u@@ -310,7 +310,7 @@ res <- P.query conn q params return $ Right $ fromMaybe u $ listToMaybe res E.catch action onFailure- + lookupByUserId PostgresAuthManager{..} uid = do let q = Query $ T.encodeUtf8 $ T.concat
src/Snap/Snaplet/PostgresqlSimple.hs view
@@ -62,6 +62,8 @@ Postgres(..) , HasPostgres(..) , pgsInit+ , pgsInit'+ , getConnectionString -- * Wrappers and re-exports , query@@ -265,12 +267,31 @@ _ -> TB.singleton c +description :: T.Text+description = "PostgreSQL abstraction" ++datadir :: Maybe (IO FilePath)+datadir = Just $ liftM (++"/resources/db") getDataDir++ ------------------------------------------------------------------------------ -- | Initialize the snaplet pgsInit :: SnapletInit b Postgres pgsInit = makeSnaplet "postgresql-simple" description datadir $ do config <- getSnapletUserConfig+ initHelper config+++------------------------------------------------------------------------------+-- | Initialize the snaplet+pgsInit' :: C.Config -> SnapletInit b Postgres+pgsInit' config = makeSnaplet "postgresql-simple" description datadir $ do+ initHelper config+++initHelper :: MonadIO m => C.Config -> m Postgres+initHelper config = do connstr <- liftIO $ getConnectionString config stripes <- liftIO $ C.lookupDefault 1 config "numStripes" idle <- liftIO $ C.lookupDefault 5 config "idleTime"@@ -278,9 +299,6 @@ pool <- liftIO $ createPool (P.connectPostgreSQL connstr) P.close stripes (realToFrac (idle :: Double)) resources return $ Postgres pool- where- description = "PostgreSQL abstraction"- datadir = Just $ liftM (++"/resources/db") getDataDir ------------------------------------------------------------------------------