Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class IsCtx ctx where
- class ApiErr apiErr where
- data ErrResult = ErrResult Status Value
- data Rsp = Rsp {}
- rspGood :: ToJSON x => x -> Rsp
- rspBad :: ApiErr ae => ae -> Rsp
- rspBadCommit :: ApiErr ae => ae -> Rsp
- rspBadRollback :: ApiErr ae => ae -> Rsp
- rspGoodCSV :: ByteString -> Rsp
- rspGoodLBS :: ByteString -> ByteString -> Rsp
- rspEmptyGood :: Rsp
- pureRsp :: IsCtx ctx => ctx -> Rsp -> Snap ()
- inTransaction :: IsCtx ctx => ctx -> (Connection -> IO Rsp) -> Snap ()
- inTransaction_readOnly :: IsCtx ctx => ctx -> (Connection -> IO Rsp) -> Snap ()
- inTransaction_override :: IsCtx ctx => ctx -> (Connection -> IO Rsp) -> Snap ()
- inTransactionMode :: IsCtx ctx => ctx -> IsolationLevel -> ReadWriteMode -> (Connection -> IO Rsp) -> Snap ()
- rspIsGood :: Rsp -> Bool
- errorEarlyCode :: ApiErr ae => ae -> Snap x
- data RspPayload
- = ToJSON x => RspPayload_Good x
- | ApiErr e => RspPayload_Bad e
- | RspPayload_Custom Status ByteString ByteString
- | RspPayload_Empty
- data ShouldCommitOrRollback
Documentation
class IsCtx ctx where Source #
ctxConnectionPool :: ctx -> Pool Connection Source #
ctxGetReadOnlyMode :: ctx -> IO Bool Source #
ctx_wrapSuccess :: ToJSON x => ctx -> x -> Value Source #
ctx_err_inReadOnlyMode :: ctx -> ErrResult Source #
rspGood :: ToJSON x => x -> Rsp Source #
This means everything's succeeded. We should commit DB changes and return a success object
rspBad :: ApiErr ae => ae -> Rsp Source #
We should send back an error object and roll back DB changes
rspBadRollback :: ApiErr ae => ae -> Rsp Source #
The same as rspBad
but more explicit that we roll back
rspGoodCSV :: ByteString -> Rsp Source #
rspGoodLBS :: ByteString -> ByteString -> Rsp Source #
First Bytestring is the content type, e.g. "application/json" Here's a helpful list: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
rspEmptyGood :: Rsp Source #
Everything worked and we send a 200, but we don't have any data to send
pureRsp :: IsCtx ctx => ctx -> Rsp -> Snap () Source #
Sometimes you don't need a DB connection at all!
inTransaction :: IsCtx ctx => ctx -> (Connection -> IO Rsp) -> Snap () Source #
- If you hit the DB, use this function!*
This is a lot like withTransaction
, but it allows us to rollback if we
want, without throwing an error.
(Don't use withTransaction
!)
NOTE this is for IO actions, not Snap actions. This is to ensure we can't
call e.g. finishEarly
and never hit the 'end transaction' code!
(It also has the side benefit of keeping code fairly framework-agnostic)
inTransaction_readOnly :: IsCtx ctx => ctx -> (Connection -> IO Rsp) -> Snap () Source #
An endpoint that uses inTransaction_readOnly
will keep responding even
when the server is in read-only mode.
Note that you the programmer are asserting the DB queries are read-only. There's nothing in this library or in postgresql-simple which statically checks that to be true!
inTransaction_override :: IsCtx ctx => ctx -> (Connection -> IO Rsp) -> Snap () Source #
YOU SHOULD ONLY USE THIS ONCE
This lets you do a write transaction during read-only mode (not a
read-only transaction! A time where ctxGetReadOnlyMode
would return
True)
You may need this so that an admin user can take the app out of read-only mode
inTransactionMode :: IsCtx ctx => ctx -> IsolationLevel -> ReadWriteMode -> (Connection -> IO Rsp) -> Snap () Source #
errorEarlyCode :: ApiErr ae => ae -> Snap x Source #
NOTE: be very careful to not use this with any setup/teardown block like withTransaction
- causes resource leaks
- BUT! This should never happen to you because all your DB code should
use inTransaction
!
NOTE: use 403 forbidden instead of unauthorized - unauth means not logged in at all
Also note this returns any 'Snap x' so you can use it like a throw anywhere in your snap code
data RspPayload Source #
data ShouldCommitOrRollback Source #
Instances
Eq ShouldCommitOrRollback Source # | |
Defined in Gingersnap.Core | |
Show ShouldCommitOrRollback Source # | |
Defined in Gingersnap.Core showsPrec :: Int -> ShouldCommitOrRollback -> ShowS # show :: ShouldCommitOrRollback -> String # showList :: [ShouldCommitOrRollback] -> ShowS # |