beam-core-0.10.0.0: Type-safe, feature-complete SQL query and manipulation interface for Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Database.Beam.Query.CTE

Synopsis

Documentation

newtype With be (db :: (Type -> Type) -> Type) a Source #

Monad in which SELECT statements can be made (via selecting) and bound to result names for re-use later. This has the advantage of only computing each result once. In SQL, this is translated to a common table expression.

Once introduced, results can be re-used in future queries with reuse.

With is also a member of MonadFix for backends that support recursive CTEs. In this case, you can use mdo or rec notation (with RecursiveDo enabled) to bind result values (again, using reuse) even before they're introduced.

See further documentation here.

Constructors

With 

Instances

Instances details
IsSql99RecursiveCommonTableExpressionSelectSyntax (BeamSqlBackendSelectSyntax be) => MonadFix (With be db) Source # 
Instance details

Defined in Database.Beam.Query.CTE

Methods

mfix :: (a -> With be db a) -> With be db a #

Applicative (With be db) Source # 
Instance details

Defined in Database.Beam.Query.CTE

Methods

pure :: a -> With be db a #

(<*>) :: With be db (a -> b) -> With be db a -> With be db b #

liftA2 :: (a -> b -> c) -> With be db a -> With be db b -> With be db c #

(*>) :: With be db a -> With be db b -> With be db b #

(<*) :: With be db a -> With be db b -> With be db a #

Functor (With be db) Source # 
Instance details

Defined in Database.Beam.Query.CTE

Methods

fmap :: (a -> b) -> With be db a -> With be db b #

(<$) :: a -> With be db b -> With be db a #

Monad (With be db) Source # 
Instance details

Defined in Database.Beam.Query.CTE

Methods

(>>=) :: With be db a -> (a -> With be db b) -> With be db b #

(>>) :: With be db a -> With be db b -> With be db b #

return :: a -> With be db a #

data ReusableQ be db res where Source #

Query results that have been introduced into a common table expression via selecting that can be used in future queries with reuse.

Constructors

ReusableQ :: Proxy res -> (forall s. Proxy s -> Q be db s (WithRewrittenThread QAnyScope s res)) -> ReusableQ be db res 

reusableForCTE :: forall be res db. (ThreadRewritable QAnyScope res, Projectible be res, BeamSqlBackend be) => Text -> ReusableQ be db res Source #

selecting :: forall res be db. (BeamSql99CommonTableExpressionBackend be, HasQBuilder be, Projectible be res, ThreadRewritable QAnyScope res) => Q be db QAnyScope res -> With be db (ReusableQ be db res) Source #

Introduce the result of a query as a result in a common table expression. The returned value can be used in future queries by applying reuse.

reuse :: forall s be db res. ReusableQ be db res -> Q be db s (WithRewrittenThread QAnyScope s res) Source #

Introduces the result of a previous selecting (a CTE) into a new query