{-# LANGUAGE CPP #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE CPP #-}

module Database.Beam.Query.Combinators
    ( -- * Various SQL functions and constructs
      coalesce_, fromMaybe_, position_
    , charLength_, octetLength_, bitLength_
    , currentTimestamp_
    , lower_, upper_
    , trim_

    -- ** @IF-THEN-ELSE@ support
    , if_, then_, else_
    , then_'
    , ifThenElse_, bool_

    -- * SQL @UPDATE@ assignments
    , (<-.), current_

    -- * Project Haskell values to 'QGenExpr's
    , HaskellLiteralForQExpr
    , SqlValable(..), SqlValableTable
    , default_

    -- * General query combinators

    , all_, values_
    , allFromView_, join_, join_'
    , guard_, guard_', filter_, filter_'
    , related_, relatedBy_, relatedBy_'
    , leftJoin_, leftJoin_'
    , perhaps_, outerJoin_, outerJoin_'
    , subselect_, references_, references_'

    , nub_

    , SqlJustable(..)
    , SqlDeconstructMaybe(..)
    , SqlOrderable
    , QIfCond, QIfElse
    , (<|>.)

    , limit_, offset_

    , as_

    -- ** Subqueries
    , exists_, unique_, distinct_, subquery_

    -- ** Set operations
    -- |  'Q' values can be combined using a variety of set operations. See the
    --    <https://haskell-beam.github.io/beam/user-guide/queries/combining-queries manual section>.
    , union_, unionAll_
    , intersect_, intersectAll_
    , except_, exceptAll_

    -- * Window functions
    -- | See the corresponding
    --   <https://haskell-beam.github.io/beam/user-guide/queries/window-functions manual section> for more.
    , over_, frame_, bounds_, unbounded_, nrows_, fromBound_
    , noBounds_, noOrder_, noPartition_
    , partitionBy_, orderPartitionBy_, withWindow_

    -- * Ordering primitives
    , orderBy_, asc_, desc_, nullsFirst_, nullsLast_
    ) where

import Database.Beam.Backend.Types
import Database.Beam.Backend.SQL

import Database.Beam.Query.Internal
import Database.Beam.Query.Ord
import Database.Beam.Query.Operator
import Database.Beam.Query.Types

import Database.Beam.Schema.Tables

import Control.Monad.Identity
import Control.Monad.Free
import Control.Applicative

import Data.Maybe
import Data.Proxy
import Data.Time (LocalTime)

import GHC.TypeLits (TypeError, ErrorMessage(Text))

-- | Introduce all entries of a table into the 'Q' monad
all_ :: ( Database be db, BeamSqlBackend be )
       => DatabaseEntity be db (TableEntity table)
       -> Q be db s (table (QExpr be s))
all_ :: DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ (DatabaseEntity dt :: DatabaseEntityDescriptor be (TableEntity table)
dt@(DatabaseTable {})) =
    QM be db s (table (QExpr be s)) -> Q be db s (table (QExpr be s))
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QM be db s (table (QExpr be s)) -> Q be db s (table (QExpr be s)))
-> QM be db s (table (QExpr be s))
-> Q be db s (table (QExpr be s))
forall a b. (a -> b) -> a -> b
$ QF be db s (table (QExpr be s)) -> QM be db s (table (QExpr be s))
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((TablePrefix -> TablePrefix -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> table (QExpr be s))
-> (table (QExpr be s)
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> ((TablePrefix, table (QExpr be s)) -> table (QExpr be s))
-> QF be db s (table (QExpr be s))
forall be r next (db :: (* -> *) -> *) s.
Projectible be r =>
(TablePrefix -> TablePrefix -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> r)
-> (r
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> ((TablePrefix, r) -> next)
-> QF be db s next
QAll (\TablePrefix
_ -> Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be)
-> Maybe (TablePrefix, Maybe [TablePrefix])
-> BeamSqlBackendFromSyntax be
forall from.
IsSql92FromSyntax from =>
Sql92FromTableSourceSyntax from
-> Maybe (TablePrefix, Maybe [TablePrefix]) -> from
fromTable (Sql92TableSourceTableNameSyntax
  (Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be))
-> Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be)
forall tblSource.
IsSql92TableSourceSyntax tblSource =>
Sql92TableSourceTableNameSyntax tblSource -> tblSource
tableNamed (Maybe TablePrefix
-> TablePrefix
-> Sql92TableSourceTableNameSyntax
     (Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be))
forall tblName.
IsSql92TableNameSyntax tblName =>
Maybe TablePrefix -> TablePrefix -> tblName
tableName (DatabaseEntityDescriptor be (TableEntity table)
-> Maybe TablePrefix
forall be (tbl :: (* -> *) -> *).
DatabaseEntityDescriptor be (TableEntity tbl) -> Maybe TablePrefix
dbTableSchema DatabaseEntityDescriptor be (TableEntity table)
dt) (DatabaseEntityDescriptor be (TableEntity table) -> TablePrefix
forall be (tbl :: (* -> *) -> *).
DatabaseEntityDescriptor be (TableEntity tbl) -> TablePrefix
dbTableCurrentName DatabaseEntityDescriptor be (TableEntity table)
dt))) (Maybe (TablePrefix, Maybe [TablePrefix])
 -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> Maybe (TablePrefix, Maybe [TablePrefix]))
-> TablePrefix
-> BeamSqlBackendFromSyntax be
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TablePrefix, Maybe [TablePrefix])
-> Maybe (TablePrefix, Maybe [TablePrefix])
forall a. a -> Maybe a
Just ((TablePrefix, Maybe [TablePrefix])
 -> Maybe (TablePrefix, Maybe [TablePrefix]))
-> (TablePrefix -> (TablePrefix, Maybe [TablePrefix]))
-> TablePrefix
-> Maybe (TablePrefix, Maybe [TablePrefix])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,Maybe [TablePrefix]
forall a. Maybe a
Nothing))
                    (TableSettings table -> TablePrefix -> table (QExpr be s)
forall be (table :: (* -> *) -> *) ctxt s.
(BeamSqlBackend be, Beamable table) =>
TableSettings table -> TablePrefix -> table (QGenExpr ctxt be s)
tableFieldsToExpressions (DatabaseEntityDescriptor be (TableEntity table)
-> TableSettings table
forall be (tbl :: (* -> *) -> *).
DatabaseEntityDescriptor be (TableEntity tbl) -> TableSettings tbl
dbTableSettings DatabaseEntityDescriptor be (TableEntity table)
dt))
                    (\table (QExpr be s)
_ -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be))
forall a. Maybe a
Nothing) (TablePrefix, table (QExpr be s)) -> table (QExpr be s)
forall a b. (a, b) -> b
snd)

-- | Introduce all entries of a view into the 'Q' monad
allFromView_ :: ( Database be db, Beamable table
                , BeamSqlBackend be )
               => DatabaseEntity be db (ViewEntity table)
               -> Q be db s (table (QExpr be s))
allFromView_ :: DatabaseEntity be db (ViewEntity table)
-> Q be db s (table (QExpr be s))
allFromView_ (DatabaseEntity DatabaseEntityDescriptor be (ViewEntity table)
vw) =
    QM be db s (table (QExpr be s)) -> Q be db s (table (QExpr be s))
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QM be db s (table (QExpr be s)) -> Q be db s (table (QExpr be s)))
-> QM be db s (table (QExpr be s))
-> Q be db s (table (QExpr be s))
forall a b. (a -> b) -> a -> b
$ QF be db s (table (QExpr be s)) -> QM be db s (table (QExpr be s))
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((TablePrefix -> TablePrefix -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> table (QExpr be s))
-> (table (QExpr be s)
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> ((TablePrefix, table (QExpr be s)) -> table (QExpr be s))
-> QF be db s (table (QExpr be s))
forall be r next (db :: (* -> *) -> *) s.
Projectible be r =>
(TablePrefix -> TablePrefix -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> r)
-> (r
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> ((TablePrefix, r) -> next)
-> QF be db s next
QAll (\TablePrefix
_ -> Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be)
-> Maybe (TablePrefix, Maybe [TablePrefix])
-> BeamSqlBackendFromSyntax be
forall from.
IsSql92FromSyntax from =>
Sql92FromTableSourceSyntax from
-> Maybe (TablePrefix, Maybe [TablePrefix]) -> from
fromTable (Sql92TableSourceTableNameSyntax
  (Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be))
-> Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be)
forall tblSource.
IsSql92TableSourceSyntax tblSource =>
Sql92TableSourceTableNameSyntax tblSource -> tblSource
tableNamed (Maybe TablePrefix
-> TablePrefix
-> Sql92TableSourceTableNameSyntax
     (Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be))
forall tblName.
IsSql92TableNameSyntax tblName =>
Maybe TablePrefix -> TablePrefix -> tblName
tableName (DatabaseEntityDescriptor be (ViewEntity table) -> Maybe TablePrefix
forall be (tbl :: (* -> *) -> *).
DatabaseEntityDescriptor be (ViewEntity tbl) -> Maybe TablePrefix
dbViewSchema DatabaseEntityDescriptor be (ViewEntity table)
vw) (DatabaseEntityDescriptor be (ViewEntity table) -> TablePrefix
forall be (tbl :: (* -> *) -> *).
DatabaseEntityDescriptor be (ViewEntity tbl) -> TablePrefix
dbViewCurrentName DatabaseEntityDescriptor be (ViewEntity table)
vw))) (Maybe (TablePrefix, Maybe [TablePrefix])
 -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> Maybe (TablePrefix, Maybe [TablePrefix]))
-> TablePrefix
-> BeamSqlBackendFromSyntax be
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TablePrefix, Maybe [TablePrefix])
-> Maybe (TablePrefix, Maybe [TablePrefix])
forall a. a -> Maybe a
Just ((TablePrefix, Maybe [TablePrefix])
 -> Maybe (TablePrefix, Maybe [TablePrefix]))
-> (TablePrefix -> (TablePrefix, Maybe [TablePrefix]))
-> TablePrefix
-> Maybe (TablePrefix, Maybe [TablePrefix])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,Maybe [TablePrefix]
forall a. Maybe a
Nothing))
                    (TableSettings table -> TablePrefix -> table (QExpr be s)
forall be (table :: (* -> *) -> *) ctxt s.
(BeamSqlBackend be, Beamable table) =>
TableSettings table -> TablePrefix -> table (QGenExpr ctxt be s)
tableFieldsToExpressions (DatabaseEntityDescriptor be (ViewEntity table)
-> TableSettings table
forall be (tbl :: (* -> *) -> *).
DatabaseEntityDescriptor be (ViewEntity tbl) -> TableSettings tbl
dbViewSettings DatabaseEntityDescriptor be (ViewEntity table)
vw))
                    (\table (QExpr be s)
_ -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be))
forall a. Maybe a
Nothing) (TablePrefix, table (QExpr be s)) -> table (QExpr be s)
forall a b. (a, b) -> b
snd)

-- | SQL @VALUES@ clause. Introduce the elements of the given list as
-- rows in a joined table.
values_ :: forall be db s a
         . ( Projectible be a
           , BeamSqlBackend be )
        => [ a ] -> Q be db s a
values_ :: [a] -> Q be db s a
values_ [a]
rows =
    QM be db s a -> Q be db s a
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QM be db s a -> Q be db s a) -> QM be db s a -> Q be db s a
forall a b. (a -> b) -> a -> b
$ QF be db s a -> QM be db s a
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((TablePrefix -> TablePrefix -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> a)
-> (a
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> ((TablePrefix, a) -> a)
-> QF be db s a
forall be r next (db :: (* -> *) -> *) s.
Projectible be r =>
(TablePrefix -> TablePrefix -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> r)
-> (r
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> ((TablePrefix, r) -> next)
-> QF be db s next
QAll (\TablePrefix
tblPfx -> Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be)
-> Maybe (TablePrefix, Maybe [TablePrefix])
-> BeamSqlBackendFromSyntax be
forall from.
IsSql92FromSyntax from =>
Sql92FromTableSourceSyntax from
-> Maybe (TablePrefix, Maybe [TablePrefix]) -> from
fromTable ([[Sql92TableSourceExpressionSyntax
    (Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be))]]
-> Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be)
forall tblSource.
IsSql92TableSourceSyntax tblSource =>
[[Sql92TableSourceExpressionSyntax tblSource]] -> tblSource
tableFromValues ((a
 -> [Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))])
-> [a]
-> [[Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]]
forall a b. (a -> b) -> [a] -> [b]
map (\a
row -> Proxy be
-> a -> WithExprContext [BeamSqlBackendExpressionSyntax be]
forall be a.
Projectible be a =>
Proxy be
-> a -> WithExprContext [BeamSqlBackendExpressionSyntax be]
project (Proxy be
forall k (t :: k). Proxy t
Proxy @be) a
row TablePrefix
tblPfx) [a]
rows)) (Maybe (TablePrefix, Maybe [TablePrefix])
 -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> Maybe (TablePrefix, Maybe [TablePrefix]))
-> TablePrefix
-> BeamSqlBackendFromSyntax be
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TablePrefix, Maybe [TablePrefix])
-> Maybe (TablePrefix, Maybe [TablePrefix])
forall a. a -> Maybe a
Just ((TablePrefix, Maybe [TablePrefix])
 -> Maybe (TablePrefix, Maybe [TablePrefix]))
-> (TablePrefix -> (TablePrefix, Maybe [TablePrefix]))
-> TablePrefix
-> Maybe (TablePrefix, Maybe [TablePrefix])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,[TablePrefix] -> Maybe [TablePrefix]
forall a. a -> Maybe a
Just [TablePrefix]
fieldNames))
                    (\TablePrefix
tblNm' -> (a, [TablePrefix]) -> a
forall a b. (a, b) -> a
fst ((a, [TablePrefix]) -> a) -> (a, [TablePrefix]) -> a
forall a b. (a -> b) -> a -> b
$ (TablePrefix -> BeamSqlBackendFieldNameSyntax be)
-> (a, [TablePrefix])
forall be res.
(BeamSqlBackend be, Projectible be res) =>
(TablePrefix -> BeamSqlBackendFieldNameSyntax be)
-> (res, [TablePrefix])
mkFieldNames (TablePrefix
-> TablePrefix
-> Sql92ExpressionFieldNameSyntax
     (Sql92InsertValuesExpressionSyntax
        (Sql92InsertValuesSyntax
           (Sql92InsertSyntax (BeamSqlBackendSyntax be))))
forall fn.
IsSql92FieldNameSyntax fn =>
TablePrefix -> TablePrefix -> fn
qualifiedField TablePrefix
tblNm'))
                    (\a
_ -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be))
forall a. Maybe a
Nothing) (TablePrefix, a) -> a
forall a b. (a, b) -> b
snd)
    where
      fieldNames :: [TablePrefix]
fieldNames = (a, [TablePrefix]) -> [TablePrefix]
forall a b. (a, b) -> b
snd ((a, [TablePrefix]) -> [TablePrefix])
-> (a, [TablePrefix]) -> [TablePrefix]
forall a b. (a -> b) -> a -> b
$ (TablePrefix -> BeamSqlBackendFieldNameSyntax be)
-> (a, [TablePrefix])
forall be res.
(BeamSqlBackend be, Projectible be res) =>
(TablePrefix -> BeamSqlBackendFieldNameSyntax be)
-> (res, [TablePrefix])
mkFieldNames @be @a TablePrefix -> BeamSqlBackendFieldNameSyntax be
forall fn. IsSql92FieldNameSyntax fn => TablePrefix -> fn
unqualifiedField

-- | Introduce all entries of a table into the 'Q' monad based on the
--   given QExpr. The join condition is expected to return a
--   'Bool'. For a version that takes 'SqlBool' (a possibly @UNKNOWN@
--   boolean, that maps more closely to the SQL standard), see
--   'join_''.
join_ :: ( Database be db, Table table, BeamSqlBackend be )
      => DatabaseEntity be db (TableEntity table)
      -> (table (QExpr be s) -> QExpr be s Bool)
      -> Q be db s (table (QExpr be s))
join_ :: DatabaseEntity be db (TableEntity table)
-> (table (QExpr be s) -> QExpr be s Bool)
-> Q be db s (table (QExpr be s))
join_ DatabaseEntity be db (TableEntity table)
tbl table (QExpr be s) -> QExpr be s Bool
mkOn = DatabaseEntity be db (TableEntity table)
-> (table (QExpr be s) -> QExpr be s SqlBool)
-> Q be db s (table (QExpr be s))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, Table table, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> (table (QExpr be s) -> QExpr be s SqlBool)
-> Q be db s (table (QExpr be s))
join_' DatabaseEntity be db (TableEntity table)
tbl (QExpr be s Bool -> QExpr be s SqlBool
forall context syntax s.
QGenExpr context syntax s Bool -> QGenExpr context syntax s SqlBool
sqlBool_ (QExpr be s Bool -> QExpr be s SqlBool)
-> (table (QExpr be s) -> QExpr be s Bool)
-> table (QExpr be s)
-> QExpr be s SqlBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. table (QExpr be s) -> QExpr be s Bool
mkOn)

-- | Like 'join_', but accepting an @ON@ condition that returns
-- 'SqlBool'
join_' :: ( Database be db, Table table, BeamSqlBackend be )
       => DatabaseEntity be db (TableEntity table)
       -> (table (QExpr be s) -> QExpr be s SqlBool)
       -> Q be db s (table (QExpr be s))
join_' :: DatabaseEntity be db (TableEntity table)
-> (table (QExpr be s) -> QExpr be s SqlBool)
-> Q be db s (table (QExpr be s))
join_' (DatabaseEntity tbl :: DatabaseEntityDescriptor be (TableEntity table)
tbl@(DatabaseTable {})) table (QExpr be s) -> QExpr be s SqlBool
mkOn =
    QM be db s (table (QExpr be s)) -> Q be db s (table (QExpr be s))
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QM be db s (table (QExpr be s)) -> Q be db s (table (QExpr be s)))
-> QM be db s (table (QExpr be s))
-> Q be db s (table (QExpr be s))
forall a b. (a -> b) -> a -> b
$ QF be db s (table (QExpr be s)) -> QM be db s (table (QExpr be s))
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((TablePrefix -> TablePrefix -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> table (QExpr be s))
-> (table (QExpr be s)
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> ((TablePrefix, table (QExpr be s)) -> table (QExpr be s))
-> QF be db s (table (QExpr be s))
forall be r next (db :: (* -> *) -> *) s.
Projectible be r =>
(TablePrefix -> TablePrefix -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> r)
-> (r
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> ((TablePrefix, r) -> next)
-> QF be db s next
QAll (\TablePrefix
_ -> Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be)
-> Maybe (TablePrefix, Maybe [TablePrefix])
-> BeamSqlBackendFromSyntax be
forall from.
IsSql92FromSyntax from =>
Sql92FromTableSourceSyntax from
-> Maybe (TablePrefix, Maybe [TablePrefix]) -> from
fromTable (Sql92TableSourceTableNameSyntax
  (Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be))
-> Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be)
forall tblSource.
IsSql92TableSourceSyntax tblSource =>
Sql92TableSourceTableNameSyntax tblSource -> tblSource
tableNamed (Maybe TablePrefix
-> TablePrefix
-> Sql92TableSourceTableNameSyntax
     (Sql92FromTableSourceSyntax (BeamSqlBackendFromSyntax be))
forall tblName.
IsSql92TableNameSyntax tblName =>
Maybe TablePrefix -> TablePrefix -> tblName
tableName (DatabaseEntityDescriptor be (TableEntity table)
-> Maybe TablePrefix
forall be (tbl :: (* -> *) -> *).
DatabaseEntityDescriptor be (TableEntity tbl) -> Maybe TablePrefix
dbTableSchema DatabaseEntityDescriptor be (TableEntity table)
tbl) (DatabaseEntityDescriptor be (TableEntity table) -> TablePrefix
forall be (tbl :: (* -> *) -> *).
DatabaseEntityDescriptor be (TableEntity tbl) -> TablePrefix
dbTableCurrentName DatabaseEntityDescriptor be (TableEntity table)
tbl))) (Maybe (TablePrefix, Maybe [TablePrefix])
 -> BeamSqlBackendFromSyntax be)
-> (TablePrefix -> Maybe (TablePrefix, Maybe [TablePrefix]))
-> TablePrefix
-> BeamSqlBackendFromSyntax be
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TablePrefix, Maybe [TablePrefix])
-> Maybe (TablePrefix, Maybe [TablePrefix])
forall a. a -> Maybe a
Just ((TablePrefix, Maybe [TablePrefix])
 -> Maybe (TablePrefix, Maybe [TablePrefix]))
-> (TablePrefix -> (TablePrefix, Maybe [TablePrefix]))
-> TablePrefix
-> Maybe (TablePrefix, Maybe [TablePrefix])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (, Maybe [TablePrefix]
forall a. Maybe a
Nothing))
                    (TableSettings table -> TablePrefix -> table (QExpr be s)
forall be (table :: (* -> *) -> *) ctxt s.
(BeamSqlBackend be, Beamable table) =>
TableSettings table -> TablePrefix -> table (QGenExpr ctxt be s)
tableFieldsToExpressions (DatabaseEntityDescriptor be (TableEntity table)
-> TableSettings table
forall be (tbl :: (* -> *) -> *).
DatabaseEntityDescriptor be (TableEntity tbl) -> TableSettings tbl
dbTableSettings DatabaseEntityDescriptor be (TableEntity table)
tbl))
                    (\table (QExpr be s)
tbl' -> let QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
on = table (QExpr be s) -> QExpr be s SqlBool
mkOn table (QExpr be s)
tbl' in (TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Maybe
     (TablePrefix
      -> Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
forall a. a -> Maybe a
Just TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
WithExprContext (BeamSqlBackendExpressionSyntax be)
on) (TablePrefix, table (QExpr be s)) -> table (QExpr be s)
forall a b. (a, b) -> b
snd)

-- | Introduce a table using a left join with no ON clause. Because this is not
--   an inner join, the resulting table is made nullable. This means that each
--   field that would normally have type 'QExpr x' will now have type 'QExpr
--   (Maybe x)'.
perhaps_ :: forall s r be db.
          ( Projectible be r, BeamSqlBackend be
          , ThreadRewritable (QNested s) r
          , Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s r) )
         => Q be db (QNested s) r
         -> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
perhaps_ :: Q be db (QNested s) r
-> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
perhaps_ (Q QM be db (QNested s) r
sub) =
  QM be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
-> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QM be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
 -> Q be
      db
      s
      (Retag Nullable (WithRewrittenThread (QNested s) s r)))
-> QM
     be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
-> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
forall a b. (a -> b) -> a -> b
$ QF be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
-> QM
     be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (QM be db (QNested s) r
-> (BeamSqlBackendFromSyntax be
    -> BeamSqlBackendFromSyntax be
    -> Maybe (BeamSqlBackendExpressionSyntax be)
    -> BeamSqlBackendFromSyntax be)
-> (r
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> (r -> Retag Nullable (WithRewrittenThread (QNested s) s r))
-> QF
     be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
QM be db (QNested s) r
-> (BeamSqlBackendFromSyntax be
    -> BeamSqlBackendFromSyntax be
    -> Maybe (BeamSqlBackendExpressionSyntax be)
    -> BeamSqlBackendFromSyntax be)
-> (r
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> (r -> next)
-> QF be db s next
QArbitraryJoin
              QM be db (QNested s) r
sub BeamSqlBackendFromSyntax be
-> BeamSqlBackendFromSyntax be
-> Maybe (BeamSqlBackendExpressionSyntax be)
-> BeamSqlBackendFromSyntax be
forall from.
IsSql92FromSyntax from =>
from -> from -> Maybe (Sql92FromExpressionSyntax from) -> from
leftJoin
              (\r
_ -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be))
forall a. Maybe a
Nothing)
              (\r
r -> (forall a.
 Columnar' (QExpr be s) a -> Columnar' (Nullable (QExpr be s)) a)
-> WithRewrittenThread (QNested s) s r
-> Retag Nullable (WithRewrittenThread (QNested s) s r)
forall (f :: * -> *) x (tag :: (* -> *) -> * -> *).
Retaggable f x =>
(forall a. Columnar' f a -> Columnar' (tag f) a)
-> x -> Retag tag x
retag (\(Columnar' (QExpr e) :: Columnar' (QExpr be s) a) ->
                                            Columnar (Nullable (QExpr be s)) a
-> Columnar' (Nullable (QExpr be s)) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' (WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QGenExpr QValueContext be s (Maybe a)
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
e) :: Columnar' (Nullable (QExpr be s)) a) (WithRewrittenThread (QNested s) s r
 -> Retag Nullable (WithRewrittenThread (QNested s) s r))
-> WithRewrittenThread (QNested s) s r
-> Retag Nullable (WithRewrittenThread (QNested s) s r)
forall a b. (a -> b) -> a -> b
$
                                  Proxy s -> r -> WithRewrittenThread (QNested s) s r
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s) r
r))

-- | Outer join. every row of each table, returning @NULL@ for any row
-- of either table for which the join condition finds no related rows.
--
-- This expects a join expression returning 'Bool', for a version that
-- accepts a 'SqlBool' (a possibly @UNKNOWN@ boolean, that maps more
-- closely to the SQL standard), see 'outerJoin_''
outerJoin_ :: forall s a b be db.
              ( BeamSqlBackend be, BeamSqlBackendSupportsOuterJoin be
              , Projectible be a, Projectible be b
              , ThreadRewritable (QNested s) a, ThreadRewritable (QNested s) b
              , Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s a)
              , Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s b)
              )
           => Q be db (QNested s) a
           -> Q be db (QNested s) b
           -> ( (WithRewrittenThread (QNested s) s a, WithRewrittenThread (QNested s) s b) -> QExpr be s Bool )
           -> Q be db s ( Retag Nullable (WithRewrittenThread (QNested s) s a)
                        , Retag Nullable (WithRewrittenThread (QNested s) s b) )
outerJoin_ :: Q be db (QNested s) a
-> Q be db (QNested s) b
-> ((WithRewrittenThread (QNested s) s a,
     WithRewrittenThread (QNested s) s b)
    -> QExpr be s Bool)
-> Q be
     db
     s
     (Retag Nullable (WithRewrittenThread (QNested s) s a),
      Retag Nullable (WithRewrittenThread (QNested s) s b))
outerJoin_ Q be db (QNested s) a
a Q be db (QNested s) b
b (WithRewrittenThread (QNested s) s a,
 WithRewrittenThread (QNested s) s b)
-> QExpr be s Bool
on_ = Q be db (QNested s) a
-> Q be db (QNested s) b
-> ((WithRewrittenThread (QNested s) s a,
     WithRewrittenThread (QNested s) s b)
    -> QExpr be s SqlBool)
-> Q be
     db
     s
     (Retag Nullable (WithRewrittenThread (QNested s) s a),
      Retag Nullable (WithRewrittenThread (QNested s) s b))
forall s a b be (db :: (* -> *) -> *).
(BeamSqlBackend be, BeamSqlBackendSupportsOuterJoin be,
 Projectible be a, Projectible be b, ThreadRewritable (QNested s) a,
 ThreadRewritable (QNested s) b,
 Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s a),
 Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s b)) =>
Q be db (QNested s) a
-> Q be db (QNested s) b
-> ((WithRewrittenThread (QNested s) s a,
     WithRewrittenThread (QNested s) s b)
    -> QExpr be s SqlBool)
-> Q be
     db
     s
     (Retag Nullable (WithRewrittenThread (QNested s) s a),
      Retag Nullable (WithRewrittenThread (QNested s) s b))
outerJoin_' Q be db (QNested s) a
a Q be db (QNested s) b
b (QExpr be s Bool -> QExpr be s SqlBool
forall context syntax s.
QGenExpr context syntax s Bool -> QGenExpr context syntax s SqlBool
sqlBool_ (QExpr be s Bool -> QExpr be s SqlBool)
-> ((WithRewrittenThread (QNested s) s a,
     WithRewrittenThread (QNested s) s b)
    -> QExpr be s Bool)
-> (WithRewrittenThread (QNested s) s a,
    WithRewrittenThread (QNested s) s b)
-> QExpr be s SqlBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WithRewrittenThread (QNested s) s a,
 WithRewrittenThread (QNested s) s b)
-> QExpr be s Bool
on_)

-- | Like 'outerJoin_', but accepting 'SqlBool'. Pairs of rows for
-- which the join condition is unknown are considered to be unrelated,
-- by SQL compliant databases at least.
outerJoin_' :: forall s a b be db.
               ( BeamSqlBackend be, BeamSqlBackendSupportsOuterJoin be
               , Projectible be a, Projectible be b
               , ThreadRewritable (QNested s) a, ThreadRewritable (QNested s) b
               , Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s a)
               , Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s b)
               )
            => Q be db (QNested s) a
            -> Q be db (QNested s) b
            -> ( (WithRewrittenThread (QNested s) s a, WithRewrittenThread (QNested s) s b) -> QExpr be s SqlBool )
            -> Q be db s ( Retag Nullable (WithRewrittenThread (QNested s) s a)
                         , Retag Nullable (WithRewrittenThread (QNested s) s b) )
outerJoin_' :: Q be db (QNested s) a
-> Q be db (QNested s) b
-> ((WithRewrittenThread (QNested s) s a,
     WithRewrittenThread (QNested s) s b)
    -> QExpr be s SqlBool)
-> Q be
     db
     s
     (Retag Nullable (WithRewrittenThread (QNested s) s a),
      Retag Nullable (WithRewrittenThread (QNested s) s b))
outerJoin_' (Q QM be db (QNested s) a
a) (Q QM be db (QNested s) b
b) (WithRewrittenThread (QNested s) s a,
 WithRewrittenThread (QNested s) s b)
-> QExpr be s SqlBool
on_ =
  QM
  be
  db
  s
  (Retag Nullable (WithRewrittenThread (QNested s) s a),
   Retag Nullable (WithRewrittenThread (QNested s) s b))
-> Q be
     db
     s
     (Retag Nullable (WithRewrittenThread (QNested s) s a),
      Retag Nullable (WithRewrittenThread (QNested s) s b))
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QM
   be
   db
   s
   (Retag Nullable (WithRewrittenThread (QNested s) s a),
    Retag Nullable (WithRewrittenThread (QNested s) s b))
 -> Q be
      db
      s
      (Retag Nullable (WithRewrittenThread (QNested s) s a),
       Retag Nullable (WithRewrittenThread (QNested s) s b)))
-> QM
     be
     db
     s
     (Retag Nullable (WithRewrittenThread (QNested s) s a),
      Retag Nullable (WithRewrittenThread (QNested s) s b))
-> Q be
     db
     s
     (Retag Nullable (WithRewrittenThread (QNested s) s a),
      Retag Nullable (WithRewrittenThread (QNested s) s b))
forall a b. (a -> b) -> a -> b
$ QF
  be
  db
  s
  (Retag Nullable (WithRewrittenThread (QNested s) s a),
   Retag Nullable (WithRewrittenThread (QNested s) s b))
-> QM
     be
     db
     s
     (Retag Nullable (WithRewrittenThread (QNested s) s a),
      Retag Nullable (WithRewrittenThread (QNested s) s b))
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (QM be db (QNested s) a
-> QM be db (QNested s) b
-> (BeamSqlBackendFromSyntax be
    -> BeamSqlBackendFromSyntax be
    -> Maybe (BeamSqlBackendExpressionSyntax be)
    -> BeamSqlBackendFromSyntax be)
-> ((a, b)
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> ((a, b)
    -> (Retag Nullable (WithRewrittenThread (QNested s) s a),
        Retag Nullable (WithRewrittenThread (QNested s) s b)))
-> QF
     be
     db
     s
     (Retag Nullable (WithRewrittenThread (QNested s) s a),
      Retag Nullable (WithRewrittenThread (QNested s) s b))
forall be a b (db :: (* -> *) -> *) s next.
(Projectible be a, Projectible be b) =>
QM be db (QNested s) a
-> QM be db (QNested s) b
-> (BeamSqlBackendFromSyntax be
    -> BeamSqlBackendFromSyntax be
    -> Maybe (BeamSqlBackendExpressionSyntax be)
    -> BeamSqlBackendFromSyntax be)
-> ((a, b)
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> ((a, b) -> next)
-> QF be db s next
QTwoWayJoin QM be db (QNested s) a
a QM be db (QNested s) b
b BeamSqlBackendFromSyntax be
-> BeamSqlBackendFromSyntax be
-> Maybe (BeamSqlBackendExpressionSyntax be)
-> BeamSqlBackendFromSyntax be
forall from.
IsSql92FromOuterJoinSyntax from =>
from -> from -> Maybe (Sql92FromExpressionSyntax from) -> from
outerJoin
              (\(a
a', b
b') ->
                 let QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
e = (WithRewrittenThread (QNested s) s a,
 WithRewrittenThread (QNested s) s b)
-> QExpr be s SqlBool
on_ (Proxy s -> a -> WithRewrittenThread (QNested s) s a
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s) a
a', Proxy s -> b -> WithRewrittenThread (QNested s) s b
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s) b
b')
                 in (TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Maybe
     (TablePrefix
      -> Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
forall a. a -> Maybe a
Just TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
WithExprContext (BeamSqlBackendExpressionSyntax be)
e)
              (\(a
a', b
b') ->
                 let retag' :: (ThreadRewritable (QNested s) x, Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s x))
                            => x -> Retag Nullable (WithRewrittenThread (QNested s) s x)
                     retag' :: x -> Retag Nullable (WithRewrittenThread (QNested s) s x)
retag' = (forall a.
 Columnar' (QExpr be s) a -> Columnar' (Nullable (QExpr be s)) a)
-> WithRewrittenThread (QNested s) s x
-> Retag Nullable (WithRewrittenThread (QNested s) s x)
forall (f :: * -> *) x (tag :: (* -> *) -> * -> *).
Retaggable f x =>
(forall a. Columnar' f a -> Columnar' (tag f) a)
-> x -> Retag tag x
retag (\(Columnar' (QExpr e) :: Columnar' (QExpr be s) x) ->
                                        Columnar (Nullable (QExpr be s)) a
-> Columnar' (Nullable (QExpr be s)) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' (WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QGenExpr QValueContext be s (Maybe a)
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
e) :: Columnar' (Nullable (QExpr be s)) x) (WithRewrittenThread (QNested s) s x
 -> Retag Nullable (WithRewrittenThread (QNested s) s x))
-> (x -> WithRewrittenThread (QNested s) s x)
-> x
-> Retag Nullable (WithRewrittenThread (QNested s) s x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                              Proxy s -> x -> WithRewrittenThread (QNested s) s x
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s)
                 in ( a -> Retag Nullable (WithRewrittenThread (QNested s) s a)
forall x.
(ThreadRewritable (QNested s) x,
 Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s x)) =>
x -> Retag Nullable (WithRewrittenThread (QNested s) s x)
retag' a
a', b -> Retag Nullable (WithRewrittenThread (QNested s) s b)
forall x.
(ThreadRewritable (QNested s) x,
 Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s x)) =>
x -> Retag Nullable (WithRewrittenThread (QNested s) s x)
retag' b
b' )))

-- | Introduce a table using a left join. The ON clause is required here.Because
--   this is not an inner join, the resulting table is made nullable. This means
--   that each field that would normally have type 'QExpr x' will now have type
--   'QExpr (Maybe x)'.
--
--   The @ON@ condition given must return 'Bool'. For a version that
--   accepts an @ON@ condition returning 'SqlBool', see 'leftJoin_''.
leftJoin_ :: forall s r be db.
           ( BeamSqlBackend be, Projectible be r
           , ThreadRewritable (QNested s) r
           , Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s r) )
          => Q be db (QNested s) r
          -> (WithRewrittenThread (QNested s) s r -> QExpr be s Bool)
          -> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
leftJoin_ :: Q be db (QNested s) r
-> (WithRewrittenThread (QNested s) s r -> QExpr be s Bool)
-> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
leftJoin_ Q be db (QNested s) r
sub WithRewrittenThread (QNested s) s r -> QExpr be s Bool
on_ = Q be db (QNested s) r
-> (WithRewrittenThread (QNested s) s r -> QExpr be s SqlBool)
-> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
forall s r be (db :: (* -> *) -> *).
(BeamSqlBackend be, Projectible be r,
 ThreadRewritable (QNested s) r,
 Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s r)) =>
Q be db (QNested s) r
-> (WithRewrittenThread (QNested s) s r -> QExpr be s SqlBool)
-> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
leftJoin_' Q be db (QNested s) r
sub (QExpr be s Bool -> QExpr be s SqlBool
forall context syntax s.
QGenExpr context syntax s Bool -> QGenExpr context syntax s SqlBool
sqlBool_ (QExpr be s Bool -> QExpr be s SqlBool)
-> (WithRewrittenThread (QNested s) s r -> QExpr be s Bool)
-> WithRewrittenThread (QNested s) s r
-> QExpr be s SqlBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithRewrittenThread (QNested s) s r -> QExpr be s Bool
on_)

-- | Like 'leftJoin_', but accepts an @ON@ clause returning 'SqlBool'.
leftJoin_' :: forall s r be db.
            ( BeamSqlBackend be, Projectible be r
            , ThreadRewritable (QNested s) r
            , Retaggable (QExpr be s) (WithRewrittenThread (QNested s) s r) )
           => Q be db (QNested s) r
           -> (WithRewrittenThread (QNested s) s r -> QExpr be s SqlBool)
           -> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
leftJoin_' :: Q be db (QNested s) r
-> (WithRewrittenThread (QNested s) s r -> QExpr be s SqlBool)
-> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
leftJoin_' (Q QM be db (QNested s) r
sub) WithRewrittenThread (QNested s) s r -> QExpr be s SqlBool
on_ =
  QM be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
-> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QM be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
 -> Q be
      db
      s
      (Retag Nullable (WithRewrittenThread (QNested s) s r)))
-> QM
     be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
-> Q be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
forall a b. (a -> b) -> a -> b
$ QF be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
-> QM
     be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (QM be db (QNested s) r
-> (BeamSqlBackendFromSyntax be
    -> BeamSqlBackendFromSyntax be
    -> Maybe (BeamSqlBackendExpressionSyntax be)
    -> BeamSqlBackendFromSyntax be)
-> (r
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> (r -> Retag Nullable (WithRewrittenThread (QNested s) s r))
-> QF
     be db s (Retag Nullable (WithRewrittenThread (QNested s) s r))
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
QM be db (QNested s) r
-> (BeamSqlBackendFromSyntax be
    -> BeamSqlBackendFromSyntax be
    -> Maybe (BeamSqlBackendExpressionSyntax be)
    -> BeamSqlBackendFromSyntax be)
-> (r
    -> Maybe (WithExprContext (BeamSqlBackendExpressionSyntax be)))
-> (r -> next)
-> QF be db s next
QArbitraryJoin
               QM be db (QNested s) r
sub BeamSqlBackendFromSyntax be
-> BeamSqlBackendFromSyntax be
-> Maybe (BeamSqlBackendExpressionSyntax be)
-> BeamSqlBackendFromSyntax be
forall from.
IsSql92FromSyntax from =>
from -> from -> Maybe (Sql92FromExpressionSyntax from) -> from
leftJoin
               (\r
r -> let QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
e = WithRewrittenThread (QNested s) s r -> QExpr be s SqlBool
on_ (Proxy s -> r -> WithRewrittenThread (QNested s) s r
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s) r
r) in (TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Maybe
     (TablePrefix
      -> Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
forall a. a -> Maybe a
Just TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
WithExprContext (BeamSqlBackendExpressionSyntax be)
e)
               (\r
r -> (forall a.
 Columnar' (QExpr be s) a -> Columnar' (Nullable (QExpr be s)) a)
-> WithRewrittenThread (QNested s) s r
-> Retag Nullable (WithRewrittenThread (QNested s) s r)
forall (f :: * -> *) x (tag :: (* -> *) -> * -> *).
Retaggable f x =>
(forall a. Columnar' f a -> Columnar' (tag f) a)
-> x -> Retag tag x
retag (\(Columnar' (QExpr e) :: Columnar' (QExpr be s) a) ->
                                Columnar (Nullable (QExpr be s)) a
-> Columnar' (Nullable (QExpr be s)) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' (WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QGenExpr QValueContext be s (Maybe a)
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
e) :: Columnar' (Nullable (QExpr be s)) a) (WithRewrittenThread (QNested s) s r
 -> Retag Nullable (WithRewrittenThread (QNested s) s r))
-> WithRewrittenThread (QNested s) s r
-> Retag Nullable (WithRewrittenThread (QNested s) s r)
forall a b. (a -> b) -> a -> b
$
                      Proxy s -> r -> WithRewrittenThread (QNested s) s r
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s) r
r))

subselect_ :: forall s r be db.
            ( ThreadRewritable (QNested s) r
            , Projectible be r )
           => Q be db (QNested s) r
           -> Q be db s (WithRewrittenThread (QNested s) s r)
subselect_ :: Q be db (QNested s) r
-> Q be db s (WithRewrittenThread (QNested s) s r)
subselect_ (Q QM be db (QNested s) r
q') =
  QM be db s (WithRewrittenThread (QNested s) s r)
-> Q be db s (WithRewrittenThread (QNested s) s r)
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s (WithRewrittenThread (QNested s) s r)
-> QM be db s (WithRewrittenThread (QNested s) s r)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (QM be db (QNested s) r
-> (r -> WithRewrittenThread (QNested s) s r)
-> QF be db s (WithRewrittenThread (QNested s) s r)
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
QM be db (QNested s) r -> (r -> next) -> QF be db s next
QSubSelect QM be db (QNested s) r
q' (Proxy s -> r -> WithRewrittenThread (QNested s) s r
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s))))

-- | Only allow results for which the 'QExpr' yields 'True'. For a
-- version that operates over possibly @NULL@ 'SqlBool's, see
-- 'guard_''.
guard_ :: forall be db s
        . BeamSqlBackend be
       => QExpr be s Bool -> Q be db s ()
guard_ :: QExpr be s Bool -> Q be db s ()
guard_ = QExpr be s SqlBool -> Q be db s ()
forall be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
QExpr be s SqlBool -> Q be db s ()
guard_' (QExpr be s SqlBool -> Q be db s ())
-> (QExpr be s Bool -> QExpr be s SqlBool)
-> QExpr be s Bool
-> Q be db s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QExpr be s Bool -> QExpr be s SqlBool
forall context syntax s.
QGenExpr context syntax s Bool -> QGenExpr context syntax s SqlBool
sqlBool_

-- | Only allow results for which the 'QExpr' yields @TRUE@.
--
-- This function operates over 'SqlBool', which are like haskell
-- 'Bool's, except for the special @UNKNOWN@ value that occurs when
-- comparisons include @NULL@. For a version that operates over known
-- non-@NULL@ booleans, see 'guard_'.
guard_' :: forall be db s
         . BeamSqlBackend be
        => QExpr be s SqlBool -> Q be db s ()
guard_' :: QExpr be s SqlBool -> Q be db s ()
guard_' (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
guardE') = QM be db s () -> Q be db s ()
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s () -> QM be db s ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> () -> QF be db s ()
forall be next (db :: (* -> *) -> *) s.
WithExprContext (BeamSqlBackendExpressionSyntax be)
-> next -> QF be db s next
QGuard TablePrefix -> BeamSqlBackendExpressionSyntax be
guardE' ()))

-- | Synonym for @clause >>= \\x -> guard_ (mkExpr x)>> pure x@. Use 'filter_'' for comparisons with 'SqlBool'
filter_ :: forall r be db s
         . BeamSqlBackend be
        => (r -> QExpr be s Bool)
        -> Q be db s r -> Q be db s r
filter_ :: (r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_ r -> QExpr be s Bool
mkExpr Q be db s r
clause = Q be db s r
clause Q be db s r -> (r -> Q be db s r) -> Q be db s r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \r
x -> QExpr be s Bool -> Q be db s ()
forall be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
QExpr be s Bool -> Q be db s ()
guard_ (r -> QExpr be s Bool
mkExpr r
x) Q be db s () -> Q be db s r -> Q be db s r
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> r -> Q be db s r
forall (f :: * -> *) a. Applicative f => a -> f a
pure r
x

-- | Synonym for @clause >>= \\x -> guard_' (mkExpr x)>> pure x@. Use 'filter_' for comparisons with 'Bool'
filter_' :: forall r be db s
          . BeamSqlBackend be
        => (r -> QExpr be s SqlBool)
        -> Q be db s r -> Q be db s r
filter_' :: (r -> QExpr be s SqlBool) -> Q be db s r -> Q be db s r
filter_' r -> QExpr be s SqlBool
mkExpr Q be db s r
clause = Q be db s r
clause Q be db s r -> (r -> Q be db s r) -> Q be db s r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \r
x -> QExpr be s SqlBool -> Q be db s ()
forall be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
QExpr be s SqlBool -> Q be db s ()
guard_' (r -> QExpr be s SqlBool
mkExpr r
x) Q be db s () -> Q be db s r -> Q be db s r
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> r -> Q be db s r
forall (f :: * -> *) a. Applicative f => a -> f a
pure r
x

-- | Introduce all entries of the given table which are referenced by the given 'PrimaryKey'
related_ :: forall be db rel s
          . ( Database be db, Table rel, BeamSqlBackend be
            , HasTableEquality be (PrimaryKey rel)
            )
         => DatabaseEntity be db (TableEntity rel)
         -> PrimaryKey rel (QExpr be s)
         -> Q be db s (rel (QExpr be s))
related_ :: DatabaseEntity be db (TableEntity rel)
-> PrimaryKey rel (QExpr be s) -> Q be db s (rel (QExpr be s))
related_ DatabaseEntity be db (TableEntity rel)
relTbl PrimaryKey rel (QExpr be s)
relKey =
  DatabaseEntity be db (TableEntity rel)
-> (rel (QExpr be s) -> QExpr be s Bool)
-> Q be db s (rel (QExpr be s))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, Table table, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> (table (QExpr be s) -> QExpr be s Bool)
-> Q be db s (table (QExpr be s))
join_ DatabaseEntity be db (TableEntity rel)
relTbl (\rel (QExpr be s)
rel -> PrimaryKey rel (QExpr be s)
relKey PrimaryKey rel (QExpr be s)
-> PrimaryKey rel (QExpr be s) -> QExpr be s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. rel (QExpr be s) -> PrimaryKey rel (QExpr be s)
forall (table :: (* -> *) -> *) (column :: * -> *).
Table table =>
table column -> PrimaryKey table column
primaryKey rel (QExpr be s)
rel)

-- | Introduce all entries of the given table for which the expression (which can depend on the queried table returns true)
relatedBy_ :: forall be db rel s
            . ( Database be db, Table rel, BeamSqlBackend be )
           => DatabaseEntity be db (TableEntity rel)
           -> (rel (QExpr be s) -> QExpr be s Bool)
           -> Q be db s (rel (QExpr be s))
relatedBy_ :: DatabaseEntity be db (TableEntity rel)
-> (rel (QExpr be s) -> QExpr be s Bool)
-> Q be db s (rel (QExpr be s))
relatedBy_ = DatabaseEntity be db (TableEntity rel)
-> (rel (QExpr be s) -> QExpr be s Bool)
-> Q be db s (rel (QExpr be s))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, Table table, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> (table (QExpr be s) -> QExpr be s Bool)
-> Q be db s (table (QExpr be s))
join_

-- | Introduce all entries of the given table for which the expression (which can depend on the queried table returns true)
relatedBy_' :: forall be db rel s
             . ( Database be db, Table rel, BeamSqlBackend be )
            => DatabaseEntity be db (TableEntity rel)
            -> (rel (QExpr be s) -> QExpr be s SqlBool)
            -> Q be db s (rel (QExpr be s))
relatedBy_' :: DatabaseEntity be db (TableEntity rel)
-> (rel (QExpr be s) -> QExpr be s SqlBool)
-> Q be db s (rel (QExpr be s))
relatedBy_' = DatabaseEntity be db (TableEntity rel)
-> (rel (QExpr be s) -> QExpr be s SqlBool)
-> Q be db s (rel (QExpr be s))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, Table table, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> (table (QExpr be s) -> QExpr be s SqlBool)
-> Q be db s (table (QExpr be s))
join_'

-- | Generate an appropriate boolean 'QGenExpr' comparing the given foreign key
--   to the given table. Useful for creating join conditions.
--   Use 'references_'' for a 'SqlBool' comparison.
references_ :: ( Table t, BeamSqlBackend be
               , HasTableEquality be (PrimaryKey t) )
            => PrimaryKey t (QGenExpr ctxt be s) -> t (QGenExpr ctxt be s) -> QGenExpr ctxt be s Bool
references_ :: PrimaryKey t (QGenExpr ctxt be s)
-> t (QGenExpr ctxt be s) -> QGenExpr ctxt be s Bool
references_ PrimaryKey t (QGenExpr ctxt be s)
fk t (QGenExpr ctxt be s)
tbl = PrimaryKey t (QGenExpr ctxt be s)
fk PrimaryKey t (QGenExpr ctxt be s)
-> PrimaryKey t (QGenExpr ctxt be s) -> QGenExpr ctxt be s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. t (QGenExpr ctxt be s) -> PrimaryKey t (QGenExpr ctxt be s)
forall (t :: (* -> *) -> *) (f :: * -> *).
Table t =>
t f -> PrimaryKey t f
pk t (QGenExpr ctxt be s)
tbl

-- | Generate an appropriate boolean 'QGenExpr' comparing the given foreign key
--   to the given table. Useful for creating join conditions.
--   Use 'references_' for a 'Bool' comparison.
references_' :: ( Table t, BeamSqlBackend be
                , HasTableEquality be (PrimaryKey t) )
             => PrimaryKey t (QGenExpr ctxt be s) -> t (QGenExpr ctxt be s) -> QGenExpr ctxt be s SqlBool
references_' :: PrimaryKey t (QGenExpr ctxt be s)
-> t (QGenExpr ctxt be s) -> QGenExpr ctxt be s SqlBool
references_' PrimaryKey t (QGenExpr ctxt be s)
fk t (QGenExpr ctxt be s)
tbl = PrimaryKey t (QGenExpr ctxt be s)
fk PrimaryKey t (QGenExpr ctxt be s)
-> PrimaryKey t (QGenExpr ctxt be s) -> QGenExpr ctxt be s SqlBool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. t (QGenExpr ctxt be s) -> PrimaryKey t (QGenExpr ctxt be s)
forall (t :: (* -> *) -> *) (f :: * -> *).
Table t =>
t f -> PrimaryKey t f
pk t (QGenExpr ctxt be s)
tbl

-- | Only return distinct values from a query
nub_ :: ( BeamSqlBackend be, Projectible be r )
     => Q be db s r -> Q be db s r
nub_ :: Q be db s r -> Q be db s r
nub_ (Q QM be db s r
sub) = QM be db s r -> Q be db s r
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QM be db s r -> Q be db s r) -> QM be db s r -> Q be db s r
forall a b. (a -> b) -> a -> b
$ QF be db s r -> QM be db s r
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((r -> WithExprContext (BeamSqlBackendSetQuantifierSyntax be))
-> QM be db s r -> (r -> r) -> QF be db s r
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
(r -> WithExprContext (BeamSqlBackendSetQuantifierSyntax be))
-> QM be db s r -> (r -> next) -> QF be db s next
QDistinct (\r
_ TablePrefix
_ -> BeamSqlBackendSetQuantifierSyntax be
forall q. IsSql92AggregationSetQuantifierSyntax q => q
setQuantifierDistinct) QM be db s r
sub r -> r
forall a. a -> a
id)

-- | Limit the number of results returned by a query.
limit_ :: forall s a be db
        . ( Projectible be a
          , ThreadRewritable (QNested s) a )
        => Integer -> Q be db (QNested s) a -> Q be db s (WithRewrittenThread (QNested s) s a)
limit_ :: Integer
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
limit_ Integer
limit' (Q QM be db (QNested s) a
q) =
  QM be db s (WithRewrittenThread (QNested s) s a)
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s (WithRewrittenThread (QNested s) s a)
-> QM be db s (WithRewrittenThread (QNested s) s a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (Integer
-> QM be db (QNested s) a
-> (a -> WithRewrittenThread (QNested s) s a)
-> QF be db s (WithRewrittenThread (QNested s) s a)
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
Integer -> QM be db (QNested s) r -> (r -> next) -> QF be db s next
QLimit Integer
limit' QM be db (QNested s) a
q (Proxy s -> a -> WithRewrittenThread (QNested s) s a
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s))))

-- | Drop the first `offset'` results.
offset_ :: forall s a be db
         . ( Projectible be a
           , ThreadRewritable (QNested s) a )
        => Integer -> Q be db (QNested s) a -> Q be db s (WithRewrittenThread (QNested s) s a)
offset_ :: Integer
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
offset_ Integer
offset' (Q QM be db (QNested s) a
q) =
  QM be db s (WithRewrittenThread (QNested s) s a)
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s (WithRewrittenThread (QNested s) s a)
-> QM be db s (WithRewrittenThread (QNested s) s a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (Integer
-> QM be db (QNested s) a
-> (a -> WithRewrittenThread (QNested s) s a)
-> QF be db s (WithRewrittenThread (QNested s) s a)
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
Integer -> QM be db (QNested s) r -> (r -> next) -> QF be db s next
QOffset Integer
offset' QM be db (QNested s) a
q (Proxy s -> a -> WithRewrittenThread (QNested s) s a
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s))))

-- | Use the SQL @EXISTS@ operator to determine if the given query returns any results
exists_ :: ( BeamSqlBackend be, HasQBuilder be, Projectible be a)
        => Q be db s a -> QExpr be s Bool
exists_ :: Q be db s a -> QExpr be s Bool
exists_ Q be db s a
q = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QExpr be s Bool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\TablePrefix
tbl -> Sql92ExpressionSelectSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionSelectSyntax expr -> expr
existsE (TablePrefix -> Q be db s a -> BeamSqlBackendSelectSyntax be
forall be a (db :: (* -> *) -> *) s.
(HasQBuilder be, Projectible be a) =>
TablePrefix -> Q be db s a -> BeamSqlBackendSelectSyntax be
buildSqlQuery TablePrefix
tbl Q be db s a
q))

-- | Use the SQL @UNIQUE@ operator to determine if the given query produces a unique result
unique_ :: ( BeamSqlBackend be, HasQBuilder be, Projectible be a)
        => Q be db s a -> QExpr be s Bool
unique_ :: Q be db s a -> QExpr be s Bool
unique_ Q be db s a
q = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QExpr be s Bool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\TablePrefix
tbl -> Sql92ExpressionSelectSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionSelectSyntax expr -> expr
uniqueE (TablePrefix -> Q be db s a -> BeamSqlBackendSelectSyntax be
forall be a (db :: (* -> *) -> *) s.
(HasQBuilder be, Projectible be a) =>
TablePrefix -> Q be db s a -> BeamSqlBackendSelectSyntax be
buildSqlQuery TablePrefix
tbl Q be db s a
q))

-- | Use the SQL99 @DISTINCT@ operator to determine if the given query produces a distinct result
distinct_ :: ( BeamSqlBackend be, BeamSql99ExpressionBackend be, HasQBuilder be, Projectible be a)
          => Q be db s a -> QExpr be s Bool
distinct_ :: Q be db s a -> QExpr be s Bool
distinct_ Q be db s a
q = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QExpr be s Bool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\TablePrefix
tbl -> Sql92ExpressionSelectSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql99ExpressionSyntax expr =>
Sql92ExpressionSelectSyntax expr -> expr
distinctE (TablePrefix -> Q be db s a -> BeamSqlBackendSelectSyntax be
forall be a (db :: (* -> *) -> *) s.
(HasQBuilder be, Projectible be a) =>
TablePrefix -> Q be db s a -> BeamSqlBackendSelectSyntax be
buildSqlQuery TablePrefix
tbl Q be db s a
q))

-- | Project the (presumably) singular result of the given query as an expression
subquery_ :: ( BeamSqlBackend be, HasQBuilder be, Projectible be (QExpr be s a) )
          => Q be db s (QExpr be s a)
          -> QGenExpr ctxt be s a
subquery_ :: Q be db s (QExpr be s a) -> QGenExpr ctxt be s a
subquery_ Q be db s (QExpr be s a)
q =
  (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\TablePrefix
tbl -> Sql92ExpressionSelectSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionSelectSyntax expr -> expr
subqueryE (TablePrefix
-> Q be db s (QExpr be s a) -> BeamSqlBackendSelectSyntax be
forall be a (db :: (* -> *) -> *) s.
(HasQBuilder be, Projectible be a) =>
TablePrefix -> Q be db s a -> BeamSqlBackendSelectSyntax be
buildSqlQuery TablePrefix
tbl Q be db s (QExpr be s a)
q))

-- | SQL @CHAR_LENGTH@ function
charLength_ :: ( BeamSqlBackend be, BeamSqlBackendIsString be text, Integral a )
            => QGenExpr context be s text -> QGenExpr context be s a
charLength_ :: QGenExpr context be s text -> QGenExpr context be s a
charLength_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
charLengthE (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | SQL @OCTET_LENGTH@ function
octetLength_ :: ( BeamSqlBackend be, BeamSqlBackendIsString be text, Integral a )
             => QGenExpr context be s text -> QGenExpr context be s a
octetLength_ :: QGenExpr context be s text -> QGenExpr context be s a
octetLength_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
octetLengthE (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | SQL @BIT_LENGTH@ function
bitLength_ :: ( BeamSqlBackend be, Integral a )
           => QGenExpr context be s SqlBitString -> QGenExpr context be s a
bitLength_ :: QGenExpr context be s SqlBitString -> QGenExpr context be s a
bitLength_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
x) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
bitLengthE (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
x)

-- | SQL @CURRENT_TIMESTAMP@ function
currentTimestamp_ :: BeamSqlBackend be => QGenExpr ctxt be s LocalTime
currentTimestamp_ :: QGenExpr ctxt be s LocalTime
currentTimestamp_ = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s LocalTime
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr
currentTimestampE)

-- | SQL @POSITION(.. IN ..)@ function
position_ :: ( BeamSqlBackendIsString be text
             , BeamSqlBackend be, Integral b )
          => QExpr be s text -> QExpr be s text -> QExpr be s b
position_ :: QExpr be s text -> QExpr be s text -> QExpr be s b
position_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
needle) (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
haystack) =
  (TablePrefix -> BeamSqlBackendExpressionSyntax be) -> QExpr be s b
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr ((Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr -> expr
likeE TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
needle TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
haystack)

-- | SQL @LOWER@ function
lower_ ::  ( BeamSqlBackendIsString be text
           , BeamSqlBackend be )
       => QGenExpr context be s text -> QGenExpr context be s text
lower_ :: QGenExpr context be s text -> QGenExpr context be s text
lower_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s text
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
lowerE (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | SQL @UPPER@ function
upper_ :: ( BeamSqlBackendIsString be text
          , BeamSqlBackend be )
       => QGenExpr context be s text -> QGenExpr context be s text
upper_ :: QGenExpr context be s text -> QGenExpr context be s text
upper_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s text
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
upperE (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | SQL @TRIM@ function
trim_ :: ( BeamSqlBackendIsString be text
         , BeamSqlBackend be )
       => QGenExpr context be s text -> QGenExpr context be s text
trim_ :: QGenExpr context be s text -> QGenExpr context be s text
trim_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s text
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
trimE (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | Combine all the given boolean value 'QGenExpr's with the '&&.' operator.
allE :: BeamSqlBackend be
     => [ QGenExpr context be s Bool ] -> QGenExpr context be s Bool
allE :: [QGenExpr context be s Bool] -> QGenExpr context be s Bool
allE [QGenExpr context be s Bool]
es = QGenExpr context be s Bool
-> Maybe (QGenExpr context be s Bool) -> QGenExpr context be s Bool
forall a. a -> Maybe a -> a
fromMaybe ((TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s Bool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Sql92ExpressionValueSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (Bool
-> Sql92ExpressionValueSyntax (BeamSqlBackendExpressionSyntax be)
forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax Bool
True)))) (Maybe (QGenExpr context be s Bool) -> QGenExpr context be s Bool)
-> Maybe (QGenExpr context be s Bool) -> QGenExpr context be s Bool
forall a b. (a -> b) -> a -> b
$
          (Maybe (QGenExpr context be s Bool)
 -> QGenExpr context be s Bool
 -> Maybe (QGenExpr context be s Bool))
-> Maybe (QGenExpr context be s Bool)
-> [QGenExpr context be s Bool]
-> Maybe (QGenExpr context be s Bool)
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (\Maybe (QGenExpr context be s Bool)
expr QGenExpr context be s Bool
x ->
                   QGenExpr context be s Bool -> Maybe (QGenExpr context be s Bool)
forall a. a -> Maybe a
Just (QGenExpr context be s Bool -> Maybe (QGenExpr context be s Bool))
-> QGenExpr context be s Bool -> Maybe (QGenExpr context be s Bool)
forall a b. (a -> b) -> a -> b
$ QGenExpr context be s Bool
-> (QGenExpr context be s Bool -> QGenExpr context be s Bool)
-> Maybe (QGenExpr context be s Bool)
-> QGenExpr context be s Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe QGenExpr context be s Bool
x (\QGenExpr context be s Bool
e -> QGenExpr context be s Bool
e QGenExpr context be s Bool
-> QGenExpr context be s Bool -> QGenExpr context be s Bool
forall be context s.
BeamSqlBackend be =>
QGenExpr context be s Bool
-> QGenExpr context be s Bool -> QGenExpr context be s Bool
&&. QGenExpr context be s Bool
x) Maybe (QGenExpr context be s Bool)
expr)
                Maybe (QGenExpr context be s Bool)
forall a. Maybe a
Nothing [QGenExpr context be s Bool]
es

-- * UPDATE operators

-- | Extract an expression representing the current (non-UPDATEd) value of a 'QField'
current_ :: BeamSqlBackend be => QField s ty -> QExpr be s ty
current_ :: QField s ty -> QExpr be s ty
current_ (QField Bool
False TablePrefix
_ TablePrefix
nm) = (TablePrefix -> BeamSqlBackendExpressionSyntax be) -> QExpr be s ty
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Sql92ExpressionFieldNameSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionFieldNameSyntax expr -> expr
fieldE (TablePrefix
-> Sql92ExpressionFieldNameSyntax
     (Sql92InsertValuesExpressionSyntax
        (Sql92InsertValuesSyntax
           (Sql92InsertSyntax (BeamSqlBackendSyntax be))))
forall fn. IsSql92FieldNameSyntax fn => TablePrefix -> fn
unqualifiedField TablePrefix
nm)))
current_ (QField Bool
True TablePrefix
tbl TablePrefix
nm) = (TablePrefix -> BeamSqlBackendExpressionSyntax be) -> QExpr be s ty
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Sql92ExpressionFieldNameSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionFieldNameSyntax expr -> expr
fieldE (TablePrefix
-> TablePrefix
-> Sql92ExpressionFieldNameSyntax
     (Sql92InsertValuesExpressionSyntax
        (Sql92InsertValuesSyntax
           (Sql92InsertSyntax (BeamSqlBackendSyntax be))))
forall fn.
IsSql92FieldNameSyntax fn =>
TablePrefix -> TablePrefix -> fn
qualifiedField TablePrefix
tbl TablePrefix
nm)))

infix 4 <-.
class BeamSqlBackend be =>
  SqlUpdatable be s lhs rhs | rhs -> be, lhs -> s
                            , rhs -> s, lhs s be -> rhs
                            , rhs -> lhs where


  -- | Update a 'QField' or 'Beamable' type containing 'QField's with the given
  --   'QExpr' or 'Beamable' type containing 'QExpr'
  (<-.) :: lhs
        -> rhs
        -> QAssignment be s

instance BeamSqlBackend be => SqlUpdatable be s (QField s a) (QExpr be s a) where
  QField Bool
_ TablePrefix
_ TablePrefix
nm <-. :: QField s a -> QExpr be s a -> QAssignment be s
<-. QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
expr =
    [(BeamSqlBackendFieldNameSyntax be,
  BeamSqlBackendExpressionSyntax be)]
-> QAssignment be s
forall be s.
[(BeamSqlBackendFieldNameSyntax be,
  BeamSqlBackendExpressionSyntax be)]
-> QAssignment be s
QAssignment [(TablePrefix
-> Sql92ExpressionFieldNameSyntax
     (Sql92InsertValuesExpressionSyntax
        (Sql92InsertValuesSyntax
           (Sql92InsertSyntax (BeamSqlBackendSyntax be))))
forall fn. IsSql92FieldNameSyntax fn => TablePrefix -> fn
unqualifiedField TablePrefix
nm, TablePrefix -> BeamSqlBackendExpressionSyntax be
expr TablePrefix
"t")]

instance (BeamSqlBackend be, Beamable tbl) => SqlUpdatable be s (tbl (QField s)) (tbl (QExpr be s)) where
  tbl (QField s)
lhs <-. :: tbl (QField s) -> tbl (QExpr be s) -> QAssignment be s
<-. tbl (QExpr be s)
rhs =
    [(BeamSqlBackendFieldNameSyntax be,
  BeamSqlBackendExpressionSyntax be)]
-> QAssignment be s
forall be s.
[(BeamSqlBackendFieldNameSyntax be,
  BeamSqlBackendExpressionSyntax be)]
-> QAssignment be s
QAssignment ([(BeamSqlBackendFieldNameSyntax be,
   BeamSqlBackendExpressionSyntax be)]
 -> QAssignment be s)
-> [(BeamSqlBackendFieldNameSyntax be,
     BeamSqlBackendExpressionSyntax be)]
-> QAssignment be s
forall a b. (a -> b) -> a -> b
$
    (forall a.
 Columnar'
   (Const
      (Sql92ExpressionFieldNameSyntax
         (Sql92InsertValuesExpressionSyntax
            (Sql92InsertValuesSyntax
               (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
       Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
   a
 -> (Sql92ExpressionFieldNameSyntax
       (Sql92InsertValuesExpressionSyntax
          (Sql92InsertValuesSyntax
             (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
     Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> tbl
     (Const
        (Sql92ExpressionFieldNameSyntax
           (Sql92InsertValuesExpressionSyntax
              (Sql92InsertValuesSyntax
                 (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
         Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> [(Sql92ExpressionFieldNameSyntax
       (Sql92InsertValuesExpressionSyntax
          (Sql92InsertValuesSyntax
             (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
     Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))]
forall (table :: (* -> *) -> *) (f :: * -> *) b.
Beamable table =>
(forall a. Columnar' f a -> b) -> table f -> [b]
allBeamValues (\(Columnar' (Const assignments)) -> (Sql92ExpressionFieldNameSyntax
   (Sql92InsertValuesExpressionSyntax
      (Sql92InsertValuesSyntax
         (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
 Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
assignments) (tbl
   (Const
      (Sql92ExpressionFieldNameSyntax
         (Sql92InsertValuesExpressionSyntax
            (Sql92InsertValuesSyntax
               (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
       Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
 -> [(Sql92ExpressionFieldNameSyntax
        (Sql92InsertValuesExpressionSyntax
           (Sql92InsertValuesSyntax
              (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
      Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))])
-> tbl
     (Const
        (Sql92ExpressionFieldNameSyntax
           (Sql92InsertValuesExpressionSyntax
              (Sql92InsertValuesSyntax
                 (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
         Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> [(Sql92ExpressionFieldNameSyntax
       (Sql92InsertValuesExpressionSyntax
          (Sql92InsertValuesSyntax
             (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
     Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))]
forall a b. (a -> b) -> a -> b
$
    Identity
  (tbl
     (Const
        (Sql92ExpressionFieldNameSyntax
           (Sql92InsertValuesExpressionSyntax
              (Sql92InsertValuesSyntax
                 (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
         Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))))
-> tbl
     (Const
        (Sql92ExpressionFieldNameSyntax
           (Sql92InsertValuesExpressionSyntax
              (Sql92InsertValuesSyntax
                 (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
         Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. Identity a -> a
runIdentity (Identity
   (tbl
      (Const
         (Sql92ExpressionFieldNameSyntax
            (Sql92InsertValuesExpressionSyntax
               (Sql92InsertValuesSyntax
                  (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
          Sql92UpdateExpressionSyntax
            (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))))
 -> tbl
      (Const
         (Sql92ExpressionFieldNameSyntax
            (Sql92InsertValuesExpressionSyntax
               (Sql92InsertValuesSyntax
                  (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
          Sql92UpdateExpressionSyntax
            (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))))
-> Identity
     (tbl
        (Const
           (Sql92ExpressionFieldNameSyntax
              (Sql92InsertValuesExpressionSyntax
                 (Sql92InsertValuesSyntax
                    (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
            Sql92UpdateExpressionSyntax
              (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))))
-> tbl
     (Const
        (Sql92ExpressionFieldNameSyntax
           (Sql92InsertValuesExpressionSyntax
              (Sql92InsertValuesSyntax
                 (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
         Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a b. (a -> b) -> a -> b
$
    (forall a.
 Columnar' (QField s) a
 -> Columnar' (QExpr be s) a
 -> Identity
      (Columnar'
         (Const
            (Sql92ExpressionFieldNameSyntax
               (Sql92InsertValuesExpressionSyntax
                  (Sql92InsertValuesSyntax
                     (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
             Sql92UpdateExpressionSyntax
               (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
         a))
-> tbl (QField s)
-> tbl (QExpr be s)
-> Identity
     (tbl
        (Const
           (Sql92ExpressionFieldNameSyntax
              (Sql92InsertValuesExpressionSyntax
                 (Sql92InsertValuesSyntax
                    (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
            Sql92UpdateExpressionSyntax
              (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))))
forall (table :: (* -> *) -> *) (m :: * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
(Beamable table, Applicative m) =>
(forall a. Columnar' f a -> Columnar' g a -> m (Columnar' h a))
-> table f -> table g -> m (table h)
zipBeamFieldsM (\(Columnar' (QField _ _ f) :: Columnar' (QField s) t) (Columnar' (QExpr e)) ->
                       Columnar'
  (Const
     (Sql92ExpressionFieldNameSyntax
        (Sql92InsertValuesExpressionSyntax
           (Sql92InsertValuesSyntax
              (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
      Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
  a
-> Identity
     (Columnar'
        (Const
           (Sql92ExpressionFieldNameSyntax
              (Sql92InsertValuesExpressionSyntax
                 (Sql92InsertValuesSyntax
                    (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
            Sql92UpdateExpressionSyntax
              (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
        a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Columnar
  (Const
     (Sql92ExpressionFieldNameSyntax
        (Sql92InsertValuesExpressionSyntax
           (Sql92InsertValuesSyntax
              (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
      Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
  a
-> Columnar'
     (Const
        (Sql92ExpressionFieldNameSyntax
           (Sql92InsertValuesExpressionSyntax
              (Sql92InsertValuesSyntax
                 (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
         Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
     a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' ((Sql92ExpressionFieldNameSyntax
   (Sql92InsertValuesExpressionSyntax
      (Sql92InsertValuesSyntax
         (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
 Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Const
     (Sql92ExpressionFieldNameSyntax
        (Sql92InsertValuesExpressionSyntax
           (Sql92InsertValuesSyntax
              (Sql92InsertSyntax (BeamSqlBackendSyntax be)))),
      Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
     a
forall k a (b :: k). a -> Const a b
Const (TablePrefix
-> Sql92ExpressionFieldNameSyntax
     (Sql92InsertValuesExpressionSyntax
        (Sql92InsertValuesSyntax
           (Sql92InsertSyntax (BeamSqlBackendSyntax be))))
forall fn. IsSql92FieldNameSyntax fn => TablePrefix -> fn
unqualifiedField TablePrefix
f, TablePrefix -> BeamSqlBackendExpressionSyntax be
e TablePrefix
"t")) :: Columnar' (Const (BeamSqlBackendFieldNameSyntax be, BeamSqlBackendExpressionSyntax be)) t)) tbl (QField s)
lhs tbl (QExpr be s)
rhs

instance (BeamSqlBackend be, Beamable tbl) => SqlUpdatable be s (tbl (Nullable (QField s))) (tbl (Nullable (QExpr be s))) where
  tbl (Nullable (QField s))
lhs <-. :: tbl (Nullable (QField s))
-> tbl (Nullable (QExpr be s)) -> QAssignment be s
<-. tbl (Nullable (QExpr be s))
rhs =
    let lhs' :: tbl (QField s)
lhs' = (forall a.
 Columnar' (Nullable (QField s)) a -> Columnar' (QField s) a)
-> tbl (Nullable (QField s)) -> tbl (QField s)
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' (QField q tblName fieldName') :: Columnar' (Nullable (QField s)) a) ->
                                Columnar (QField s) a -> Columnar' (QField s) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' (Bool -> TablePrefix -> TablePrefix -> QField s a
forall s ty. Bool -> TablePrefix -> TablePrefix -> QField s ty
QField Bool
q TablePrefix
tblName TablePrefix
fieldName') :: Columnar' (QField s)  a) tbl (Nullable (QField s))
lhs
        rhs' :: tbl (QExpr be s)
rhs' = (forall a.
 Columnar' (Nullable (QExpr be s)) a -> Columnar' (QExpr be s) a)
-> tbl (Nullable (QExpr be s)) -> tbl (QExpr be s)
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' (QExpr e) :: Columnar' (Nullable (QExpr be s)) a) ->
                                Columnar (QExpr be s) a -> Columnar' (QExpr be s) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' ((TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr QValueContext be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e) :: Columnar' (QExpr be s) a) tbl (Nullable (QExpr be s))
rhs
    in tbl (QField s)
lhs' tbl (QField s) -> tbl (QExpr be s) -> QAssignment be s
forall be s lhs rhs.
SqlUpdatable be s lhs rhs =>
lhs -> rhs -> QAssignment be s
<-. tbl (QExpr be s)
rhs'

-- | SQL @UNION@ operator
union_ :: forall be db s a
        . ( BeamSqlBackend be, Projectible be a
          , ThreadRewritable (QNested s) a )
       => Q be db (QNested s) a -> Q be db (QNested s) a
       -> Q be db s (WithRewrittenThread (QNested s) s a)
union_ :: Q be db (QNested s) a
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
union_ (Q QM be db (QNested s) a
a) (Q QM be db (QNested s) a
b) = QM be db s (WithRewrittenThread (QNested s) s a)
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s (WithRewrittenThread (QNested s) s a)
-> QM be db s (WithRewrittenThread (QNested s) s a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) a
-> QM be db (QNested s) a
-> (a -> WithRewrittenThread (QNested s) s a)
-> QF be db s (WithRewrittenThread (QNested s) s a)
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
(BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) r
-> QM be db (QNested s) r
-> (r -> next)
-> QF be db s next
QSetOp (Bool
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
forall select.
IsSql92SelectTableSyntax select =>
Bool -> select -> select -> select
unionTables Bool
False) QM be db (QNested s) a
a QM be db (QNested s) a
b (Proxy s -> a -> WithRewrittenThread (QNested s) s a
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s))))

-- | SQL @UNION ALL@ operator
unionAll_ :: forall be db s a.
             ( BeamSqlBackend be, Projectible be a
             , ThreadRewritable (QNested s) a)
          => Q be db (QNested s) a -> Q be db (QNested s) a
          -> Q be db s (WithRewrittenThread (QNested s) s a)
unionAll_ :: Q be db (QNested s) a
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
unionAll_ (Q QM be db (QNested s) a
a) (Q QM be db (QNested s) a
b) = QM be db s (WithRewrittenThread (QNested s) s a)
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s (WithRewrittenThread (QNested s) s a)
-> QM be db s (WithRewrittenThread (QNested s) s a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) a
-> QM be db (QNested s) a
-> (a -> WithRewrittenThread (QNested s) s a)
-> QF be db s (WithRewrittenThread (QNested s) s a)
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
(BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) r
-> QM be db (QNested s) r
-> (r -> next)
-> QF be db s next
QSetOp (Bool
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
forall select.
IsSql92SelectTableSyntax select =>
Bool -> select -> select -> select
unionTables Bool
True) QM be db (QNested s) a
a QM be db (QNested s) a
b (Proxy s -> a -> WithRewrittenThread (QNested s) s a
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s))))

-- | SQL @INTERSECT@ operator
intersect_ :: forall be db s a.
              ( BeamSqlBackend be, Projectible be a
              , ThreadRewritable (QNested s) a)
           => Q be db (QNested s) a -> Q be db (QNested s) a
           -> Q be db s (WithRewrittenThread (QNested s) s a)
intersect_ :: Q be db (QNested s) a
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
intersect_ (Q QM be db (QNested s) a
a) (Q QM be db (QNested s) a
b) = QM be db s (WithRewrittenThread (QNested s) s a)
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s (WithRewrittenThread (QNested s) s a)
-> QM be db s (WithRewrittenThread (QNested s) s a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) a
-> QM be db (QNested s) a
-> (a -> WithRewrittenThread (QNested s) s a)
-> QF be db s (WithRewrittenThread (QNested s) s a)
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
(BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) r
-> QM be db (QNested s) r
-> (r -> next)
-> QF be db s next
QSetOp (Bool
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
forall select.
IsSql92SelectTableSyntax select =>
Bool -> select -> select -> select
intersectTables Bool
False) QM be db (QNested s) a
a QM be db (QNested s) a
b (Proxy s -> a -> WithRewrittenThread (QNested s) s a
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s))))

-- | SQL @INTERSECT ALL@ operator
intersectAll_ :: forall be db s a.
                 ( BeamSqlBackend be, Projectible be a
                 , ThreadRewritable (QNested s) a)
              => Q be db (QNested s) a -> Q be db (QNested s) a
              -> Q be db s (WithRewrittenThread (QNested s) s a)
intersectAll_ :: Q be db (QNested s) a
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
intersectAll_ (Q QM be db (QNested s) a
a) (Q QM be db (QNested s) a
b) = QM be db s (WithRewrittenThread (QNested s) s a)
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s (WithRewrittenThread (QNested s) s a)
-> QM be db s (WithRewrittenThread (QNested s) s a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) a
-> QM be db (QNested s) a
-> (a -> WithRewrittenThread (QNested s) s a)
-> QF be db s (WithRewrittenThread (QNested s) s a)
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
(BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) r
-> QM be db (QNested s) r
-> (r -> next)
-> QF be db s next
QSetOp (Bool
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
forall select.
IsSql92SelectTableSyntax select =>
Bool -> select -> select -> select
intersectTables Bool
True) QM be db (QNested s) a
a QM be db (QNested s) a
b (Proxy s -> a -> WithRewrittenThread (QNested s) s a
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s))))

-- | SQL @EXCEPT@ operator
except_ :: forall be db s a.
           ( BeamSqlBackend be, Projectible be a
           , ThreadRewritable (QNested s) a)
        => Q be db (QNested s) a -> Q be db (QNested s) a
        -> Q be db s (WithRewrittenThread (QNested s) s a)
except_ :: Q be db (QNested s) a
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
except_ (Q QM be db (QNested s) a
a) (Q QM be db (QNested s) a
b) = QM be db s (WithRewrittenThread (QNested s) s a)
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s (WithRewrittenThread (QNested s) s a)
-> QM be db s (WithRewrittenThread (QNested s) s a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) a
-> QM be db (QNested s) a
-> (a -> WithRewrittenThread (QNested s) s a)
-> QF be db s (WithRewrittenThread (QNested s) s a)
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
(BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) r
-> QM be db (QNested s) r
-> (r -> next)
-> QF be db s next
QSetOp (Bool
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
forall select.
IsSql92SelectTableSyntax select =>
Bool -> select -> select -> select
exceptTable Bool
False) QM be db (QNested s) a
a QM be db (QNested s) a
b (Proxy s -> a -> WithRewrittenThread (QNested s) s a
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s))))

-- | SQL @EXCEPT ALL@ operator
exceptAll_ :: forall be db s a.
              ( BeamSqlBackend be, Projectible be a
              , ThreadRewritable (QNested s) a)
           => Q be db (QNested s) a -> Q be db (QNested s) a
           -> Q be db s (WithRewrittenThread (QNested s) s a)
exceptAll_ :: Q be db (QNested s) a
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
exceptAll_ (Q QM be db (QNested s) a
a) (Q QM be db (QNested s) a
b) = QM be db s (WithRewrittenThread (QNested s) s a)
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s (WithRewrittenThread (QNested s) s a)
-> QM be db s (WithRewrittenThread (QNested s) s a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) a
-> QM be db (QNested s) a
-> (a -> WithRewrittenThread (QNested s) s a)
-> QF be db s (WithRewrittenThread (QNested s) s a)
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
(BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be
 -> BeamSqlBackendSelectTableSyntax be)
-> QM be db (QNested s) r
-> QM be db (QNested s) r
-> (r -> next)
-> QF be db s next
QSetOp (Bool
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
-> BeamSqlBackendSelectTableSyntax be
forall select.
IsSql92SelectTableSyntax select =>
Bool -> select -> select -> select
exceptTable Bool
True) QM be db (QNested s) a
a QM be db (QNested s) a
b (Proxy s -> a -> WithRewrittenThread (QNested s) s a
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s))))

-- | Convenience function that allows you to use type applications to specify
--   the result of a 'QGenExpr'.
--
--   Useful to disambiguate the types of 'QGenExpr's without having to provide a
--   complete type signature. As an example, the 'countAll_' aggregate can
--   return a result of any 'Integral' type. Without further constraints, the
--   type is ambiguous. You can use 'as_' to disambiguate the return type.
--
--   For example, this is ambiguous
--
-- > aggregate_ (\_ -> countAll_) ..
--
--   But this is not
--
-- > aggregate_ (\_ -> as_ @Int32 countAll_) ..
--
as_ :: forall a ctxt be s. QGenExpr ctxt be s a -> QGenExpr ctxt be s a
as_ :: QGenExpr ctxt be s a -> QGenExpr ctxt be s a
as_ = QGenExpr ctxt be s a -> QGenExpr ctxt be s a
forall a. a -> a
id

-- * Marshalling between Haskell literals and QExprs

type family HaskellLiteralForQExpr x = a
type instance HaskellLiteralForQExpr (QGenExpr context be s a) = a
type instance HaskellLiteralForQExpr (table (QGenExpr context be s)) = table Identity
type instance HaskellLiteralForQExpr (table (Nullable f)) = HaskellLiteralForQExpr_AddNullable (HaskellLiteralForQExpr (table f))

type family HaskellLiteralForQExpr_AddNullable x = a
type instance HaskellLiteralForQExpr_AddNullable (tbl f) = tbl (Nullable f)

type SqlValableTable be table =
   ( Beamable table
   , FieldsFulfillConstraint (HasSqlValueSyntax (BeamSqlBackendValueSyntax be)) table )

class SqlValable a where
    val_ :: HaskellLiteralForQExpr a -> a

instance ( BeamSqlBackendCanSerialize be a, BeamSqlBackend be ) =>
  SqlValable (QGenExpr ctxt be s a) where

  val_ :: HaskellLiteralForQExpr (QGenExpr ctxt be s a)
-> QGenExpr ctxt be s a
val_ = (TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> QGenExpr ctxt be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr ((TablePrefix
  -> Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
 -> QGenExpr ctxt be s a)
-> (a
    -> TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> a
-> QGenExpr ctxt be s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (a
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> a
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sql92ExpressionValueSyntax
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (Sql92ExpressionValueSyntax
   (Sql92SelectTableExpressionSyntax
      (Sql92SelectSelectTableSyntax
         (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (a
    -> Sql92ExpressionValueSyntax
         (Sql92SelectTableExpressionSyntax
            (Sql92SelectSelectTableSyntax
               (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))
-> a
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a
-> Sql92ExpressionValueSyntax
     (Sql92SelectTableExpressionSyntax
        (Sql92SelectSelectTableSyntax
           (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax
instance ( Beamable table, BeamSqlBackend be
         , FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table ) =>
  SqlValable (table (QGenExpr ctxt be s)) where
  val_ :: HaskellLiteralForQExpr (table (QGenExpr ctxt be s))
-> table (QGenExpr ctxt be s)
val_ HaskellLiteralForQExpr (table (QGenExpr ctxt be s))
tbl =
    let fields :: table (WithConstraint (BeamSqlBackendCanSerialize be))
        fields :: table (WithConstraint (BeamSqlBackendCanSerialize be))
fields = table Identity
-> table (WithConstraint (BeamSqlBackendCanSerialize be))
forall (c :: * -> Constraint) (tbl :: (* -> *) -> *).
(FieldsFulfillConstraint c tbl, Beamable tbl) =>
tbl Identity -> tbl (WithConstraint c)
withConstrainedFields table Identity
HaskellLiteralForQExpr (table (QGenExpr ctxt be s))
tbl
    in (forall a.
 Columnar' (WithConstraint (BeamSqlBackendCanSerialize be)) a
 -> Columnar' (QGenExpr ctxt be s) a)
-> table (WithConstraint (BeamSqlBackendCanSerialize be))
-> table (QGenExpr ctxt be s)
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' (WithConstraint x :: WithConstraint (BeamSqlBackendCanSerialize be) x)) ->
                         Columnar (QGenExpr ctxt be s) a -> Columnar' (QGenExpr ctxt be s) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' ((TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Sql92ExpressionValueSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (a -> Sql92ExpressionValueSyntax (BeamSqlBackendExpressionSyntax be)
forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax a
x))))) table (WithConstraint (BeamSqlBackendCanSerialize be))
fields
instance ( Beamable table, BeamSqlBackend be
         , FieldsFulfillConstraintNullable (BeamSqlBackendCanSerialize be) table ) =>

         SqlValable (table (Nullable (QGenExpr ctxt be s))) where

  val_ :: HaskellLiteralForQExpr (table (Nullable (QGenExpr ctxt be s)))
-> table (Nullable (QGenExpr ctxt be s))
val_ HaskellLiteralForQExpr (table (Nullable (QGenExpr ctxt be s)))
tbl =
    let fields :: table (Nullable (WithConstraint (BeamSqlBackendCanSerialize be)))
        fields :: table (Nullable (WithConstraint (BeamSqlBackendCanSerialize be)))
fields = table (Nullable Identity)
-> table
     (Nullable (WithConstraint (BeamSqlBackendCanSerialize be)))
forall (c :: * -> Constraint) (tbl :: (* -> *) -> *).
(FieldsFulfillConstraintNullable c tbl, Beamable tbl) =>
tbl (Nullable Identity) -> tbl (Nullable (WithConstraint c))
withNullableConstrainedFields table (Nullable Identity)
HaskellLiteralForQExpr (table (Nullable (QGenExpr ctxt be s)))
tbl
    in (forall a.
 Columnar'
   (Nullable (WithConstraint (BeamSqlBackendCanSerialize be))) a
 -> Columnar' (Nullable (QGenExpr ctxt be s)) a)
-> table
     (Nullable (WithConstraint (BeamSqlBackendCanSerialize be)))
-> table (Nullable (QGenExpr ctxt be s))
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' (WithConstraint x :: WithConstraint (BeamSqlBackendCanSerialize be) (Maybe x))) ->
                         Columnar (Nullable (QGenExpr ctxt be s)) a
-> Columnar' (Nullable (QGenExpr ctxt be s)) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' ((TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s (Maybe a)
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Sql92ExpressionValueSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (Maybe a
-> Sql92ExpressionValueSyntax (BeamSqlBackendExpressionSyntax be)
forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax Maybe a
x))))) table (Nullable (WithConstraint (BeamSqlBackendCanSerialize be)))
fields

default_ :: BeamSqlBackend be => QGenExpr ctxt be s a
default_ :: QGenExpr ctxt be s a
default_ = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr
defaultE)

-- * Window functions

noBounds_ :: QFrameBounds be
noBounds_ :: QFrameBounds be
noBounds_ = Maybe (BeamSqlBackendWindowFrameBoundsSyntax be) -> QFrameBounds be
forall be.
Maybe (BeamSqlBackendWindowFrameBoundsSyntax be) -> QFrameBounds be
QFrameBounds Maybe (BeamSqlBackendWindowFrameBoundsSyntax be)
forall a. Maybe a
Nothing

fromBound_ :: BeamSql2003ExpressionBackend be
           => QFrameBound be -> QFrameBounds be
fromBound_ :: QFrameBound be -> QFrameBounds be
fromBound_ QFrameBound be
start = QFrameBound be -> Maybe (QFrameBound be) -> QFrameBounds be
forall be.
BeamSql2003ExpressionBackend be =>
QFrameBound be -> Maybe (QFrameBound be) -> QFrameBounds be
bounds_ QFrameBound be
start Maybe (QFrameBound be)
forall a. Maybe a
Nothing

bounds_ :: BeamSql2003ExpressionBackend be
        => QFrameBound be
        -> Maybe (QFrameBound be)
        -> QFrameBounds be
bounds_ :: QFrameBound be -> Maybe (QFrameBound be) -> QFrameBounds be
bounds_ (QFrameBound BeamSqlBackendWindowFrameBoundSyntax be
start) Maybe (QFrameBound be)
end =
    Maybe
  (Sql2003WindowFrameBoundsSyntax
     (Sql2003ExpressionWindowFrameSyntax
        (Sql92SelectTableExpressionSyntax
           (Sql92SelectSelectTableSyntax
              (Sql92SelectSyntax (BeamSqlBackendSyntax be))))))
-> QFrameBounds be
forall be.
Maybe (BeamSqlBackendWindowFrameBoundsSyntax be) -> QFrameBounds be
QFrameBounds (Maybe
   (Sql2003WindowFrameBoundsSyntax
      (Sql2003ExpressionWindowFrameSyntax
         (Sql92SelectTableExpressionSyntax
            (Sql92SelectSelectTableSyntax
               (Sql92SelectSyntax (BeamSqlBackendSyntax be))))))
 -> QFrameBounds be)
-> (Sql2003WindowFrameBoundsSyntax
      (Sql2003ExpressionWindowFrameSyntax
         (Sql92SelectTableExpressionSyntax
            (Sql92SelectSelectTableSyntax
               (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))
    -> Maybe
         (Sql2003WindowFrameBoundsSyntax
            (Sql2003ExpressionWindowFrameSyntax
               (Sql92SelectTableExpressionSyntax
                  (Sql92SelectSelectTableSyntax
                     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))))
-> Sql2003WindowFrameBoundsSyntax
     (Sql2003ExpressionWindowFrameSyntax
        (Sql92SelectTableExpressionSyntax
           (Sql92SelectSelectTableSyntax
              (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))
-> QFrameBounds be
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sql2003WindowFrameBoundsSyntax
  (Sql2003ExpressionWindowFrameSyntax
     (Sql92SelectTableExpressionSyntax
        (Sql92SelectSelectTableSyntax
           (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))
-> Maybe
     (Sql2003WindowFrameBoundsSyntax
        (Sql2003ExpressionWindowFrameSyntax
           (Sql92SelectTableExpressionSyntax
              (Sql92SelectSelectTableSyntax
                 (Sql92SelectSyntax (BeamSqlBackendSyntax be))))))
forall a. a -> Maybe a
Just (Sql2003WindowFrameBoundsSyntax
   (Sql2003ExpressionWindowFrameSyntax
      (Sql92SelectTableExpressionSyntax
         (Sql92SelectSelectTableSyntax
            (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))
 -> QFrameBounds be)
-> Sql2003WindowFrameBoundsSyntax
     (Sql2003ExpressionWindowFrameSyntax
        (Sql92SelectTableExpressionSyntax
           (Sql92SelectSelectTableSyntax
              (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))
-> QFrameBounds be
forall a b. (a -> b) -> a -> b
$
    BeamSqlBackendWindowFrameBoundSyntax be
-> Maybe (BeamSqlBackendWindowFrameBoundSyntax be)
-> Sql2003WindowFrameBoundsSyntax
     (Sql2003ExpressionWindowFrameSyntax
        (Sql92SelectTableExpressionSyntax
           (Sql92SelectSelectTableSyntax
              (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))
forall bounds.
IsSql2003WindowFrameBoundsSyntax bounds =>
Sql2003WindowFrameBoundsBoundSyntax bounds
-> Maybe (Sql2003WindowFrameBoundsBoundSyntax bounds) -> bounds
fromToBoundSyntax BeamSqlBackendWindowFrameBoundSyntax be
start
      ((QFrameBound be -> BeamSqlBackendWindowFrameBoundSyntax be)
-> Maybe (QFrameBound be)
-> Maybe (BeamSqlBackendWindowFrameBoundSyntax be)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(QFrameBound BeamSqlBackendWindowFrameBoundSyntax be
end') -> BeamSqlBackendWindowFrameBoundSyntax be
end') Maybe (QFrameBound be)
end)

unbounded_ :: BeamSql2003ExpressionBackend be => QFrameBound be
unbounded_ :: QFrameBound be
unbounded_ = BeamSqlBackendWindowFrameBoundSyntax be -> QFrameBound be
forall be.
BeamSqlBackendWindowFrameBoundSyntax be -> QFrameBound be
QFrameBound BeamSqlBackendWindowFrameBoundSyntax be
forall bound. IsSql2003WindowFrameBoundSyntax bound => bound
unboundedSyntax

nrows_ :: BeamSql2003ExpressionBackend be
       => Int -> QFrameBound be
nrows_ :: Int -> QFrameBound be
nrows_ Int
x = BeamSqlBackendWindowFrameBoundSyntax be -> QFrameBound be
forall be.
BeamSqlBackendWindowFrameBoundSyntax be -> QFrameBound be
QFrameBound (Int -> BeamSqlBackendWindowFrameBoundSyntax be
forall bound. IsSql2003WindowFrameBoundSyntax bound => Int -> bound
nrowsBoundSyntax Int
x)

noPartition_ :: Integral a => Maybe (QExpr be s a)
noPartition_ :: Maybe (QExpr be s a)
noPartition_ = Maybe (QExpr be s a)
forall a. Maybe a
Nothing

noOrder_ :: Integral a => Maybe (QOrd be s a)
noOrder_ :: Maybe (QOrd be s a)
noOrder_ = Maybe (QOrd be s a)
forall a. Maybe a
Nothing

partitionBy_, orderPartitionBy_ :: partition -> Maybe partition
partitionBy_ :: partition -> Maybe partition
partitionBy_  = partition -> Maybe partition
forall a. a -> Maybe a
Just
orderPartitionBy_ :: partition -> Maybe partition
orderPartitionBy_ = partition -> Maybe partition
forall a. a -> Maybe a
Just

-- | Specify a window frame with all the options
frame_ :: forall be ordering partition s
        . ( BeamSql2003ExpressionBackend be
          , SqlOrderable be ordering
          , Projectible be partition )
       => Maybe partition {-^ PARTITION BY -}
       -> Maybe ordering  {-^ ORDER BY -}
       -> QFrameBounds be {-^ RANGE / ROWS -}
       -> QWindow be s
frame_ :: Maybe partition
-> Maybe ordering -> QFrameBounds be -> QWindow be s
frame_ Maybe partition
partition_ Maybe ordering
ordering_ (QFrameBounds Maybe (BeamSqlBackendWindowFrameBoundsSyntax be)
bounds) =
    WithExprContext (BeamSqlBackendWindowFrameSyntax be)
-> QWindow be s
forall be s.
WithExprContext (BeamSqlBackendWindowFrameSyntax be)
-> QWindow be s
QWindow (WithExprContext (BeamSqlBackendWindowFrameSyntax be)
 -> QWindow be s)
-> WithExprContext (BeamSqlBackendWindowFrameSyntax be)
-> QWindow be s
forall a b. (a -> b) -> a -> b
$ \TablePrefix
tblPfx ->
    Maybe
  [Sql2003WindowFrameExpressionSyntax
     (BeamSqlBackendWindowFrameSyntax be)]
-> Maybe
     [Sql2003WindowFrameOrderingSyntax
        (BeamSqlBackendWindowFrameSyntax be)]
-> Maybe (BeamSqlBackendWindowFrameBoundsSyntax be)
-> BeamSqlBackendWindowFrameSyntax be
forall frame.
IsSql2003WindowFrameSyntax frame =>
Maybe [Sql2003WindowFrameExpressionSyntax frame]
-> Maybe [Sql2003WindowFrameOrderingSyntax frame]
-> Maybe (Sql2003WindowFrameBoundsSyntax frame)
-> frame
frameSyntax (case [Sql2003WindowFrameExpressionSyntax
   (BeamSqlBackendWindowFrameSyntax be)]
-> (partition
    -> [Sql2003WindowFrameExpressionSyntax
          (BeamSqlBackendWindowFrameSyntax be)])
-> Maybe partition
-> [Sql2003WindowFrameExpressionSyntax
      (BeamSqlBackendWindowFrameSyntax be)]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] ((partition
 -> TablePrefix
 -> [Sql2003WindowFrameExpressionSyntax
       (BeamSqlBackendWindowFrameSyntax be)])
-> TablePrefix
-> partition
-> [Sql2003WindowFrameExpressionSyntax
      (BeamSqlBackendWindowFrameSyntax be)]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Proxy be
-> partition -> WithExprContext [BeamSqlBackendExpressionSyntax be]
forall be a.
Projectible be a =>
Proxy be
-> a -> WithExprContext [BeamSqlBackendExpressionSyntax be]
project (Proxy be
forall k (t :: k). Proxy t
Proxy @be)) TablePrefix
tblPfx) Maybe partition
partition_ of
                   [] -> Maybe
  [Sql2003WindowFrameExpressionSyntax
     (BeamSqlBackendWindowFrameSyntax be)]
forall a. Maybe a
Nothing
                   [Sql2003WindowFrameExpressionSyntax
   (BeamSqlBackendWindowFrameSyntax be)]
xs -> [Sql2003WindowFrameExpressionSyntax
   (BeamSqlBackendWindowFrameSyntax be)]
-> Maybe
     [Sql2003WindowFrameExpressionSyntax
        (BeamSqlBackendWindowFrameSyntax be)]
forall a. a -> Maybe a
Just [Sql2003WindowFrameExpressionSyntax
   (BeamSqlBackendWindowFrameSyntax be)]
xs)
                (case (ordering
 -> [TablePrefix
     -> Sql2003WindowFrameOrderingSyntax
          (BeamSqlBackendWindowFrameSyntax be)])
-> Maybe ordering
-> Maybe
     [TablePrefix
      -> Sql2003WindowFrameOrderingSyntax
           (BeamSqlBackendWindowFrameSyntax be)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Proxy be
-> ordering -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering (Proxy be
forall k (t :: k). Proxy t
Proxy @be)) Maybe ordering
ordering_ of
                   Maybe
  [TablePrefix
   -> Sql2003WindowFrameOrderingSyntax
        (BeamSqlBackendWindowFrameSyntax be)]
Nothing -> Maybe
  [Sql2003WindowFrameOrderingSyntax
     (BeamSqlBackendWindowFrameSyntax be)]
forall a. Maybe a
Nothing
                   Just [] -> Maybe
  [Sql2003WindowFrameOrderingSyntax
     (BeamSqlBackendWindowFrameSyntax be)]
forall a. Maybe a
Nothing
                   Just [TablePrefix
 -> Sql2003WindowFrameOrderingSyntax
      (BeamSqlBackendWindowFrameSyntax be)]
xs -> [Sql2003WindowFrameOrderingSyntax
   (BeamSqlBackendWindowFrameSyntax be)]
-> Maybe
     [Sql2003WindowFrameOrderingSyntax
        (BeamSqlBackendWindowFrameSyntax be)]
forall a. a -> Maybe a
Just ([TablePrefix
 -> Sql2003WindowFrameOrderingSyntax
      (BeamSqlBackendWindowFrameSyntax be)]
-> TablePrefix
-> [Sql2003WindowFrameOrderingSyntax
      (BeamSqlBackendWindowFrameSyntax be)]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [TablePrefix
 -> Sql2003WindowFrameOrderingSyntax
      (BeamSqlBackendWindowFrameSyntax be)]
xs TablePrefix
tblPfx))
                Maybe (BeamSqlBackendWindowFrameBoundsSyntax be)
bounds

-- | Produce a window expression given an aggregate function and a window.
over_ :: BeamSql2003ExpressionBackend be
      => QAgg be s a -> QWindow be s -> QWindowExpr be s a
over_ :: QAgg be s a -> QWindow be s -> QWindowExpr be s a
over_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
a) (QWindow WithExprContext (BeamSqlBackendWindowFrameSyntax be)
frame) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QWindowExpr be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql2003WindowFrameExpressionSyntax
  (BeamSqlBackendWindowFrameSyntax be)
-> BeamSqlBackendWindowFrameSyntax be
-> Sql2003WindowFrameExpressionSyntax
     (BeamSqlBackendWindowFrameSyntax be)
forall expr.
IsSql2003ExpressionSyntax expr =>
expr -> Sql2003ExpressionWindowFrameSyntax expr -> expr
overE (Sql2003WindowFrameExpressionSyntax
   (BeamSqlBackendWindowFrameSyntax be)
 -> BeamSqlBackendWindowFrameSyntax be
 -> Sql2003WindowFrameExpressionSyntax
      (BeamSqlBackendWindowFrameSyntax be))
-> (TablePrefix
    -> Sql2003WindowFrameExpressionSyntax
         (BeamSqlBackendWindowFrameSyntax be))
-> TablePrefix
-> BeamSqlBackendWindowFrameSyntax be
-> Sql2003WindowFrameExpressionSyntax
     (BeamSqlBackendWindowFrameSyntax be)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix -> BeamSqlBackendExpressionSyntax be
TablePrefix
-> Sql2003WindowFrameExpressionSyntax
     (BeamSqlBackendWindowFrameSyntax be)
a (TablePrefix
 -> BeamSqlBackendWindowFrameSyntax be
 -> Sql2003WindowFrameExpressionSyntax
      (BeamSqlBackendWindowFrameSyntax be))
-> WithExprContext (BeamSqlBackendWindowFrameSyntax be)
-> TablePrefix
-> Sql2003WindowFrameExpressionSyntax
     (BeamSqlBackendWindowFrameSyntax be)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> WithExprContext (BeamSqlBackendWindowFrameSyntax be)
frame)

-- | Compute a query over windows.
--
--   The first function builds window frames using the 'frame_', 'partitionBy_',
--   etc functions. The return type can be a single frame, tuples of frame, or
--   any arbitrarily nested tuple of the above. Instances up to 8-tuples are
--   provided.
--
--   The second function builds the resulting projection using the result of the
--   subquery as well as the window frames built in the first function. In this
--   function, window expressions can be included in the output using the
--   'over_' function.
--
withWindow_ :: forall window a s r be db
             . ( ProjectibleWithPredicate WindowFrameContext be (WithExprContext (BeamSqlBackendWindowFrameSyntax' be)) window
               , Projectible be r, Projectible be a
               , ContextRewritable a
               , ThreadRewritable (QNested s) (WithRewrittenContext a QValueContext) )
            => (r -> window)      -- ^ Window builder function
            -> (r -> window -> a) -- ^ Projection builder function. Has access to the windows generated above
            -> Q be db (QNested s) r -- ^ Query to window over
            -> Q be db s (WithRewrittenThread (QNested s) s (WithRewrittenContext a QValueContext))
withWindow_ :: (r -> window)
-> (r -> window -> a)
-> Q be db (QNested s) r
-> Q be
     db
     s
     (WithRewrittenThread
        (QNested s) s (WithRewrittenContext a QValueContext))
withWindow_ r -> window
mkWindow r -> window -> a
mkProjection (Q QM be db (QNested s) r
windowOver)=
  QM
  be
  db
  s
  (WithRewrittenThread
     (QNested s) s (WithRewrittenContext a QValueContext))
-> Q be
     db
     s
     (WithRewrittenThread
        (QNested s) s (WithRewrittenContext a QValueContext))
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF
  be
  db
  s
  (WithRewrittenThread
     (QNested s) s (WithRewrittenContext a QValueContext))
-> QM
     be
     db
     s
     (WithRewrittenThread
        (QNested s) s (WithRewrittenContext a QValueContext))
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((r -> window)
-> (r -> window -> a)
-> QM be db (QNested s) r
-> (a
    -> WithRewrittenThread
         (QNested s) s (WithRewrittenContext a QValueContext))
-> QF
     be
     db
     s
     (WithRewrittenThread
        (QNested s) s (WithRewrittenContext a QValueContext))
forall be window r a (db :: (* -> *) -> *) s next.
(ProjectibleWithPredicate
   WindowFrameContext
   be
   (WithExprContext (BeamSqlBackendWindowFrameSyntax' be))
   window,
 Projectible be r, Projectible be a) =>
(r -> window)
-> (r -> window -> a)
-> QM be db (QNested s) r
-> (a -> next)
-> QF be db s next
QWindowOver r -> window
mkWindow r -> window -> a
mkProjection QM be db (QNested s) r
windowOver (Proxy s
-> WithRewrittenContext a QValueContext
-> WithRewrittenThread
     (QNested s) s (WithRewrittenContext a QValueContext)
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s) (WithRewrittenContext a QValueContext
 -> WithRewrittenThread
      (QNested s) s (WithRewrittenContext a QValueContext))
-> (a -> WithRewrittenContext a QValueContext)
-> a
-> WithRewrittenThread
     (QNested s) s (WithRewrittenContext a QValueContext)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy QValueContext -> a -> WithRewrittenContext a QValueContext
forall a ctxt.
ContextRewritable a =>
Proxy ctxt -> a -> WithRewrittenContext a ctxt
rewriteContext (Proxy QValueContext
forall k (t :: k). Proxy t
Proxy @QValueContext))))

-- * Order bys

class SqlOrderable be a | a -> be where
    makeSQLOrdering :: Proxy be -> a -> [ WithExprContext (BeamSqlBackendOrderingSyntax be) ]
instance SqlOrderable be (QOrd be s a) where
    makeSQLOrdering :: Proxy be
-> QOrd be s a
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
_ (QOrd WithExprContext (BeamSqlBackendOrderingSyntax be)
x) = [WithExprContext (BeamSqlBackendOrderingSyntax be)
x]
instance TypeError ('Text "Missing mandatory sorting order. Use either 'asc_' or 'desc_' to specify sorting order.") =>
    SqlOrderable be (QGenExpr ctx be s a) where
        makeSQLOrdering :: Proxy be
-> QGenExpr ctx be s a
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering = [Char]
-> Proxy be
-> QGenExpr ctx be s a
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. HasCallStack => [Char] -> a
error [Char]
"unreachable SqlOrderable QGenExpr instance"
instance SqlOrderable be a => SqlOrderable be [a] where
    makeSQLOrdering :: Proxy be
-> [a] -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be = (a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)])
-> [a] -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be)
instance ( SqlOrderable be a, SqlOrderable be b ) => SqlOrderable be (a, b) where
    makeSQLOrdering :: Proxy be
-> (a, b) -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be (a
a, b
b) =
      Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be a
a [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> b -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be b
b
instance ( SqlOrderable be a, SqlOrderable be b
         , SqlOrderable be c ) => SqlOrderable be (a, b, c) where
    makeSQLOrdering :: Proxy be
-> (a, b, c) -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be (a
a, b
b, c
c) =
      Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be a
a [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> b -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be b
b [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> c -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be c
c
instance ( SqlOrderable be a, SqlOrderable be b
         , SqlOrderable be c, SqlOrderable be d ) => SqlOrderable be (a, b, c, d) where
    makeSQLOrdering :: Proxy be
-> (a, b, c, d)
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be (a
a, b
b, c
c, d
d) =
      Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be a
a [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> b -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be b
b [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> c -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be c
c [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> d -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be d
d
instance ( SqlOrderable be a, SqlOrderable be b
         , SqlOrderable be c, SqlOrderable be d
         , SqlOrderable be e ) => SqlOrderable be (a, b, c, d, e) where
    makeSQLOrdering :: Proxy be
-> (a, b, c, d, e)
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be (a
a, b
b, c
c, d
d, e
e) =
      Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be a
a [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> b -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be b
b [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> c -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be c
c [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> d -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be d
d [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<>
      Proxy be
-> e -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be e
e
instance ( SqlOrderable be a, SqlOrderable be b
         , SqlOrderable be c, SqlOrderable be d
         , SqlOrderable be e, SqlOrderable be f ) => SqlOrderable be (a, b, c, d, e, f) where
    makeSQLOrdering :: Proxy be
-> (a, b, c, d, e, f)
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be (a
a, b
b, c
c, d
d, e
e, f
f) =
      Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be a
a [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> b -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be b
b [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> c -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be c
c [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> d -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be d
d [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<>
      Proxy be
-> e -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be e
e [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> f -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be f
f
instance ( SqlOrderable be a, SqlOrderable be b
         , SqlOrderable be c, SqlOrderable be d
         , SqlOrderable be e, SqlOrderable be f
         , SqlOrderable be g ) => SqlOrderable be (a, b, c, d, e, f, g) where
    makeSQLOrdering :: Proxy be
-> (a, b, c, d, e, f, g)
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be (a
a, b
b, c
c, d
d, e
e, f
f, g
g) =
      Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be a
a [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> b -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be b
b [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> c -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be c
c [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> d -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be d
d [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<>
      Proxy be
-> e -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be e
e [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> f -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be f
f [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> g -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be g
g
instance ( SqlOrderable be a, SqlOrderable be b
         , SqlOrderable be c, SqlOrderable be d
         , SqlOrderable be e, SqlOrderable be f
         , SqlOrderable be g, SqlOrderable be h ) => SqlOrderable be (a, b, c, d, e, f, g, h) where
    makeSQLOrdering :: Proxy be
-> (a, b, c, d, e, f, g, h)
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h) =
      Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be a
a [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> b -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be b
b [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> c -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be c
c [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> d -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be d
d [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<>
      Proxy be
-> e -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be e
e [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> f -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be f
f [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> g -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be g
g [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
-> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall a. Semigroup a => a -> a -> a
<> Proxy be
-> h -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering Proxy be
be h
h

-- | Order by the given expressions. The return type of the ordering key should
--   either be the result of 'asc_' or 'desc_' (or another ordering 'QOrd'
--   generated by a backend-specific ordering) or an (possibly nested) tuple of
--   results of the former.
--
--   The <https://haskell-beam.github.io/beam/user-guide/queries/ordering manual section>
--   has more information.
orderBy_ :: forall s a ordering be db
          . ( Projectible be a, SqlOrderable be ordering
            , ThreadRewritable (QNested s) a )
         => (a -> ordering) -> Q be db (QNested s) a -> Q be db s (WithRewrittenThread (QNested s) s a)
orderBy_ :: (a -> ordering)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
orderBy_ a -> ordering
orderer (Q QM be db (QNested s) a
q) =
    QM be db s (WithRewrittenThread (QNested s) s a)
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall be (db :: (* -> *) -> *) s a. QM be db s a -> Q be db s a
Q (QF be db s (WithRewrittenThread (QNested s) s a)
-> QM be db s (WithRewrittenThread (QNested s) s a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ((a -> WithExprContext [BeamSqlBackendOrderingSyntax be])
-> QM be db (QNested s) a
-> (a -> WithRewrittenThread (QNested s) s a)
-> QF be db s (WithRewrittenThread (QNested s) s a)
forall be r (db :: (* -> *) -> *) s next.
Projectible be r =>
(r -> WithExprContext [BeamSqlBackendOrderingSyntax be])
-> QM be db (QNested s) r -> (r -> next) -> QF be db s next
QOrderBy ([TablePrefix -> BeamSqlBackendOrderingSyntax be]
-> WithExprContext [BeamSqlBackendOrderingSyntax be]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ([TablePrefix -> BeamSqlBackendOrderingSyntax be]
 -> WithExprContext [BeamSqlBackendOrderingSyntax be])
-> (a -> [TablePrefix -> BeamSqlBackendOrderingSyntax be])
-> a
-> WithExprContext [BeamSqlBackendOrderingSyntax be]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy be
-> ordering -> [TablePrefix -> BeamSqlBackendOrderingSyntax be]
forall be a.
SqlOrderable be a =>
Proxy be
-> a -> [WithExprContext (BeamSqlBackendOrderingSyntax be)]
makeSQLOrdering (Proxy be
forall k (t :: k). Proxy t
Proxy @be) (ordering -> [TablePrefix -> BeamSqlBackendOrderingSyntax be])
-> (a -> ordering)
-> a
-> [TablePrefix -> BeamSqlBackendOrderingSyntax be]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ordering
orderer) QM be db (QNested s) a
q (Proxy s -> a -> WithRewrittenThread (QNested s) s a
forall s a s'.
ThreadRewritable s a =>
Proxy s' -> a -> WithRewrittenThread s s' a
rewriteThread (Proxy s
forall k (t :: k). Proxy t
Proxy @s))))

nullsFirst_ :: IsSql2003OrderingElementaryOLAPOperationsSyntax (BeamSqlBackendOrderingSyntax be)
            => QOrd be s a -> QOrd be s a
nullsFirst_ :: QOrd be s a -> QOrd be s a
nullsFirst_ (QOrd TablePrefix -> BeamSqlBackendOrderingSyntax be
e) = (TablePrefix -> BeamSqlBackendOrderingSyntax be) -> QOrd be s a
forall be s t.
(TablePrefix -> BeamSqlBackendOrderingSyntax be) -> QOrd be s t
QOrd (BeamSqlBackendOrderingSyntax be -> BeamSqlBackendOrderingSyntax be
forall ord.
IsSql2003OrderingElementaryOLAPOperationsSyntax ord =>
ord -> ord
nullsFirstOrdering (BeamSqlBackendOrderingSyntax be
 -> BeamSqlBackendOrderingSyntax be)
-> (TablePrefix -> BeamSqlBackendOrderingSyntax be)
-> TablePrefix
-> BeamSqlBackendOrderingSyntax be
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix -> BeamSqlBackendOrderingSyntax be
e)

nullsLast_ :: IsSql2003OrderingElementaryOLAPOperationsSyntax (BeamSqlBackendOrderingSyntax be)
           => QOrd be s a -> QOrd be s a
nullsLast_ :: QOrd be s a -> QOrd be s a
nullsLast_ (QOrd TablePrefix -> BeamSqlBackendOrderingSyntax be
e) = (TablePrefix -> BeamSqlBackendOrderingSyntax be) -> QOrd be s a
forall be s t.
(TablePrefix -> BeamSqlBackendOrderingSyntax be) -> QOrd be s t
QOrd (BeamSqlBackendOrderingSyntax be -> BeamSqlBackendOrderingSyntax be
forall ord.
IsSql2003OrderingElementaryOLAPOperationsSyntax ord =>
ord -> ord
nullsLastOrdering (BeamSqlBackendOrderingSyntax be
 -> BeamSqlBackendOrderingSyntax be)
-> (TablePrefix -> BeamSqlBackendOrderingSyntax be)
-> TablePrefix
-> BeamSqlBackendOrderingSyntax be
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix -> BeamSqlBackendOrderingSyntax be
e)

-- | Produce a 'QOrd' corresponding to a SQL @ASC@ ordering
asc_ :: forall be s a
      . BeamSqlBackend be
     => QExpr be s a -> QOrd be s a
asc_ :: QExpr be s a -> QOrd be s a
asc_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e) = (TablePrefix -> BeamSqlBackendOrderingSyntax be) -> QOrd be s a
forall be s t.
(TablePrefix -> BeamSqlBackendOrderingSyntax be) -> QOrd be s t
QOrd (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> BeamSqlBackendOrderingSyntax be
forall ord.
IsSql92OrderingSyntax ord =>
Sql92OrderingExpressionSyntax ord -> ord
ascOrdering (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> BeamSqlBackendOrderingSyntax be)
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> BeamSqlBackendOrderingSyntax be
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
e)

-- | Produce a 'QOrd' corresponding to a SQL @DESC@ ordering
desc_ :: forall be s a
       . BeamSqlBackend be
      => QExpr be s a -> QOrd be s a
desc_ :: QExpr be s a -> QOrd be s a
desc_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e) = (TablePrefix -> BeamSqlBackendOrderingSyntax be) -> QOrd be s a
forall be s t.
(TablePrefix -> BeamSqlBackendOrderingSyntax be) -> QOrd be s t
QOrd (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> BeamSqlBackendOrderingSyntax be
forall ord.
IsSql92OrderingSyntax ord =>
Sql92OrderingExpressionSyntax ord -> ord
descOrdering (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> BeamSqlBackendOrderingSyntax be)
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> BeamSqlBackendOrderingSyntax be
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
e)

-- * Subqueries

-- * Nullable conversions

-- | Type class for things that can be nullable. This includes 'QExpr (Maybe a)', 'tbl (Nullable
-- QExpr)', and 'PrimaryKey tbl (Nullable QExpr)'
class SqlJustable a b | b -> a where

    -- | Given something of type 'QExpr a', 'tbl QExpr', or 'PrimaryKey tbl
    --   QExpr', turn it into a 'QExpr (Maybe a)', 'tbl (Nullable QExpr)', or
    --   'PrimaryKey t (Nullable QExpr)' respectively that contains the same
    --   values.
    just_ :: a -> b

    -- | Return either a 'QExpr (Maybe x)' representing 'Nothing' or a nullable 'Table' or
    --   'PrimaryKey' filled with 'Nothing'.
    nothing_ :: b

instance BeamSqlBackend be =>
    SqlJustable (QExpr be s a) (QExpr be s (Maybe a)) where

    just_ :: QExpr be s a -> QExpr be s (Maybe a)
just_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QExpr be s (Maybe a)
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e
    nothing_ :: QExpr be s (Maybe a)
nothing_ = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QExpr be s (Maybe a)
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Sql92ExpressionValueSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (SqlNull
-> Sql92ExpressionValueSyntax (BeamSqlBackendExpressionSyntax be)
forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax SqlNull
SqlNull)))

instance {-# OVERLAPPING #-} ( Table t, BeamSqlBackend be ) =>
    SqlJustable (PrimaryKey t (QExpr be s)) (PrimaryKey t (Nullable (QExpr be s))) where
    just_ :: PrimaryKey t (QExpr be s) -> PrimaryKey t (Nullable (QExpr be s))
just_ = (forall a.
 Columnar' (QExpr be s) a -> Columnar' (Nullable (QExpr be s)) a)
-> PrimaryKey t (QExpr be s)
-> PrimaryKey t (Nullable (QExpr be s))
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' Columnar (QExpr be s) a
q) -> Columnar (Nullable (QExpr be s)) a
-> Columnar' (Nullable (QExpr be s)) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' (QGenExpr QValueContext be s a
-> QGenExpr QValueContext be s (Maybe a)
forall a b. SqlJustable a b => a -> b
just_ Columnar (QExpr be s) a
QGenExpr QValueContext be s a
q))
    nothing_ :: PrimaryKey t (Nullable (QExpr be s))
nothing_ = (forall a.
 Columnar' Ignored a -> Columnar' (Nullable (QExpr be s)) a)
-> PrimaryKey t Ignored -> PrimaryKey t (Nullable (QExpr be s))
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' Columnar Ignored a
_) -> Columnar (Nullable (QExpr be s)) a
-> Columnar' (Nullable (QExpr be s)) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' Columnar (Nullable (QExpr be s)) a
forall a b. SqlJustable a b => b
nothing_) (t Ignored -> PrimaryKey t Ignored
forall (table :: (* -> *) -> *) (column :: * -> *).
Table table =>
table column -> PrimaryKey table column
primaryKey (t Ignored
forall (table :: (* -> *) -> *).
Beamable table =>
TableSkeleton table
tblSkeleton :: TableSkeleton t))

instance {-# OVERLAPPING #-} ( Table t, BeamSqlBackend be ) =>
    SqlJustable (t (QExpr be s)) (t (Nullable (QExpr be s))) where
    just_ :: t (QExpr be s) -> t (Nullable (QExpr be s))
just_ = (forall a.
 Columnar' (QExpr be s) a -> Columnar' (Nullable (QExpr be s)) a)
-> t (QExpr be s) -> t (Nullable (QExpr be s))
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' Columnar (QExpr be s) a
q) -> Columnar (Nullable (QExpr be s)) a
-> Columnar' (Nullable (QExpr be s)) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' (QGenExpr QValueContext be s a
-> QGenExpr QValueContext be s (Maybe a)
forall a b. SqlJustable a b => a -> b
just_ Columnar (QExpr be s) a
QGenExpr QValueContext be s a
q))
    nothing_ :: t (Nullable (QExpr be s))
nothing_ = (forall a.
 Columnar' Ignored a -> Columnar' (Nullable (QExpr be s)) a)
-> t Ignored -> t (Nullable (QExpr be s))
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' Columnar Ignored a
_) -> Columnar (Nullable (QExpr be s)) a
-> Columnar' (Nullable (QExpr be s)) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' Columnar (Nullable (QExpr be s)) a
forall a b. SqlJustable a b => b
nothing_) (t Ignored
forall (table :: (* -> *) -> *).
Beamable table =>
TableSkeleton table
tblSkeleton :: TableSkeleton t)

instance {-# OVERLAPPING #-} Table t => SqlJustable (PrimaryKey t Identity) (PrimaryKey t (Nullable Identity)) where
    just_ :: PrimaryKey t Identity -> PrimaryKey t (Nullable Identity)
just_ = (forall a. Columnar' Identity a -> Columnar' (Nullable Identity) a)
-> PrimaryKey t Identity -> PrimaryKey t (Nullable Identity)
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' Columnar Identity a
q) -> Columnar (Nullable Identity) a -> Columnar' (Nullable Identity) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' (a -> Maybe a
forall a. a -> Maybe a
Just a
Columnar Identity a
q))
    nothing_ :: PrimaryKey t (Nullable Identity)
nothing_ = (forall a. Columnar' Ignored a -> Columnar' (Nullable Identity) a)
-> PrimaryKey t Ignored -> PrimaryKey t (Nullable Identity)
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' Columnar Ignored a
_) -> Columnar (Nullable Identity) a -> Columnar' (Nullable Identity) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' Columnar (Nullable Identity) a
forall a. Maybe a
Nothing) (t Ignored -> PrimaryKey t Ignored
forall (table :: (* -> *) -> *) (column :: * -> *).
Table table =>
table column -> PrimaryKey table column
primaryKey (t Ignored
forall (table :: (* -> *) -> *).
Beamable table =>
TableSkeleton table
tblSkeleton :: TableSkeleton t))

instance {-# OVERLAPPING #-} Table t => SqlJustable (t Identity) (t (Nullable Identity)) where
    just_ :: t Identity -> t (Nullable Identity)
just_ = (forall a. Columnar' Identity a -> Columnar' (Nullable Identity) a)
-> t Identity -> t (Nullable Identity)
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' Columnar Identity a
q) -> Columnar (Nullable Identity) a -> Columnar' (Nullable Identity) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' (a -> Maybe a
forall a. a -> Maybe a
Just a
Columnar Identity a
q))
    nothing_ :: t (Nullable Identity)
nothing_ = (forall a. Columnar' Ignored a -> Columnar' (Nullable Identity) a)
-> t Ignored -> t (Nullable Identity)
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' Columnar Ignored a
_) -> Columnar (Nullable Identity) a -> Columnar' (Nullable Identity) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' Columnar (Nullable Identity) a
forall a. Maybe a
Nothing) (t Ignored
forall (table :: (* -> *) -> *).
Beamable table =>
TableSkeleton table
tblSkeleton :: TableSkeleton t)

-- * Nullable checking

data QIfCond context be s a = QIfCond (QGenExpr context be s SqlBool) (QGenExpr context be s a)
newtype QIfElse context be s a = QIfElse (QGenExpr context be s a)

then_ :: QGenExpr context be s Bool -> QGenExpr context be s a -> QIfCond context be s a
then_ :: QGenExpr context be s Bool
-> QGenExpr context be s a -> QIfCond context be s a
then_ QGenExpr context be s Bool
cond QGenExpr context be s a
res = QGenExpr context be s SqlBool
-> QGenExpr context be s a -> QIfCond context be s a
forall context be s a.
QGenExpr context be s SqlBool
-> QGenExpr context be s a -> QIfCond context be s a
QIfCond (QGenExpr context be s Bool -> QGenExpr context be s SqlBool
forall context syntax s.
QGenExpr context syntax s Bool -> QGenExpr context syntax s SqlBool
sqlBool_ QGenExpr context be s Bool
cond) QGenExpr context be s a
res

then_' :: QGenExpr context be s SqlBool -> QGenExpr context be s a -> QIfCond context be s a
then_' :: QGenExpr context be s SqlBool
-> QGenExpr context be s a -> QIfCond context be s a
then_' QGenExpr context be s SqlBool
cond QGenExpr context be s a
res = QGenExpr context be s SqlBool
-> QGenExpr context be s a -> QIfCond context be s a
forall context be s a.
QGenExpr context be s SqlBool
-> QGenExpr context be s a -> QIfCond context be s a
QIfCond QGenExpr context be s SqlBool
cond QGenExpr context be s a
res

else_ :: QGenExpr context be s a -> QIfElse context be s a
else_ :: QGenExpr context be s a -> QIfElse context be s a
else_ = QGenExpr context be s a -> QIfElse context be s a
forall context be s a.
QGenExpr context be s a -> QIfElse context be s a
QIfElse

if_ :: BeamSqlBackend be
    => [ QIfCond context be s a ]
    -> QIfElse context be s a
    -> QGenExpr context be s a
if_ :: [QIfCond context be s a]
-> QIfElse context be s a -> QGenExpr context be s a
if_ [QIfCond context be s a]
conds (QIfElse (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
elseExpr)) =
  (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\TablePrefix
tbl -> [(Sql92UpdateExpressionSyntax
    (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
  Sql92UpdateExpressionSyntax
    (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
[(expr, expr)] -> expr -> expr
caseE ((QIfCond context be s a
 -> (Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
     Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> [QIfCond context be s a]
-> [(Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
     Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))]
forall a b. (a -> b) -> [a] -> [b]
map (\(QIfCond (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
cond) (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
res)) -> (TablePrefix -> BeamSqlBackendExpressionSyntax be
cond TablePrefix
tbl, TablePrefix -> BeamSqlBackendExpressionSyntax be
res TablePrefix
tbl)) [QIfCond context be s a]
conds) (TablePrefix -> BeamSqlBackendExpressionSyntax be
elseExpr TablePrefix
tbl))

ifThenElse_
  :: BeamSqlBackend be
  => QGenExpr context be s Bool
  -> QGenExpr context be s a
  -> QGenExpr context be s a
  -> QGenExpr context be s a
ifThenElse_ :: QGenExpr context be s Bool
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s a
ifThenElse_ QGenExpr context be s Bool
c QGenExpr context be s a
t QGenExpr context be s a
f = [QIfCond context be s a]
-> QIfElse context be s a -> QGenExpr context be s a
forall be context s a.
BeamSqlBackend be =>
[QIfCond context be s a]
-> QIfElse context be s a -> QGenExpr context be s a
if_ [QGenExpr context be s Bool
c QGenExpr context be s Bool
-> QGenExpr context be s a -> QIfCond context be s a
forall context be s a.
QGenExpr context be s Bool
-> QGenExpr context be s a -> QIfCond context be s a
`then_` QGenExpr context be s a
t] (QGenExpr context be s a -> QIfElse context be s a
forall context be s a.
QGenExpr context be s a -> QIfElse context be s a
else_ QGenExpr context be s a
f)

bool_
  :: BeamSqlBackend be
  => QGenExpr context be s a
  -> QGenExpr context be s a
  -> QGenExpr context be s Bool
  -> QGenExpr context be s a
bool_ :: QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s Bool
-> QGenExpr context be s a
bool_ QGenExpr context be s a
f QGenExpr context be s a
t QGenExpr context be s Bool
c = QGenExpr context be s Bool
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s a
forall be context s a.
BeamSqlBackend be =>
QGenExpr context be s Bool
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s a
ifThenElse_ QGenExpr context be s Bool
c QGenExpr context be s a
t QGenExpr context be s a
f

-- | SQL @COALESCE@ support
coalesce_ :: BeamSqlBackend be
          => [ QGenExpr ctxt be s (Maybe a) ] -> QGenExpr ctxt be s a -> QGenExpr ctxt be s a
coalesce_ :: [QGenExpr ctxt be s (Maybe a)]
-> QGenExpr ctxt be s a -> QGenExpr ctxt be s a
coalesce_ [QGenExpr ctxt be s (Maybe a)]
qs (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
onNull) =
  (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr ((TablePrefix -> BeamSqlBackendExpressionSyntax be)
 -> QGenExpr ctxt be s a)
-> (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s a
forall a b. (a -> b) -> a -> b
$ do
    Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
onNull' <- TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
onNull
    [Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => [expr] -> expr
coalesceE ([Sql92UpdateExpressionSyntax
    (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> ([Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
    -> [Sql92UpdateExpressionSyntax
          (Sql92UpdateSyntax (BeamSqlBackendSyntax be))])
-> [Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> [Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> [Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
forall a. Semigroup a => a -> a -> a
<> [Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
onNull']) ([Sql92UpdateExpressionSyntax
    (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> [Sql92UpdateExpressionSyntax
          (Sql92UpdateSyntax (BeamSqlBackendSyntax be))])
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (QGenExpr ctxt be s (Maybe a)
 -> TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> [QGenExpr ctxt be s (Maybe a)]
-> TablePrefix
-> [Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
q) -> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
q) [QGenExpr ctxt be s (Maybe a)]
qs

-- | Convert a 'Maybe' value to a concrete value, by suppling a default
fromMaybe_ :: BeamSqlBackend be
           => QGenExpr ctxt be s a -> QGenExpr ctxt be s (Maybe a) -> QGenExpr ctxt be s a
fromMaybe_ :: QGenExpr ctxt be s a
-> QGenExpr ctxt be s (Maybe a) -> QGenExpr ctxt be s a
fromMaybe_ QGenExpr ctxt be s a
onNull QGenExpr ctxt be s (Maybe a)
q = [QGenExpr ctxt be s (Maybe a)]
-> QGenExpr ctxt be s a -> QGenExpr ctxt be s a
forall be ctxt s a.
BeamSqlBackend be =>
[QGenExpr ctxt be s (Maybe a)]
-> QGenExpr ctxt be s a -> QGenExpr ctxt be s a
coalesce_ [QGenExpr ctxt be s (Maybe a)
q] QGenExpr ctxt be s a
onNull

-- | Type class for anything which can be checked for null-ness. This includes 'QExpr (Maybe a)' as
-- well as 'Table's or 'PrimaryKey's over 'Nullable QExpr'.
class BeamSqlBackend be => SqlDeconstructMaybe be a nonNullA s | a s -> be, a -> nonNullA, a -> s, nonNullA -> s where
    -- | Returns a 'QExpr' that evaluates to true when the first argument is not null
    isJust_ :: a -> QGenExpr ctxt be s Bool

    -- | Returns a 'QExpr' that evaluates to true when the first argument is null
    isNothing_ :: a -> QGenExpr ctxt be s Bool

    -- | Given an object (third argument) which may or may not be null, return the default value if
    -- null (first argument), or transform the value that could be null to yield the result of the
    -- expression (second argument)
    maybe_ :: QGenExpr ctxt be s y -> (nonNullA -> QGenExpr ctxt be s y) -> a -> QGenExpr ctxt be s y

instance BeamSqlBackend be => SqlDeconstructMaybe be (QGenExpr ctxt be s (Maybe x)) (QGenExpr ctxt be s x) s where
    isJust_ :: QGenExpr ctxt be s (Maybe x) -> QGenExpr ctxt be s Bool
isJust_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
x) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s Bool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isNotNullE (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
x)
    isNothing_ :: QGenExpr ctxt be s (Maybe x) -> QGenExpr ctxt be s Bool
isNothing_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
x) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s Bool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isNullE (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
x)

    maybe_ :: QGenExpr ctxt be s y
-> (QGenExpr ctxt be s x -> QGenExpr ctxt be s y)
-> QGenExpr ctxt be s (Maybe x)
-> QGenExpr ctxt be s y
maybe_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
onNothing) QGenExpr ctxt be s x -> QGenExpr ctxt be s y
onJust (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e) =
        let QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
onJust' = QGenExpr ctxt be s x -> QGenExpr ctxt be s y
onJust ((TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s x
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e)
        in (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s y
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\TablePrefix
tbl -> [(Sql92UpdateExpressionSyntax
    (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
  Sql92UpdateExpressionSyntax
    (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
[(expr, expr)] -> expr -> expr
caseE [(Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isNotNullE (TablePrefix -> BeamSqlBackendExpressionSyntax be
e TablePrefix
tbl), TablePrefix -> BeamSqlBackendExpressionSyntax be
onJust' TablePrefix
tbl)] (TablePrefix -> BeamSqlBackendExpressionSyntax be
onNothing TablePrefix
tbl))

instance ( BeamSqlBackend be, Beamable t)
    => SqlDeconstructMaybe be (t (Nullable (QGenExpr ctxt be s))) (t (QGenExpr ctxt be s)) s where
    isJust_ :: t (Nullable (QGenExpr ctxt be s)) -> QGenExpr ctxt be s Bool
isJust_ t (Nullable (QGenExpr ctxt be s))
t = [QGenExpr ctxt be s Bool] -> QGenExpr ctxt be s Bool
forall be context s.
BeamSqlBackend be =>
[QGenExpr context be s Bool] -> QGenExpr context be s Bool
allE ((forall a.
 Columnar' (Nullable (QGenExpr ctxt be s)) a
 -> QGenExpr ctxt be s Bool)
-> t (Nullable (QGenExpr ctxt be s)) -> [QGenExpr ctxt be s Bool]
forall (table :: (* -> *) -> *) (f :: * -> *) b.
Beamable table =>
(forall a. Columnar' f a -> b) -> table f -> [b]
allBeamValues (\(Columnar' Columnar (Nullable (QGenExpr ctxt be s)) a
e) -> QGenExpr ctxt be s (Maybe a) -> QGenExpr ctxt be s Bool
forall be a nonNullA s ctxt.
SqlDeconstructMaybe be a nonNullA s =>
a -> QGenExpr ctxt be s Bool
isJust_ Columnar (Nullable (QGenExpr ctxt be s)) a
QGenExpr ctxt be s (Maybe a)
e) t (Nullable (QGenExpr ctxt be s))
t)
    isNothing_ :: t (Nullable (QGenExpr ctxt be s)) -> QGenExpr ctxt be s Bool
isNothing_ t (Nullable (QGenExpr ctxt be s))
t = [QGenExpr ctxt be s Bool] -> QGenExpr ctxt be s Bool
forall be context s.
BeamSqlBackend be =>
[QGenExpr context be s Bool] -> QGenExpr context be s Bool
allE ((forall a.
 Columnar' (Nullable (QGenExpr ctxt be s)) a
 -> QGenExpr ctxt be s Bool)
-> t (Nullable (QGenExpr ctxt be s)) -> [QGenExpr ctxt be s Bool]
forall (table :: (* -> *) -> *) (f :: * -> *) b.
Beamable table =>
(forall a. Columnar' f a -> b) -> table f -> [b]
allBeamValues (\(Columnar' Columnar (Nullable (QGenExpr ctxt be s)) a
e) -> QGenExpr ctxt be s (Maybe a) -> QGenExpr ctxt be s Bool
forall be a nonNullA s ctxt.
SqlDeconstructMaybe be a nonNullA s =>
a -> QGenExpr ctxt be s Bool
isNothing_ Columnar (Nullable (QGenExpr ctxt be s)) a
QGenExpr ctxt be s (Maybe a)
e) t (Nullable (QGenExpr ctxt be s))
t)
    maybe_ :: QGenExpr ctxt be s y
-> (t (QGenExpr ctxt be s) -> QGenExpr ctxt be s y)
-> t (Nullable (QGenExpr ctxt be s))
-> QGenExpr ctxt be s y
maybe_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
onNothing) t (QGenExpr ctxt be s) -> QGenExpr ctxt be s y
onJust t (Nullable (QGenExpr ctxt be s))
tbl =
      let QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
onJust' = t (QGenExpr ctxt be s) -> QGenExpr ctxt be s y
onJust ((forall a.
 Columnar' (Nullable (QGenExpr ctxt be s)) a
 -> Columnar' (QGenExpr ctxt be s) a)
-> t (Nullable (QGenExpr ctxt be s)) -> t (QGenExpr ctxt be s)
forall (table :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable table =>
(forall a. Columnar' f a -> Columnar' g a) -> table f -> table g
changeBeamRep (\(Columnar' (QExpr e)) -> Columnar (QGenExpr ctxt be s) a -> Columnar' (QGenExpr ctxt be s) a
forall (f :: * -> *) a. Columnar f a -> Columnar' f a
Columnar' ((TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s a
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e)) t (Nullable (QGenExpr ctxt be s))
tbl)
          QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
cond = t (Nullable (QGenExpr ctxt be s)) -> QGenExpr Any be s Bool
forall be a nonNullA s ctxt.
SqlDeconstructMaybe be a nonNullA s =>
a -> QGenExpr ctxt be s Bool
isJust_ t (Nullable (QGenExpr ctxt be s))
tbl
      in (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr ctxt be s y
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\TablePrefix
tblPfx -> [(Sql92UpdateExpressionSyntax
    (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
  Sql92UpdateExpressionSyntax
    (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
[(expr, expr)] -> expr -> expr
caseE [(TablePrefix -> BeamSqlBackendExpressionSyntax be
cond TablePrefix
tblPfx, TablePrefix -> BeamSqlBackendExpressionSyntax be
onJust' TablePrefix
tblPfx)] (TablePrefix -> BeamSqlBackendExpressionSyntax be
onNothing TablePrefix
tblPfx))

infixl 3 <|>.
(<|>.) :: ( SqlJustable a (QGenExpr ctxt syntax s y)
          , SqlDeconstructMaybe syntax (QGenExpr ctxt syntax s y) a s
          )
       => QGenExpr ctxt syntax s y
       -> QGenExpr ctxt syntax s y
       -> QGenExpr ctxt syntax s y
QGenExpr ctxt syntax s y
l <|>. :: QGenExpr ctxt syntax s y
-> QGenExpr ctxt syntax s y -> QGenExpr ctxt syntax s y
<|>. QGenExpr ctxt syntax s y
r = QGenExpr ctxt syntax s y
-> (a -> QGenExpr ctxt syntax s y)
-> QGenExpr ctxt syntax s y
-> QGenExpr ctxt syntax s y
forall be a nonNullA s ctxt y.
SqlDeconstructMaybe be a nonNullA s =>
QGenExpr ctxt be s y
-> (nonNullA -> QGenExpr ctxt be s y) -> a -> QGenExpr ctxt be s y
maybe_ QGenExpr ctxt syntax s y
r a -> QGenExpr ctxt syntax s y
forall a b. SqlJustable a b => a -> b
just_ QGenExpr ctxt syntax s y
l