Safe Haskell | None |
---|---|
Language | Haskell2010 |
This builds on TsWeb.Types.Db's read-only/read-write discrimination by
providing query functions to perform read-only operations, and an execute
function to run updates, inserts, and deletes (and also selects as
appropriate). All of these are performed as TsActionCtxT
actions
so as to nicely integrate with Spock. Finally, because I'm not a fan of
exceptions, all of these functions trap Postgres errors and convert them into
sum-type results.
I'm not yet providing shortcuts for the beam-postgres specific functions. I'm not actually sure that I need to (IIRC they all build Pg actions), but I will be adding them if necessary.
Synopsis
- data TxOpt
- data QueryResult a
- data ExecResult a
- query :: ListContains n ReadOnlyPool xs => TxOpt -> RoPg a -> TsActionCtxT lts xs sessdata (QueryResult a)
- queryMaybe :: (ListContains n ReadOnlyPool xs, FromBackendRow Postgres a) => Sel a -> TsActionCtxT lts xs sessdata (QueryResult (Maybe a))
- queryList :: (ListContains n ReadOnlyPool xs, FromBackendRow Postgres a) => Sel a -> TsActionCtxT lts xs sessdata (QueryResult [a])
- execute :: ListContains n ReadWritePool xs => TxOpt -> Pg a -> TsActionCtxT lts xs sessdata (ExecResult a)
Documentation
Transaction option: provide WithTx to wrap operations in BEGIN/COMMIT, or NoTx to skip that.
data QueryResult a Source #
Result of a select operation. This will either succeed with a QSimply, or fail with a QError (probably then an error in the db connection or table definitions).
Instances
Eq a => Eq (QueryResult a) Source # | |
Defined in TsWeb.Db (==) :: QueryResult a -> QueryResult a -> Bool # (/=) :: QueryResult a -> QueryResult a -> Bool # | |
Show a => Show (QueryResult a) Source # | |
Defined in TsWeb.Db showsPrec :: Int -> QueryResult a -> ShowS # show :: QueryResult a -> String # showList :: [QueryResult a] -> ShowS # |
data ExecResult a Source #
The result of a select, insert, update, or delete operation. This adds a
constraint error to the QueryResult
, making it nicer to filter out
conflicts when handling errors.
Instances
Eq a => Eq (ExecResult a) Source # | |
Defined in TsWeb.Db (==) :: ExecResult a -> ExecResult a -> Bool # (/=) :: ExecResult a -> ExecResult a -> Bool # | |
Show a => Show (ExecResult a) Source # | |
Defined in TsWeb.Db showsPrec :: Int -> ExecResult a -> ShowS # show :: ExecResult a -> String # showList :: [ExecResult a] -> ShowS # |
query :: ListContains n ReadOnlyPool xs => TxOpt -> RoPg a -> TsActionCtxT lts xs sessdata (QueryResult a) Source #
Run one or many Beam runSelectReturningList
or
runSelectReturningOne
operation(s) against a view's
ReadOnlyPool.
queryMaybe :: (ListContains n ReadOnlyPool xs, FromBackendRow Postgres a) => Sel a -> TsActionCtxT lts xs sessdata (QueryResult (Maybe a)) Source #
Run a single Beam select
, returning a single (Maybe) value
queryList :: (ListContains n ReadOnlyPool xs, FromBackendRow Postgres a) => Sel a -> TsActionCtxT lts xs sessdata (QueryResult [a]) Source #
Run a single Beam select
, returning a list of values
execute :: ListContains n ReadWritePool xs => TxOpt -> Pg a -> TsActionCtxT lts xs sessdata (ExecResult a) Source #
Run any arbitrary Pg
monad in the context of a view,
returning an ExecResult