{-# LANGUAGE UndecidableInstances #-}

-- | Defines classen 'SqlEq' and 'SqlOrd' that can be used to perform equality
--   and comparison operations on certain expressions.
--
--   In particular, any 'Beamable' value over 'QGenExpr' or any 'QGenExpr'
--   object can be compared for equality and inequality using the '(==.)' and
--   '(/=.)' operators respectively.
--
--   Simple (scalar) 'QGenExpr's can be compared using the '(<.)', '(>.)',
--   '(<=.)', and '(>=.)' operators respectively.
--
--   The "Quantified Comparison Syntax" (i.e., @.. > ANY (..)@) is supported
--   using the corresponding operators suffixed with a @*@ before the dot. For
--   example, @x == ANY(SELECT ..)@ can be written.
--
-- > x ==*. anyOf_ ..
--
--   Or, for example, @x > ALL(SELECT ..)@ can be written
--
-- > x >*. allOf_ ..
module Database.Beam.Query.Ord
  ( SqlEq(..), SqlEqQuantified(..), SqlIn(..)
  , HasSqlInTable(..)
  , SqlOrd(..), SqlOrdQuantified(..)
  , QQuantified(..)

  , HasSqlEqualityCheck(..), HasSqlQuantifiedEqualityCheck(..)
  , HasTableEquality, HasTableEqualityNullable

  , isTrue_, isNotTrue_
  , isFalse_, isNotFalse_
  , isUnknown_, isNotUnknown_
  , unknownAs_, sqlBool_
  , possiblyNullBool_
  , fromPossiblyNullBool_

  , anyOf_, anyIn_
  , allOf_, allIn_

  , between_
  ) where

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

import Database.Beam.Schema.Tables
import Database.Beam.Backend.SQL
-- import Database.Beam.Backend.SQL.AST (Expression)
--import Database.Beam.Backend.SQL.Builder (SqlSyntaxBackend)

import Control.Applicative
import Control.Monad.State

import Data.Maybe
import Data.Proxy
import Data.Kind
import Data.Word
import Data.Int
import Data.Tagged
import Data.Text (Text)
import Data.Time (UTCTime, LocalTime, Day, TimeOfDay)

import GHC.TypeLits

-- | A data structure representing the set to quantify a comparison operator over.
data QQuantified be s r
  = QQuantified (BeamSqlBackendExpressionQuantifierSyntax be) (WithExprContext (BeamSqlBackendExpressionSyntax be))

-- | Convert a /known not null/ bool to a 'SqlBool'. See 'unknownAs_' for the inverse
sqlBool_ :: QGenExpr context syntax s Bool -> QGenExpr context syntax s SqlBool
sqlBool_ :: QGenExpr context syntax s Bool -> QGenExpr context syntax s SqlBool
sqlBool_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax syntax
s) = (TablePrefix -> BeamSqlBackendExpressionSyntax syntax)
-> QGenExpr context syntax s SqlBool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr TablePrefix -> BeamSqlBackendExpressionSyntax syntax
s

-- | SQL @IS TRUE@ operator
isTrue_ :: BeamSqlBackend be
        => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isTrue_ :: QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isTrue_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (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))
 -> 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
fmap Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isTrueE TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | SQL @IS NOT TRUE@ operator
isNotTrue_ :: BeamSqlBackend be
           => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotTrue_ :: QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotTrue_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (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))
 -> 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
fmap Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isNotTrueE TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | SQL @IS FALSE@ operator
isFalse_ :: BeamSqlBackend be
         => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isFalse_ :: QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isFalse_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (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))
 -> 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
fmap Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isFalseE TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | SQL @IS NOT FALSE@ operator
isNotFalse_ :: BeamSqlBackend be
            => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotFalse_ :: QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotFalse_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (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))
 -> 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
fmap Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isNotFalseE TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | SQL @IS UNKNOWN@ operator
isUnknown_ :: BeamSqlBackend be
           => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isUnknown_ :: QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isUnknown_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (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))
 -> 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
fmap Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isUnknownE TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | SQL @IS NOT UNKNOWN@ operator
isNotUnknown_ :: BeamSqlBackend be
              => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotUnknown_ :: QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotUnknown_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
s) = (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))
 -> 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
fmap Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isNotUnknownE TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
s)

-- | Return the first argument if the expression has the unknown SQL value
-- See 'sqlBool_' for the inverse
unknownAs_ :: BeamSqlBackend be
           => Bool -> QGenExpr context be s SqlBool -> QGenExpr context be s Bool
unknownAs_ :: Bool -> QGenExpr context be s SqlBool -> QGenExpr context be s Bool
unknownAs_ Bool
False = QGenExpr context be s SqlBool -> QGenExpr context be s Bool
forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isTrue_ -- If unknown is being treated as false, then return true only if the expression is true
unknownAs_ Bool
True  = QGenExpr context be s SqlBool -> QGenExpr context be s Bool
forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotFalse_ -- If unknown is being treated as true, then return true only if the expression is not false

-- | Retrieve a 'SqlBool' value as a potentially @NULL@ 'Bool'. This
-- is useful if you want to get the value of a SQL boolean expression
-- directly, without having to specify what to do on @UNKNOWN@. Note
-- that both @NULL@ and @UNKNOWN@ will be returned as 'Nothing'.
possiblyNullBool_ :: QGenExpr context be s SqlBool -> QGenExpr context be s (Maybe Bool)
possiblyNullBool_ :: QGenExpr context be s SqlBool -> QGenExpr context be s (Maybe Bool)
possiblyNullBool_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s (Maybe Bool)
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e

-- | Convert a possibly @NULL@ 'Bool' to a 'SqlBool'.
fromPossiblyNullBool_ :: QGenExpr context be s (Maybe Bool) -> QGenExpr context be s SqlBool
fromPossiblyNullBool_ :: QGenExpr context be s (Maybe Bool) -> QGenExpr context be s SqlBool
fromPossiblyNullBool_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e) = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s SqlBool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
e

-- | A 'QQuantified' representing a SQL @ALL(..)@ for use with a
--   <#quantified-comparison-operator quantified comparison operator>
--
--   Accepts a subquery. Use 'allIn_' for an explicit list
allOf_
  :: forall s a be db
   . ( BeamSqlBackend be, HasQBuilder be )
  => Q be db (QNested s) (QExpr be (QNested s) a)
  -> QQuantified be s a
allOf_ :: Q be db (QNested s) (QExpr be (QNested s) a) -> QQuantified be s a
allOf_ Q be db (QNested s) (QExpr be (QNested s) a)
s = BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s a
forall be s r.
BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s r
QQuantified BeamSqlBackendExpressionQuantifierSyntax be
forall quantifier. IsSql92QuantifierSyntax quantifier => quantifier
quantifyOverAll (\TablePrefix
tblPfx -> Sql92ExpressionSelectSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionSelectSyntax expr -> expr
subqueryE (TablePrefix
-> Q be db (QNested s) (QExpr be (QNested s) a)
-> BeamSqlBackendSelectSyntax be
forall be a (db :: (* -> *) -> *) s.
(HasQBuilder be, Projectible be a) =>
TablePrefix -> Q be db s a -> BeamSqlBackendSelectSyntax be
buildSqlQuery TablePrefix
tblPfx Q be db (QNested s) (QExpr be (QNested s) a)
s))

-- | A 'QQuantified' representing a SQL @ALL(..)@ for use with a
--   <#quantified-comparison-operator quantified comparison operator>
--
--   Accepts an explicit list of typed expressions. Use 'allOf_' for
--   a subquery
allIn_
  :: forall s a be
   . BeamSqlBackend be
  => [QExpr be s a]
  -> QQuantified be s a
allIn_ :: [QExpr be s a] -> QQuantified be s a
allIn_ [QExpr be s a]
es = BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s a
forall be s r.
BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s r
QQuantified BeamSqlBackendExpressionQuantifierSyntax be
forall quantifier. IsSql92QuantifierSyntax quantifier => quantifier
quantifyOverAll ([Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => [expr] -> expr
quantifierListE ([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
<$> (QExpr be s a
 -> TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> [QExpr be s 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 WithExprContext (BeamSqlBackendExpressionSyntax be)
e) -> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
WithExprContext (BeamSqlBackendExpressionSyntax be)
e) [QExpr be s a]
es)

-- | A 'QQuantified' representing a SQL @ANY(..)@ for use with a
--   <#quantified-comparison-operator quantified comparison operator>
--
--   Accepts a subquery. Use 'anyIn_' for an explicit list
anyOf_
  :: forall s a be db
   . ( BeamSqlBackend be, HasQBuilder be )
  => Q be db (QNested s) (QExpr be (QNested s) a)
  -> QQuantified be s a
anyOf_ :: Q be db (QNested s) (QExpr be (QNested s) a) -> QQuantified be s a
anyOf_ Q be db (QNested s) (QExpr be (QNested s) a)
s = BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s a
forall be s r.
BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s r
QQuantified BeamSqlBackendExpressionQuantifierSyntax be
forall quantifier. IsSql92QuantifierSyntax quantifier => quantifier
quantifyOverAny (\TablePrefix
tblPfx -> Sql92ExpressionSelectSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionSelectSyntax expr -> expr
subqueryE (TablePrefix
-> Q be db (QNested s) (QExpr be (QNested s) a)
-> BeamSqlBackendSelectSyntax be
forall be a (db :: (* -> *) -> *) s.
(HasQBuilder be, Projectible be a) =>
TablePrefix -> Q be db s a -> BeamSqlBackendSelectSyntax be
buildSqlQuery TablePrefix
tblPfx Q be db (QNested s) (QExpr be (QNested s) a)
s))

-- | A 'QQuantified' representing a SQL @ANY(..)@ for use with a
--   <#quantified-comparison-operator quantified comparison operator>
--
--   Accepts an explicit list of typed expressions. Use 'anyOf_' for
--   a subquery
anyIn_
  :: forall s a be
   . BeamSqlBackend be
  => [QExpr be s a]
  -> QQuantified be s a
anyIn_ :: [QExpr be s a] -> QQuantified be s a
anyIn_ [QExpr be s a]
es = BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s a
forall be s r.
BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s r
QQuantified BeamSqlBackendExpressionQuantifierSyntax be
forall quantifier. IsSql92QuantifierSyntax quantifier => quantifier
quantifyOverAny ([Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => [expr] -> expr
quantifierListE ([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
<$> (QExpr be s a
 -> TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> [QExpr be s 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 WithExprContext (BeamSqlBackendExpressionSyntax be)
e) -> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
WithExprContext (BeamSqlBackendExpressionSyntax be)
e) [QExpr be s a]
es)

-- | SQL @BETWEEN@ clause
between_ :: BeamSqlBackend be
         => QGenExpr context be s a -> QGenExpr context be s a
         -> QGenExpr context be s a -> QGenExpr context be s Bool
between_ :: QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s Bool
between_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
a) (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
min_) (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
max_) =
  (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))
 -> 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)))
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
expr -> expr -> expr -> expr
betweenE TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
a TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
min_ TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
max_)

class SqlIn expr a | a -> expr where
  -- | SQL @IN@ predicate
  in_ :: a -> [ a ] -> expr Bool

instance BeamSqlBackend be => SqlIn (QGenExpr context be s) (QGenExpr context be s a) where
  in_ :: QGenExpr context be s a
-> [QGenExpr context be s a] -> QGenExpr context be s Bool
in_ QGenExpr context be s a
_ [] = (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
False)))
  in_ (QExpr TablePrefix -> BeamSqlBackendExpressionSyntax be
row) [QGenExpr context be s a]
options = (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))
-> [Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => expr -> [expr] -> expr
inE (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> [Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> [Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
row (TablePrefix
 -> [Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> [Sql92UpdateExpressionSyntax
          (Sql92UpdateSyntax (BeamSqlBackendSyntax be))])
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (QGenExpr context be s a
 -> TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> [QGenExpr context be s 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
o) -> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
o) [QGenExpr context be s a]
options)

-- | Class for backends which support SQL @IN@ on lists of row values, which is
-- not part of ANSI SQL. This is useful for @IN@ on primary keys.
class BeamSqlBackend be => HasSqlInTable be where
  inRowValuesE
    :: Proxy be
    -> BeamSqlBackendExpressionSyntax be
    -> [ BeamSqlBackendExpressionSyntax be ]
    -> BeamSqlBackendExpressionSyntax be
  inRowValuesE Proxy be
Proxy = BeamSqlBackendExpressionSyntax be
-> [BeamSqlBackendExpressionSyntax be]
-> BeamSqlBackendExpressionSyntax be
forall expr. IsSql92ExpressionSyntax expr => expr -> [expr] -> expr
inE

instance ( HasSqlInTable be, Beamable table ) =>
  SqlIn (QGenExpr context be s) (table (QGenExpr context be s)) where

  in_ :: table (QGenExpr context be s)
-> [table (QGenExpr context be s)] -> QGenExpr context be s Bool
in_ table (QGenExpr context be s)
_ [] = (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
False)))
  in_ table (QGenExpr context be s)
row [table (QGenExpr context be s)]
options = (TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s Bool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (Proxy be
-> BeamSqlBackendExpressionSyntax be
-> [BeamSqlBackendExpressionSyntax be]
-> BeamSqlBackendExpressionSyntax be
forall be.
HasSqlInTable be =>
Proxy be
-> BeamSqlBackendExpressionSyntax be
-> [BeamSqlBackendExpressionSyntax be]
-> BeamSqlBackendExpressionSyntax be
inRowValuesE (Proxy be
forall k (t :: k). Proxy t
Proxy @be) (Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 -> [Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> TablePrefix
-> [Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> table (QGenExpr context be s)
-> TablePrefix -> BeamSqlBackendExpressionSyntax be
toExpr table (QGenExpr context be s)
row (TablePrefix
 -> [Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (TablePrefix
    -> [Sql92UpdateExpressionSyntax
          (Sql92UpdateSyntax (BeamSqlBackendSyntax be))])
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((table (QGenExpr context be s)
 -> TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> [table (QGenExpr context be s)]
-> TablePrefix
-> [Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM table (QGenExpr context be s)
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
table (QGenExpr context be s)
-> TablePrefix -> BeamSqlBackendExpressionSyntax be
toExpr [table (QGenExpr context be s)]
options))
    where toExpr :: table (QGenExpr context be s) -> TablePrefix -> BeamSqlBackendExpressionSyntax be
          toExpr :: table (QGenExpr context be s)
-> TablePrefix -> BeamSqlBackendExpressionSyntax be
toExpr = ([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
fmap [Sql92UpdateExpressionSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr. IsSql92ExpressionSyntax expr => [expr] -> expr
rowE ((TablePrefix
  -> [Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))])
 -> TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> (table (QGenExpr context be s)
    -> TablePrefix
    -> [Sql92UpdateExpressionSyntax
          (Sql92UpdateSyntax (BeamSqlBackendSyntax be))])
-> table (QGenExpr context be s)
-> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
-> TablePrefix
-> [Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([TablePrefix
  -> Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
 -> TablePrefix
 -> [Sql92UpdateExpressionSyntax
       (Sql92UpdateSyntax (BeamSqlBackendSyntax be))])
-> (table (QGenExpr context be s)
    -> [TablePrefix
        -> Sql92UpdateExpressionSyntax
             (Sql92UpdateSyntax (BeamSqlBackendSyntax be))])
-> table (QGenExpr context be s)
-> TablePrefix
-> [Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a.
 Columnar' (QGenExpr context be s) a
 -> TablePrefix
 -> Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> table (QGenExpr context be s)
-> [TablePrefix
    -> Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be))]
forall (table :: (* -> *) -> *) (f :: * -> *) b.
Beamable table =>
(forall a. Columnar' f a -> b) -> table f -> [b]
allBeamValues (\(Columnar' (QExpr x)) -> TablePrefix
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
TablePrefix -> BeamSqlBackendExpressionSyntax be
x)

infix 4 `between_`, `in_`

-- | Class for expression types or expression containers for which there is a
--   notion of equality.
--
--   Instances are provided to check the equality of expressions of the same
--   type as well as entire 'Beamable' types parameterized over 'QGenExpr'
class SqlEq expr a | a -> expr where
  -- | Given two expressions, returns whether they are equal, using Haskell semantics (NULLs handled properly)
  (==.) :: a -> a -> expr Bool
  -- | Given two expressions, returns whether they are not equal, using Haskell semantics (NULLs handled properly)
  (/=.) :: a -> a -> expr Bool

  -- | Given two expressions, returns the /SQL tri-state boolean/ when compared for equality
  (==?.) :: a -> a -> expr SqlBool

  -- | Given two expressions, returns the /SQL tri-state boolean/ when compared for inequality
  (/=?.) :: a -> a -> expr SqlBool

-- | Class for expression types for which there is a notion of /quantified/
--   equality.
class SqlEq expr a => SqlEqQuantified expr quantified a | a -> expr quantified where

  -- | Quantified equality and inequality using /SQL semantics/ (tri-state boolean)
  (==*.), (/=*.) :: a -> quantified -> expr SqlBool

infix 4 ==., /=., ==?., /=?., ==*., /=*.
infix 4 <., >., <=., >=.
infix 4 <*., >*., <=*., >=*.

-- | Class for Haskell types that can be compared for equality in the given backend
class BeamSqlBackend be => HasSqlEqualityCheck be a where

  sqlEqE, sqlNeqE :: Proxy a -> Proxy be
                  -> BeamSqlBackendExpressionSyntax be
                  -> BeamSqlBackendExpressionSyntax be
                  -> BeamSqlBackendExpressionSyntax be
  sqlEqE Proxy a
_ Proxy be
_ = Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
eqE Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. Maybe a
Nothing
  sqlNeqE Proxy a
_ Proxy be
_ = Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
neqE Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. Maybe a
Nothing

  -- | Tri-state equality
  sqlEqTriE, sqlNeqTriE :: Proxy a -> Proxy be
                        -> BeamSqlBackendExpressionSyntax be
                        -> BeamSqlBackendExpressionSyntax be
                        -> BeamSqlBackendExpressionSyntax be
  sqlEqTriE Proxy a
_ Proxy be
_ = Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
eqE Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. Maybe a
Nothing
  sqlNeqTriE Proxy a
_ Proxy be
_ = Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
neqE Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. Maybe a
Nothing

type family CanCheckMaybeEquality a :: Constraint where
  CanCheckMaybeEquality (Maybe a) =
    TypeError ('Text "Attempt to check equality of nested Maybe." ':$$:
               'Text "Beam can only reasonably check equality of a single nesting of Maybe.")
  CanCheckMaybeEquality a = ()

instance (HasSqlEqualityCheck be a, CanCheckMaybeEquality a) => HasSqlEqualityCheck be (Maybe a) where
  sqlEqE :: Proxy (Maybe a)
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqE Proxy (Maybe a)
_ Proxy be
_ BeamSqlBackendExpressionSyntax be
a BeamSqlBackendExpressionSyntax be
b = Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
expr -> expr -> expr -> expr
eqMaybeE Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
BeamSqlBackendExpressionSyntax be
a Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
BeamSqlBackendExpressionSyntax be
b (Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a) (Proxy be
forall k (t :: k). Proxy t
Proxy @be) BeamSqlBackendExpressionSyntax be
a BeamSqlBackendExpressionSyntax be
b)
  sqlNeqE :: Proxy (Maybe a)
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqE Proxy (Maybe a)
_ Proxy be
_ BeamSqlBackendExpressionSyntax be
a BeamSqlBackendExpressionSyntax be
b = Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
expr -> expr -> expr -> expr
neqMaybeE Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
BeamSqlBackendExpressionSyntax be
a Sql92UpdateExpressionSyntax
  (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
BeamSqlBackendExpressionSyntax be
b (Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a) (Proxy be
forall k (t :: k). Proxy t
Proxy @be) BeamSqlBackendExpressionSyntax be
a BeamSqlBackendExpressionSyntax be
b)

instance HasSqlEqualityCheck be a => HasSqlEqualityCheck be (SqlSerial a) where
  sqlEqE :: Proxy (SqlSerial a)
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqE Proxy (SqlSerial a)
_ = Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a)
  sqlNeqE :: Proxy (SqlSerial a)
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqE Proxy (SqlSerial a)
_ = Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a)

  sqlEqTriE :: Proxy (SqlSerial a)
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqTriE Proxy (SqlSerial a)
_ = Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqTriE (Proxy a
forall k (t :: k). Proxy t
Proxy @a)
  sqlNeqTriE :: Proxy (SqlSerial a)
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqTriE Proxy (SqlSerial a)
_ = Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqTriE (Proxy a
forall k (t :: k). Proxy t
Proxy @a)

-- | Class for Haskell types that can be compared for quantified equality in the given backend
class HasSqlEqualityCheck be a => HasSqlQuantifiedEqualityCheck be a where
  sqlQEqE, sqlQNeqE :: Proxy a -> Proxy be
                    -> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
                    -> BeamSqlBackendExpressionSyntax be
                    -> BeamSqlBackendExpressionSyntax be
                    -> BeamSqlBackendExpressionSyntax be
  sqlQEqE Proxy a
_ Proxy be
_ = Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
eqE
  sqlQNeqE Proxy a
_ Proxy be
_ = Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
neqE

instance (HasSqlQuantifiedEqualityCheck syntax a, CanCheckMaybeEquality a) => HasSqlQuantifiedEqualityCheck syntax (Maybe a) where
  sqlQEqE :: Proxy (Maybe a)
-> Proxy syntax
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax syntax)
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
sqlQEqE Proxy (Maybe a)
_ = Proxy a
-> Proxy syntax
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax syntax)
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQEqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a)
  sqlQNeqE :: Proxy (Maybe a)
-> Proxy syntax
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax syntax)
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
sqlQNeqE Proxy (Maybe a)
_ = Proxy a
-> Proxy syntax
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax syntax)
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQNeqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a)

instance HasSqlQuantifiedEqualityCheck syntax a => HasSqlQuantifiedEqualityCheck syntax (SqlSerial a) where
  sqlQEqE :: Proxy (SqlSerial a)
-> Proxy syntax
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax syntax)
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
sqlQEqE Proxy (SqlSerial a)
_ = Proxy a
-> Proxy syntax
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax syntax)
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQEqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a)
  sqlQNeqE :: Proxy (SqlSerial a)
-> Proxy syntax
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax syntax)
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
sqlQNeqE Proxy (SqlSerial a)
_ = Proxy a
-> Proxy syntax
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax syntax)
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
-> BeamSqlBackendExpressionSyntax syntax
forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQNeqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a)

-- | Compare two arbitrary expressions (of the same type) for equality
instance ( BeamSqlBackend be, HasSqlEqualityCheck be a ) =>
  SqlEq (QGenExpr context be s) (QGenExpr context be s a) where

  ==. :: QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s Bool
(==.) = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s Bool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a) (Proxy be
forall k (t :: k). Proxy t
Proxy @be))
  /=. :: QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s Bool
(/=.) = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s Bool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a) (Proxy be
forall k (t :: k). Proxy t
Proxy @be))

  ==?. :: QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s SqlBool
(==?.) = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s SqlBool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqTriE (Proxy a
forall k (t :: k). Proxy t
Proxy @a) (Proxy be
forall k (t :: k). Proxy t
Proxy @be))
  /=?. :: QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s SqlBool
(/=?.) = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s SqlBool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqTriE (Proxy a
forall k (t :: k). Proxy t
Proxy @a) (Proxy be
forall k (t :: k). Proxy t
Proxy @be))

-- | Two arbitrary expressions can be quantifiably compared for equality.
instance ( BeamSqlBackend be, HasSqlQuantifiedEqualityCheck be a ) =>
  SqlEqQuantified (QGenExpr context be s) (QQuantified be s a) (QGenExpr context be s a) where

  QGenExpr context be s a
a ==*. :: QGenExpr context be s a
-> QQuantified be s a -> QGenExpr context be s SqlBool
==*. QQuantified BeamSqlBackendExpressionQuantifierSyntax be
q WithExprContext (BeamSqlBackendExpressionSyntax be)
b = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s Any
-> QGenExpr context be s SqlBool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQEqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a) (Proxy be
forall k (t :: k). Proxy t
Proxy @be) (Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Maybe
     (Sql92ExpressionQuantifierSyntax
        (Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. a -> Maybe a
Just Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s Any
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
b)
  QGenExpr context be s a
a /=*. :: QGenExpr context be s a
-> QQuantified be s a -> QGenExpr context be s SqlBool
/=*. QQuantified BeamSqlBackendExpressionQuantifierSyntax be
q WithExprContext (BeamSqlBackendExpressionSyntax be)
b = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s Any
-> QGenExpr context be s SqlBool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQNeqE (Proxy a
forall k (t :: k). Proxy t
Proxy @a) (Proxy be
forall k (t :: k). Proxy t
Proxy @be) (Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Maybe
     (Sql92ExpressionQuantifierSyntax
        (Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. a -> Maybe a
Just Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s Any
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
b)

-- | Constraint synonym to check if two tables can be compared for equality
type HasTableEquality be tbl =
  (FieldsFulfillConstraint (HasSqlEqualityCheck be) tbl, Beamable tbl)
type HasTableEqualityNullable be tbl =
  (FieldsFulfillConstraintNullable (HasSqlEqualityCheck be) tbl, Beamable tbl)

-- | Compare two arbitrary 'Beamable' types containing 'QGenExpr's for equality.
instance ( BeamSqlBackend be, Beamable tbl
         , FieldsFulfillConstraint (HasSqlEqualityCheck be) tbl ) =>
         SqlEq (QGenExpr context be s) (tbl (QGenExpr context be s)) where

  tbl (QGenExpr context be s)
a ==. :: tbl (QGenExpr context be s)
-> tbl (QGenExpr context be s) -> QGenExpr context be s Bool
==. tbl (QGenExpr context be s)
b = let (tbl
  (Columnar' (HasConstraint (HasSqlEqualityCheck be))
   :*: Columnar' (QGenExpr context be s))
_, Maybe (QGenExpr context be s Bool)
e) = State
  (Maybe (QGenExpr context be s Bool))
  (tbl
     (Columnar' (HasConstraint (HasSqlEqualityCheck be))
      :*: Columnar' (QGenExpr context be s)))
-> Maybe (QGenExpr context be s Bool)
-> (tbl
      (Columnar' (HasConstraint (HasSqlEqualityCheck be))
       :*: Columnar' (QGenExpr context be s)),
    Maybe (QGenExpr context be s Bool))
forall s a. State s a -> s -> (a, s)
runState ((forall a.
 Columnar'
   (Columnar' (HasConstraint (HasSqlEqualityCheck be))
    :*: Columnar' (QGenExpr context be s))
   a
 -> Columnar' (QGenExpr context be s) a
 -> StateT
      (Maybe (QGenExpr context be s Bool))
      Identity
      (Columnar'
         (Columnar' (HasConstraint (HasSqlEqualityCheck be))
          :*: Columnar' (QGenExpr context be s))
         a))
-> tbl
     (Columnar' (HasConstraint (HasSqlEqualityCheck be))
      :*: Columnar' (QGenExpr context be s))
-> tbl (QGenExpr context be s)
-> State
     (Maybe (QGenExpr context be s Bool))
     (tbl
        (Columnar' (HasConstraint (HasSqlEqualityCheck be))
         :*: Columnar' (QGenExpr context be s)))
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
                                   (\x' :: Columnar'
  (Columnar' (HasConstraint (HasSqlEqualityCheck be))
   :*: Columnar' (QGenExpr context be s))
  a
x'@(Columnar' (Columnar' HasConstraint :*: Columnar' x)) (Columnar' Columnar (QGenExpr context be s) a
y) ->
                                       do (Maybe (QGenExpr context be s Bool)
 -> Maybe (QGenExpr context be s Bool))
-> StateT (Maybe (QGenExpr context be s Bool)) Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (\Maybe (QGenExpr context be s Bool)
expr ->
                                                    case Maybe (QGenExpr context be s Bool)
expr of
                                                      Maybe (QGenExpr context be s Bool)
Nothing -> 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
$ Columnar (QGenExpr context be s) a
QGenExpr context be s a
x QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. Columnar (QGenExpr context be s) a
QGenExpr context be s a
y
                                                      Just QGenExpr context be s Bool
expr' -> 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
expr' 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
&&. Columnar (QGenExpr context be s) a
QGenExpr context be s a
x QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. Columnar (QGenExpr context be s) a
QGenExpr context be s a
y)
                                          Columnar'
  (Columnar' (HasConstraint (HasSqlEqualityCheck be))
   :*: Columnar' (QGenExpr context be s))
  a
-> StateT
     (Maybe (QGenExpr context be s Bool))
     Identity
     (Columnar'
        (Columnar' (HasConstraint (HasSqlEqualityCheck be))
         :*: Columnar' (QGenExpr context be s))
        a)
forall (m :: * -> *) a. Monad m => a -> m a
return Columnar'
  (Columnar' (HasConstraint (HasSqlEqualityCheck be))
   :*: Columnar' (QGenExpr context be s))
  a
x') (forall (c :: * -> Constraint) (tbl :: (* -> *) -> *).
(Beamable tbl, FieldsFulfillConstraint c tbl) =>
tbl (HasConstraint c)
forall (tbl :: (* -> *) -> *).
(Beamable tbl,
 FieldsFulfillConstraint (HasSqlEqualityCheck be) tbl) =>
tbl (HasConstraint (HasSqlEqualityCheck be))
withConstraints @(HasSqlEqualityCheck be) tbl (HasConstraint (HasSqlEqualityCheck be))
-> tbl (QGenExpr context be s)
-> tbl
     (Columnar' (HasConstraint (HasSqlEqualityCheck be))
      :*: Columnar' (QGenExpr context be s))
forall (tbl :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable tbl =>
tbl f -> tbl g -> tbl (Columnar' f :*: Columnar' g)
`alongsideTable` tbl (QGenExpr context be s)
a) tbl (QGenExpr context be s)
b) Maybe (QGenExpr context be s Bool)
forall a. Maybe a
Nothing
            in 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 (\TablePrefix
_ -> 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)
e
  tbl (QGenExpr context be s)
a /=. :: tbl (QGenExpr context be s)
-> tbl (QGenExpr context be s) -> QGenExpr context be s Bool
/=. tbl (QGenExpr context be s)
b = 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
not_ (tbl (QGenExpr context be s)
a tbl (QGenExpr context be s)
-> tbl (QGenExpr context be s) -> QGenExpr context be s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. tbl (QGenExpr context be s)
b)

  tbl (QGenExpr context be s)
a ==?. :: tbl (QGenExpr context be s)
-> tbl (QGenExpr context be s) -> QGenExpr context be s SqlBool
==?. tbl (QGenExpr context be s)
b = let (tbl
  (Columnar' (HasConstraint (HasSqlEqualityCheck be))
   :*: Columnar' (QGenExpr context be s))
_, Maybe (QGenExpr context be s SqlBool)
e) = State
  (Maybe (QGenExpr context be s SqlBool))
  (tbl
     (Columnar' (HasConstraint (HasSqlEqualityCheck be))
      :*: Columnar' (QGenExpr context be s)))
-> Maybe (QGenExpr context be s SqlBool)
-> (tbl
      (Columnar' (HasConstraint (HasSqlEqualityCheck be))
       :*: Columnar' (QGenExpr context be s)),
    Maybe (QGenExpr context be s SqlBool))
forall s a. State s a -> s -> (a, s)
runState ((forall a.
 Columnar'
   (Columnar' (HasConstraint (HasSqlEqualityCheck be))
    :*: Columnar' (QGenExpr context be s))
   a
 -> Columnar' (QGenExpr context be s) a
 -> StateT
      (Maybe (QGenExpr context be s SqlBool))
      Identity
      (Columnar'
         (Columnar' (HasConstraint (HasSqlEqualityCheck be))
          :*: Columnar' (QGenExpr context be s))
         a))
-> tbl
     (Columnar' (HasConstraint (HasSqlEqualityCheck be))
      :*: Columnar' (QGenExpr context be s))
-> tbl (QGenExpr context be s)
-> State
     (Maybe (QGenExpr context be s SqlBool))
     (tbl
        (Columnar' (HasConstraint (HasSqlEqualityCheck be))
         :*: Columnar' (QGenExpr context be s)))
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
                                    (\x' :: Columnar'
  (Columnar' (HasConstraint (HasSqlEqualityCheck be))
   :*: Columnar' (QGenExpr context be s))
  a
x'@(Columnar' (Columnar' HasConstraint :*: Columnar' x)) (Columnar' Columnar (QGenExpr context be s) a
y) ->
                                        do (Maybe (QGenExpr context be s SqlBool)
 -> Maybe (QGenExpr context be s SqlBool))
-> StateT (Maybe (QGenExpr context be s SqlBool)) Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (\Maybe (QGenExpr context be s SqlBool)
expr ->
                                                     case Maybe (QGenExpr context be s SqlBool)
expr of
                                                       Maybe (QGenExpr context be s SqlBool)
Nothing -> QGenExpr context be s SqlBool
-> Maybe (QGenExpr context be s SqlBool)
forall a. a -> Maybe a
Just (QGenExpr context be s SqlBool
 -> Maybe (QGenExpr context be s SqlBool))
-> QGenExpr context be s SqlBool
-> Maybe (QGenExpr context be s SqlBool)
forall a b. (a -> b) -> a -> b
$ Columnar (QGenExpr context be s) a
QGenExpr context be s a
x QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s SqlBool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. Columnar (QGenExpr context be s) a
QGenExpr context be s a
y
                                                       Just QGenExpr context be s SqlBool
expr' -> QGenExpr context be s SqlBool
-> Maybe (QGenExpr context be s SqlBool)
forall a. a -> Maybe a
Just (QGenExpr context be s SqlBool
 -> Maybe (QGenExpr context be s SqlBool))
-> QGenExpr context be s SqlBool
-> Maybe (QGenExpr context be s SqlBool)
forall a b. (a -> b) -> a -> b
$ QGenExpr context be s SqlBool
expr' QGenExpr context be s SqlBool
-> QGenExpr context be s SqlBool -> QGenExpr context be s SqlBool
forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool
-> QGenExpr context be s SqlBool -> QGenExpr context be s SqlBool
&&?. Columnar (QGenExpr context be s) a
QGenExpr context be s a
x QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s SqlBool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. Columnar (QGenExpr context be s) a
QGenExpr context be s a
y)
                                           Columnar'
  (Columnar' (HasConstraint (HasSqlEqualityCheck be))
   :*: Columnar' (QGenExpr context be s))
  a
-> StateT
     (Maybe (QGenExpr context be s SqlBool))
     Identity
     (Columnar'
        (Columnar' (HasConstraint (HasSqlEqualityCheck be))
         :*: Columnar' (QGenExpr context be s))
        a)
forall (m :: * -> *) a. Monad m => a -> m a
return Columnar'
  (Columnar' (HasConstraint (HasSqlEqualityCheck be))
   :*: Columnar' (QGenExpr context be s))
  a
x') (forall (c :: * -> Constraint) (tbl :: (* -> *) -> *).
(Beamable tbl, FieldsFulfillConstraint c tbl) =>
tbl (HasConstraint c)
forall (tbl :: (* -> *) -> *).
(Beamable tbl,
 FieldsFulfillConstraint (HasSqlEqualityCheck be) tbl) =>
tbl (HasConstraint (HasSqlEqualityCheck be))
withConstraints @(HasSqlEqualityCheck be) tbl (HasConstraint (HasSqlEqualityCheck be))
-> tbl (QGenExpr context be s)
-> tbl
     (Columnar' (HasConstraint (HasSqlEqualityCheck be))
      :*: Columnar' (QGenExpr context be s))
forall (tbl :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable tbl =>
tbl f -> tbl g -> tbl (Columnar' f :*: Columnar' g)
`alongsideTable` tbl (QGenExpr context be s)
a) tbl (QGenExpr context be s)
b) Maybe (QGenExpr context be s SqlBool)
forall a. Maybe a
Nothing
            in QGenExpr context be s SqlBool
-> Maybe (QGenExpr context be s SqlBool)
-> QGenExpr context be s SqlBool
forall a. a -> Maybe a -> a
fromMaybe ((TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s SqlBool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\TablePrefix
_ -> 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 SqlBool)
e
  tbl (QGenExpr context be s)
a /=?. :: tbl (QGenExpr context be s)
-> tbl (QGenExpr context be s) -> QGenExpr context be s SqlBool
/=?. tbl (QGenExpr context be s)
b = QGenExpr context be s SqlBool -> QGenExpr context be s SqlBool
forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s SqlBool
sqlNot_ (tbl (QGenExpr context be s)
a tbl (QGenExpr context be s)
-> tbl (QGenExpr context be s) -> QGenExpr context be s SqlBool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. tbl (QGenExpr context be s)
b)

instance ( BeamSqlBackend be, Beamable tbl
         , FieldsFulfillConstraintNullable (HasSqlEqualityCheck be) tbl )
    => SqlEq (QGenExpr context be s) (tbl (Nullable (QGenExpr context be s))) where

  tbl (Nullable (QGenExpr context be s))
a ==. :: tbl (Nullable (QGenExpr context be s))
-> tbl (Nullable (QGenExpr context be s))
-> QGenExpr context be s Bool
==. tbl (Nullable (QGenExpr context be s))
b = let (tbl
  (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
   :*: Columnar' (Nullable (QGenExpr context be s)))
_, Maybe (QGenExpr context be s Bool)
e) = State
  (Maybe (QGenExpr context be s Bool))
  (tbl
     (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
      :*: Columnar' (Nullable (QGenExpr context be s))))
-> Maybe (QGenExpr context be s Bool)
-> (tbl
      (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
       :*: Columnar' (Nullable (QGenExpr context be s))),
    Maybe (QGenExpr context be s Bool))
forall s a. State s a -> s -> (a, s)
runState ((forall a.
 Columnar'
   (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
    :*: Columnar' (Nullable (QGenExpr context be s)))
   a
 -> Columnar' (Nullable (QGenExpr context be s)) a
 -> StateT
      (Maybe (QGenExpr context be s Bool))
      Identity
      (Columnar'
         (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
          :*: Columnar' (Nullable (QGenExpr context be s)))
         a))
-> tbl
     (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
      :*: Columnar' (Nullable (QGenExpr context be s)))
-> tbl (Nullable (QGenExpr context be s))
-> State
     (Maybe (QGenExpr context be s Bool))
     (tbl
        (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
         :*: Columnar' (Nullable (QGenExpr context be s))))
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
                                      (\x' :: Columnar'
  (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
   :*: Columnar' (Nullable (QGenExpr context be s)))
  a
x'@(Columnar' (Columnar' HasConstraint :*: Columnar' x)) (Columnar' Columnar (Nullable (QGenExpr context be s)) a
y) -> do
                                          (Maybe (QGenExpr context be s Bool)
 -> Maybe (QGenExpr context be s Bool))
-> StateT (Maybe (QGenExpr context be s Bool)) Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (\Maybe (QGenExpr context be s Bool)
expr ->
                                                    case Maybe (QGenExpr context be s Bool)
expr of
                                                      Maybe (QGenExpr context be s Bool)
Nothing -> 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
$ Columnar (Nullable (QGenExpr context be s)) a
QGenExpr context be s (Maybe a)
x QGenExpr context be s (Maybe a)
-> QGenExpr context be s (Maybe a) -> QGenExpr context be s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. Columnar (Nullable (QGenExpr context be s)) a
QGenExpr context be s (Maybe a)
y
                                                      Just QGenExpr context be s Bool
expr' -> 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
expr' 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
&&. Columnar (Nullable (QGenExpr context be s)) a
QGenExpr context be s (Maybe a)
x QGenExpr context be s (Maybe a)
-> QGenExpr context be s (Maybe a) -> QGenExpr context be s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. Columnar (Nullable (QGenExpr context be s)) a
QGenExpr context be s (Maybe a)
y)
                                          Columnar'
  (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
   :*: Columnar' (Nullable (QGenExpr context be s)))
  a
-> StateT
     (Maybe (QGenExpr context be s Bool))
     Identity
     (Columnar'
        (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
         :*: Columnar' (Nullable (QGenExpr context be s)))
        a)
forall (m :: * -> *) a. Monad m => a -> m a
return Columnar'
  (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
   :*: Columnar' (Nullable (QGenExpr context be s)))
  a
x')
                                      (forall (c :: * -> Constraint) (tbl :: (* -> *) -> *).
(Beamable tbl, FieldsFulfillConstraintNullable c tbl) =>
tbl (Nullable (HasConstraint c))
forall (tbl :: (* -> *) -> *).
(Beamable tbl,
 FieldsFulfillConstraintNullable (HasSqlEqualityCheck be) tbl) =>
tbl (Nullable (HasConstraint (HasSqlEqualityCheck be)))
withNullableConstraints @(HasSqlEqualityCheck be) tbl (Nullable (HasConstraint (HasSqlEqualityCheck be)))
-> tbl (Nullable (QGenExpr context be s))
-> tbl
     (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
      :*: Columnar' (Nullable (QGenExpr context be s)))
forall (tbl :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable tbl =>
tbl f -> tbl g -> tbl (Columnar' f :*: Columnar' g)
`alongsideTable` tbl (Nullable (QGenExpr context be s))
a) tbl (Nullable (QGenExpr context be s))
b) Maybe (QGenExpr context be s Bool)
forall a. Maybe a
Nothing
            in 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 (\TablePrefix
_ -> 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)
e
  tbl (Nullable (QGenExpr context be s))
a /=. :: tbl (Nullable (QGenExpr context be s))
-> tbl (Nullable (QGenExpr context be s))
-> QGenExpr context be s Bool
/=. tbl (Nullable (QGenExpr context be s))
b = 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
not_ (tbl (Nullable (QGenExpr context be s))
a tbl (Nullable (QGenExpr context be s))
-> tbl (Nullable (QGenExpr context be s))
-> QGenExpr context be s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. tbl (Nullable (QGenExpr context be s))
b)

  tbl (Nullable (QGenExpr context be s))
a ==?. :: tbl (Nullable (QGenExpr context be s))
-> tbl (Nullable (QGenExpr context be s))
-> QGenExpr context be s SqlBool
==?. tbl (Nullable (QGenExpr context be s))
b = let (tbl
  (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
   :*: Columnar' (Nullable (QGenExpr context be s)))
_, Maybe (QGenExpr context be s SqlBool)
e) = State
  (Maybe (QGenExpr context be s SqlBool))
  (tbl
     (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
      :*: Columnar' (Nullable (QGenExpr context be s))))
-> Maybe (QGenExpr context be s SqlBool)
-> (tbl
      (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
       :*: Columnar' (Nullable (QGenExpr context be s))),
    Maybe (QGenExpr context be s SqlBool))
forall s a. State s a -> s -> (a, s)
runState ((forall a.
 Columnar'
   (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
    :*: Columnar' (Nullable (QGenExpr context be s)))
   a
 -> Columnar' (Nullable (QGenExpr context be s)) a
 -> StateT
      (Maybe (QGenExpr context be s SqlBool))
      Identity
      (Columnar'
         (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
          :*: Columnar' (Nullable (QGenExpr context be s)))
         a))
-> tbl
     (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
      :*: Columnar' (Nullable (QGenExpr context be s)))
-> tbl (Nullable (QGenExpr context be s))
-> State
     (Maybe (QGenExpr context be s SqlBool))
     (tbl
        (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
         :*: Columnar' (Nullable (QGenExpr context be s))))
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
                                    (\x' :: Columnar'
  (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
   :*: Columnar' (Nullable (QGenExpr context be s)))
  a
x'@(Columnar' (Columnar' HasConstraint :*: Columnar' x)) (Columnar' Columnar (Nullable (QGenExpr context be s)) a
y) ->
                                        do (Maybe (QGenExpr context be s SqlBool)
 -> Maybe (QGenExpr context be s SqlBool))
-> StateT (Maybe (QGenExpr context be s SqlBool)) Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (\Maybe (QGenExpr context be s SqlBool)
expr ->
                                                     case Maybe (QGenExpr context be s SqlBool)
expr of
                                                       Maybe (QGenExpr context be s SqlBool)
Nothing -> QGenExpr context be s SqlBool
-> Maybe (QGenExpr context be s SqlBool)
forall a. a -> Maybe a
Just (QGenExpr context be s SqlBool
 -> Maybe (QGenExpr context be s SqlBool))
-> QGenExpr context be s SqlBool
-> Maybe (QGenExpr context be s SqlBool)
forall a b. (a -> b) -> a -> b
$ Columnar (Nullable (QGenExpr context be s)) a
QGenExpr context be s (Maybe a)
x QGenExpr context be s (Maybe a)
-> QGenExpr context be s (Maybe a) -> QGenExpr context be s SqlBool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. Columnar (Nullable (QGenExpr context be s)) a
QGenExpr context be s (Maybe a)
y
                                                       Just QGenExpr context be s SqlBool
expr' -> QGenExpr context be s SqlBool
-> Maybe (QGenExpr context be s SqlBool)
forall a. a -> Maybe a
Just (QGenExpr context be s SqlBool
 -> Maybe (QGenExpr context be s SqlBool))
-> QGenExpr context be s SqlBool
-> Maybe (QGenExpr context be s SqlBool)
forall a b. (a -> b) -> a -> b
$ QGenExpr context be s SqlBool
expr' QGenExpr context be s SqlBool
-> QGenExpr context be s SqlBool -> QGenExpr context be s SqlBool
forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool
-> QGenExpr context be s SqlBool -> QGenExpr context be s SqlBool
&&?. Columnar (Nullable (QGenExpr context be s)) a
QGenExpr context be s (Maybe a)
x QGenExpr context be s (Maybe a)
-> QGenExpr context be s (Maybe a) -> QGenExpr context be s SqlBool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. Columnar (Nullable (QGenExpr context be s)) a
QGenExpr context be s (Maybe a)
y)
                                           Columnar'
  (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
   :*: Columnar' (Nullable (QGenExpr context be s)))
  a
-> StateT
     (Maybe (QGenExpr context be s SqlBool))
     Identity
     (Columnar'
        (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
         :*: Columnar' (Nullable (QGenExpr context be s)))
        a)
forall (m :: * -> *) a. Monad m => a -> m a
return Columnar'
  (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
   :*: Columnar' (Nullable (QGenExpr context be s)))
  a
x') (forall (c :: * -> Constraint) (tbl :: (* -> *) -> *).
(Beamable tbl, FieldsFulfillConstraintNullable c tbl) =>
tbl (Nullable (HasConstraint c))
forall (tbl :: (* -> *) -> *).
(Beamable tbl,
 FieldsFulfillConstraintNullable (HasSqlEqualityCheck be) tbl) =>
tbl (Nullable (HasConstraint (HasSqlEqualityCheck be)))
withNullableConstraints @(HasSqlEqualityCheck be) tbl (Nullable (HasConstraint (HasSqlEqualityCheck be)))
-> tbl (Nullable (QGenExpr context be s))
-> tbl
     (Columnar' (Nullable (HasConstraint (HasSqlEqualityCheck be)))
      :*: Columnar' (Nullable (QGenExpr context be s)))
forall (tbl :: (* -> *) -> *) (f :: * -> *) (g :: * -> *).
Beamable tbl =>
tbl f -> tbl g -> tbl (Columnar' f :*: Columnar' g)
`alongsideTable` tbl (Nullable (QGenExpr context be s))
a) tbl (Nullable (QGenExpr context be s))
b) Maybe (QGenExpr context be s SqlBool)
forall a. Maybe a
Nothing
            in QGenExpr context be s SqlBool
-> Maybe (QGenExpr context be s SqlBool)
-> QGenExpr context be s SqlBool
forall a. a -> Maybe a -> a
fromMaybe ((TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s SqlBool
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\TablePrefix
_ -> 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 SqlBool)
e
  tbl (Nullable (QGenExpr context be s))
a /=?. :: tbl (Nullable (QGenExpr context be s))
-> tbl (Nullable (QGenExpr context be s))
-> QGenExpr context be s SqlBool
/=?. tbl (Nullable (QGenExpr context be s))
b = QGenExpr context be s SqlBool -> QGenExpr context be s SqlBool
forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s SqlBool
sqlNot_ (tbl (Nullable (QGenExpr context be s))
a tbl (Nullable (QGenExpr context be s))
-> tbl (Nullable (QGenExpr context be s))
-> QGenExpr context be s SqlBool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. tbl (Nullable (QGenExpr context be s))
b)


-- * Comparisons

-- | Class for expression types or expression containers for which there is a
--   notion of ordering.
--
--   Instances are provided to check the ordering of expressions of the same
--   type. Since there is no universal notion of ordering for an arbitrary
--   number of expressions, no instance is provided for 'Beamable' types.
class SqlOrd expr e | e -> expr where

  (<.), (>.), (<=.), (>=.) :: e -> e -> expr Bool

-- | Class for things which can be /quantifiably/ compared.
class SqlOrd expr e =>
  SqlOrdQuantified expr quantified e | e -> expr quantified where

  (<*.), (>*.), (<=*.), (>=*.) :: e -> quantified  -> expr Bool

instance BeamSqlBackend be =>
  SqlOrd (QGenExpr context be s) (QGenExpr context be s a) where

  <. :: QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s Bool
(<.) = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s Bool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
ltE Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. Maybe a
Nothing)
  >. :: QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s Bool
(>.) = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s Bool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
gtE Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. Maybe a
Nothing)
  <=. :: QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s Bool
(<=.) = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s Bool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
leE Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. Maybe a
Nothing)
  >=. :: QGenExpr context be s a
-> QGenExpr context be s a -> QGenExpr context be s Bool
(>=.) = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s Bool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
geE Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. Maybe a
Nothing)

instance BeamSqlBackend be =>
  SqlOrdQuantified (QGenExpr context be s) (QQuantified be s a) (QGenExpr context be s a) where
  QGenExpr context be s a
a <*. :: QGenExpr context be s a
-> QQuantified be s a -> QGenExpr context be s Bool
<*. QQuantified BeamSqlBackendExpressionQuantifierSyntax be
q WithExprContext (BeamSqlBackendExpressionSyntax be)
b = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s Any
-> QGenExpr context be s Bool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
ltE (Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Maybe
     (Sql92ExpressionQuantifierSyntax
        (Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. a -> Maybe a
Just Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s Any
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
b)
  QGenExpr context be s a
a <=*. :: QGenExpr context be s a
-> QQuantified be s a -> QGenExpr context be s Bool
<=*. QQuantified BeamSqlBackendExpressionQuantifierSyntax be
q WithExprContext (BeamSqlBackendExpressionSyntax be)
b = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s Any
-> QGenExpr context be s Bool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
leE (Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Maybe
     (Sql92ExpressionQuantifierSyntax
        (Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. a -> Maybe a
Just Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s Any
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
b)
  QGenExpr context be s a
a >*. :: QGenExpr context be s a
-> QQuantified be s a -> QGenExpr context be s Bool
>*. QQuantified BeamSqlBackendExpressionQuantifierSyntax be
q WithExprContext (BeamSqlBackendExpressionSyntax be)
b = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s Any
-> QGenExpr context be s Bool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
gtE (Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Maybe
     (Sql92ExpressionQuantifierSyntax
        (Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. a -> Maybe a
Just Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s Any
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
b)
  QGenExpr context be s a
a >=*. :: QGenExpr context be s a
-> QQuantified be s a -> QGenExpr context be s Bool
>=*. QQuantified BeamSqlBackendExpressionQuantifierSyntax be
q WithExprContext (BeamSqlBackendExpressionSyntax be)
b = (BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s Any
-> QGenExpr context be s Bool
forall be context s a b c.
BeamSqlBackend be =>
(BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be
 -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s a
-> QGenExpr context be s b
-> QGenExpr context be s c
qBinOpE (Maybe
  (Sql92ExpressionQuantifierSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
-> Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
geE (Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
-> Maybe
     (Sql92ExpressionQuantifierSyntax
        (Sql92UpdateExpressionSyntax
           (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
forall a. a -> Maybe a
Just Sql92ExpressionQuantifierSyntax
  (Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s Any
forall context be s t.
(TablePrefix -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext (BeamSqlBackendExpressionSyntax be)
b)

instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Text
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Integer
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Int
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Int8
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Int16
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Int32
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Int64
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Word
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Word8
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Word16
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Word32
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Word64
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Double
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Float
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Bool
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) UTCTime
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) LocalTime
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) Day
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlEqualityCheck (MockSqlBackend cmd) TimeOfDay
instance ( BeamSqlBackend (MockSqlBackend cmd)
         , HasSqlEqualityCheck (MockSqlBackend cmd) a
         ) => HasSqlEqualityCheck (MockSqlBackend cmd) (Tagged t a)

instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Text
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Integer
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Int
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Int8
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Int16
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Int32
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Int64
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Word
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Word8
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Word16
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Word32
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Word64
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Double
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Float
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Bool
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) UTCTime
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) LocalTime
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) Day
instance BeamSqlBackend (MockSqlBackend cmd) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) TimeOfDay
instance ( BeamSqlBackend (MockSqlBackend cmd)
         , HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) a
         ) => HasSqlQuantifiedEqualityCheck (MockSqlBackend cmd) (Tagged t a)