gingersnap 0.1.4.0 → 0.1.4.1
raw patch · 3 files changed
+19/−10 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +4/−4
- gingersnap.cabal +1/−1
- src/Gingersnap/Core.hs +14/−5
README.md view
@@ -19,7 +19,7 @@ {-# LANGUAGE DeriveGeneric, OverloadedStrings #-} import Data.Aeson (ToJSON)-import qualified Database.PostgreSQL.Simple as PSQL+import Database.PostgreSQL.Simple -- For our automatic JSON instance: import GHC.Generics (Generic) import Gingersnap.Core@@ -105,7 +105,7 @@ So let's define our own! We unimaginitavely call it "Ctx": ```haskell-data Ctx = Ctx { ctx_db :: Pool PSQL.Connection }+data Ctx = Ctx { ctx_db :: Pool Connection } instance IsCtx Ctx where ctxConnectionPool = ctx_db@@ -119,7 +119,7 @@ -- Setting up the DB connection pool: let connString = " host=localhost port=5432 dbname=postgres user=postgres "- pool <- createPool (PSQL.connectPostgreSQL connString) PSQL.close 1 5 20+ pool <- createPool (connectPostgreSQL connString) close 1 5 20 pure $ Ctx { ctx_db = pool } ```@@ -135,7 +135,7 @@ two :: Ctx -> Snap () two ctx = do inTransaction ctx $ \conn -> do- [PSQL.Only x] <- PSQL.query_ conn " SELECT 2 + 2 "+ [Only x] <- query_ conn " SELECT 2 + 2 " pure $ rspGood $ SomeData x True ```
gingersnap.cabal view
@@ -1,5 +1,5 @@ name: gingersnap-version: 0.1.4.0+version: 0.1.4.1 synopsis: snap-core + aeson + postgresql-simple = delicious description: JSON API idioms for snap-core, preventing DB connection leaks.
src/Gingersnap/Core.hs view
@@ -7,11 +7,8 @@ #-} module Gingersnap.Core (- IsCtx(..)- , ApiErr(..)- , ErrResult(..)-- , Rsp(..)+ -- * Rsp+ Rsp(..) , rspGood , rspBad@@ -21,16 +18,26 @@ , rspGoodLBS , rspEmptyGood + -- * pureRsp , pureRsp + -- * DB Transactions , inTransaction , inTransaction_readOnly , inTransaction_override , inTransactionMode , rspIsGood + -- * IsCtx+ , IsCtx(..)++ -- * Errors+ , ApiErr(..)+ , ErrResult(..)+ , errorEarlyCode + -- * Internals -- These won't typically be inspected by hand but there's no reason we should -- block people from inspecting them if they like , RspPayload(..)@@ -107,6 +114,8 @@ , "errorMessage" .= JSON.String "This action is unavailable in read-only mode" ] +-- | How we construct responses. You probably don't want to be constructing or+-- inspecting them by hand; instead you can use 'rspGood', 'rspBadRollback', etc. data Rsp = Rsp { rspShouldCommit :: ShouldCommitOrRollback