tsweb-0.1.2: An API binding Web.Spock to Database.Beam

Safe HaskellNone
LanguageHaskell2010

TsWeb.Db

Description

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

Documentation

data TxOpt Source #

Transaction option: provide WithTx to wrap operations in BEGIN/COMMIT, or NoTx to skip that.

Constructors

NoTx 
WithTx 
Instances
Bounded TxOpt Source # 
Instance details

Defined in TsWeb.Db

Enum TxOpt Source # 
Instance details

Defined in TsWeb.Db

Eq TxOpt Source # 
Instance details

Defined in TsWeb.Db

Methods

(==) :: TxOpt -> TxOpt -> Bool #

(/=) :: TxOpt -> TxOpt -> Bool #

Ord TxOpt Source # 
Instance details

Defined in TsWeb.Db

Methods

compare :: TxOpt -> TxOpt -> Ordering #

(<) :: TxOpt -> TxOpt -> Bool #

(<=) :: TxOpt -> TxOpt -> Bool #

(>) :: TxOpt -> TxOpt -> Bool #

(>=) :: TxOpt -> TxOpt -> Bool #

max :: TxOpt -> TxOpt -> TxOpt #

min :: TxOpt -> TxOpt -> TxOpt #

Show TxOpt Source # 
Instance details

Defined in TsWeb.Db

Methods

showsPrec :: Int -> TxOpt -> ShowS #

show :: TxOpt -> String #

showList :: [TxOpt] -> ShowS #

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).

Constructors

QSimply a 
QError SqlError 
Instances
Eq a => Eq (QueryResult a) Source # 
Instance details

Defined in TsWeb.Db

Show a => Show (QueryResult a) Source # 
Instance details

Defined in TsWeb.Db

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 # 
Instance details

Defined in TsWeb.Db

Methods

(==) :: ExecResult a -> ExecResult a -> Bool #

(/=) :: ExecResult a -> ExecResult a -> Bool #

Show a => Show (ExecResult a) Source # 
Instance details

Defined in TsWeb.Db

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