{-# 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_

  , inQuery_

  , 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_ :: forall context syntax s.
QGenExpr context syntax s Bool -> QGenExpr context syntax s SqlBool
sqlBool_ (QExpr Text -> BeamSqlBackendExpressionSyntax syntax
s) = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr Text -> BeamSqlBackendExpressionSyntax syntax
s

-- | SQL @IS TRUE@ operator
isTrue_ :: BeamSqlBackend be
        => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isTrue_ :: forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isTrue_ (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s) = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isTrueE Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s)

-- | SQL @IS NOT TRUE@ operator
isNotTrue_ :: BeamSqlBackend be
           => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotTrue_ :: forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotTrue_ (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s) = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isNotTrueE Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s)

-- | SQL @IS FALSE@ operator
isFalse_ :: BeamSqlBackend be
         => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isFalse_ :: forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isFalse_ (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s) = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isFalseE Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s)

-- | SQL @IS NOT FALSE@ operator
isNotFalse_ :: BeamSqlBackend be
            => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotFalse_ :: forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotFalse_ (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s) = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isNotFalseE Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s)

-- | SQL @IS UNKNOWN@ operator
isUnknown_ :: BeamSqlBackend be
           => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isUnknown_ :: forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isUnknown_ (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s) = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isUnknownE Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s)

-- | SQL @IS NOT UNKNOWN@ operator
isNotUnknown_ :: BeamSqlBackend be
              => QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotUnknown_ :: forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s Bool
isNotUnknown_ (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
s) = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall expr. IsSql92ExpressionSyntax expr => expr -> expr
isNotUnknownE Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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_ :: forall be context s.
BeamSqlBackend be =>
Bool -> QGenExpr context be s SqlBool -> QGenExpr context be s Bool
unknownAs_ Bool
False = 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  = 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_ :: forall context be s.
QGenExpr context be s SqlBool -> QGenExpr context be s (Maybe Bool)
possiblyNullBool_ (QExpr Text -> BeamSqlBackendExpressionSyntax be
e) = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr Text -> BeamSqlBackendExpressionSyntax be
e

-- | Convert a possibly @NULL@ 'Bool' to a 'SqlBool'.
fromPossiblyNullBool_ :: QGenExpr context be s (Maybe Bool) -> QGenExpr context be s SqlBool
fromPossiblyNullBool_ :: forall context be s.
QGenExpr context be s (Maybe Bool) -> QGenExpr context be s SqlBool
fromPossiblyNullBool_ (QExpr Text -> BeamSqlBackendExpressionSyntax be
e) = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr Text -> 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_ :: 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)
s = forall be s r.
BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s r
QQuantified forall quantifier. IsSql92QuantifierSyntax quantifier => quantifier
quantifyOverAll (\Text
tblPfx -> forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionSelectSyntax expr -> expr
subqueryE (forall be a (db :: (* -> *) -> *) s.
(HasQBuilder be, Projectible be a) =>
Text -> Q be db s a -> BeamSqlBackendSelectSyntax be
buildSqlQuery Text
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_ :: forall s a be.
BeamSqlBackend be =>
[QExpr be s a] -> QQuantified be s a
allIn_ [QExpr be s a]
es = forall be s r.
BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s r
QQuantified forall quantifier. IsSql92QuantifierSyntax quantifier => quantifier
quantifyOverAll (forall expr. IsSql92ExpressionSyntax expr => [expr] -> expr
quantifierListE forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
e) -> Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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_ :: 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)
s = forall be s r.
BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s r
QQuantified forall quantifier. IsSql92QuantifierSyntax quantifier => quantifier
quantifyOverAny (\Text
tblPfx -> forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionSelectSyntax expr -> expr
subqueryE (forall be a (db :: (* -> *) -> *) s.
(HasQBuilder be, Projectible be a) =>
Text -> Q be db s a -> BeamSqlBackendSelectSyntax be
buildSqlQuery Text
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_ :: forall s a be.
BeamSqlBackend be =>
[QExpr be s a] -> QQuantified be s a
anyIn_ [QExpr be s a]
es = forall be s r.
BeamSqlBackendExpressionQuantifierSyntax be
-> WithExprContext (BeamSqlBackendExpressionSyntax be)
-> QQuantified be s r
QQuantified forall quantifier. IsSql92QuantifierSyntax quantifier => quantifier
quantifyOverAny (forall expr. IsSql92ExpressionSyntax expr => [expr] -> expr
quantifierListE forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
e) -> Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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_ :: forall be context s a.
BeamSqlBackend be =>
QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s a
-> QGenExpr context be s Bool
between_ (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
a) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
min_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
max_) =
  forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 forall expr.
IsSql92ExpressionSyntax expr =>
expr -> expr -> expr -> expr
betweenE Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
a Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
min_ Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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
_ [] = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax Bool
False)))
  in_ (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
row) [QGenExpr context be s a]
options = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql92ExpressionSyntax expr => expr -> [expr] -> expr
inE forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
row forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
o) -> Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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 = 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)
_ [] = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax Bool
False)))
  in_ table (QGenExpr context be s)
row [table (QGenExpr context be s)]
options = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall be.
HasSqlInTable be =>
Proxy be
-> BeamSqlBackendExpressionSyntax be
-> [BeamSqlBackendExpressionSyntax be]
-> BeamSqlBackendExpressionSyntax be
inRowValuesE (forall {k} (t :: k). Proxy t
Proxy @be) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> table (QGenExpr context be s)
-> Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
toExpr table (QGenExpr context be s)
row forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM table (QGenExpr context be s)
-> Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
toExpr [table (QGenExpr context be s)]
options))
    where toExpr :: table (QGenExpr context be s) -> TablePrefix -> BeamSqlBackendExpressionSyntax be
          toExpr :: table (QGenExpr context be s)
-> Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
toExpr = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall expr. IsSql92ExpressionSyntax expr => [expr] -> expr
rowE forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (table :: (* -> *) -> *) (f :: * -> *) b.
Beamable table =>
(forall a. Columnar' f a -> b) -> table f -> [b]
allBeamValues (\(Columnar' (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
x)) -> Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
x)

infix 4 `between_`, `in_`, `inQuery_`

inQuery_ :: (HasQBuilder be, BeamSqlBackend be)
         => QGenExpr ctx be s a -> Q be db s (QExpr be s a) -> QGenExpr ctx be s Bool
inQuery_ :: forall be ctx s a (db :: (* -> *) -> *).
(HasQBuilder be, BeamSqlBackend be) =>
QGenExpr ctx be s a
-> Q be db s (QExpr be s a) -> QGenExpr ctx be s Bool
inQuery_ (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
needle) Q be db s (QExpr be s a)
haystack = forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr.
IsSql92ExpressionSyntax expr =>
expr -> Sql92ExpressionSelectSyntax expr -> expr
inSelectE forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
needle forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a b c. (a -> b -> c) -> b -> a -> c
flip forall be a (db :: (* -> *) -> *) s.
(HasQBuilder be, Projectible be a) =>
Text -> Q be db s a -> BeamSqlBackendSelectSyntax be
buildSqlQuery Q be db s (QExpr be s a)
haystack)

-- | 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
_ = forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
eqE forall a. Maybe a
Nothing
  sqlNeqE Proxy a
_ Proxy be
_ = forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
neqE 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
_ = forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
eqE forall a. Maybe a
Nothing
  sqlNeqTriE Proxy a
_ Proxy be
_ = forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
neqE 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
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
sqlEqE Proxy (Maybe a)
_ Proxy be
_ Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
a Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
b = forall expr.
IsSql92ExpressionSyntax expr =>
expr -> expr -> expr -> expr
eqMaybeE Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
a Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
b (forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqE (forall {k} (t :: k). Proxy t
Proxy @a) (forall {k} (t :: k). Proxy t
Proxy @be) Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
a Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
b)
  sqlNeqE :: Proxy (Maybe a)
-> Proxy be
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
sqlNeqE Proxy (Maybe a)
_ Proxy be
_ Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
a Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
b = forall expr.
IsSql92ExpressionSyntax expr =>
expr -> expr -> expr -> expr
neqMaybeE Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
a Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
b (forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqE (forall {k} (t :: k). Proxy t
Proxy @a) (forall {k} (t :: k). Proxy t
Proxy @be) Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
a Sql92SelectTableExpressionSyntax
  (Sql92SelectSelectTableSyntax
     (Sql92SelectSyntax (BeamSqlBackendSyntax 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)
_ = forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqE (forall {k} (t :: k). Proxy t
Proxy @a)
  sqlNeqE :: Proxy (SqlSerial a)
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqE Proxy (SqlSerial a)
_ = forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqE (forall {k} (t :: k). Proxy t
Proxy @a)

  sqlEqTriE :: Proxy (SqlSerial a)
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqTriE Proxy (SqlSerial a)
_ = forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqTriE (forall {k} (t :: k). Proxy t
Proxy @a)
  sqlNeqTriE :: Proxy (SqlSerial a)
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqTriE Proxy (SqlSerial a)
_ = forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqTriE (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
_ = forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
eqE
  sqlQNeqE Proxy a
_ Proxy 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)
_ = forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQEqE (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)
_ = forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQNeqE (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)
_ = forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQEqE (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)
_ = forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQNeqE (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
(==.) = 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 (forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqE (forall {k} (t :: k). Proxy t
Proxy @a) (forall {k} (t :: k). Proxy t
Proxy @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 (forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqE (forall {k} (t :: k). Proxy t
Proxy @a) (forall {k} (t :: k). Proxy t
Proxy @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 (forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlEqTriE (forall {k} (t :: k). Proxy t
Proxy @a) (forall {k} (t :: k). Proxy t
Proxy @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 (forall be a.
HasSqlEqualityCheck be a =>
Proxy a
-> Proxy be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlNeqTriE (forall {k} (t :: k). Proxy t
Proxy @a) (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
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
b = 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 (forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQEqE (forall {k} (t :: k). Proxy t
Proxy @a) (forall {k} (t :: k). Proxy t
Proxy @be) (forall a. a -> Maybe a
Just BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
b = 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 (forall be a.
HasSqlQuantifiedEqualityCheck be a =>
Proxy a
-> Proxy be
-> Maybe (BeamSqlBackendExpressionQuantifierSyntax be)
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
-> BeamSqlBackendExpressionSyntax be
sqlQNeqE (forall {k} (t :: k). Proxy t
Proxy @a) (forall {k} (t :: k). Proxy t
Proxy @be) (forall a. a -> Maybe a
Just BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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) = forall s a. State s a -> s -> (a, s)
runState (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 (HasSqlEqualityCheck be) a
Columnar (HasConstraint (HasSqlEqualityCheck be)) a
HasConstraint :*: Columnar' Columnar (QGenExpr context be s) a
x)) (Columnar' Columnar (QGenExpr context be s) a
y) ->
                                       do 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 -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Columnar (QGenExpr context be s) a
x forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. Columnar (QGenExpr context be s) a
y
                                                      Just QGenExpr context be s Bool
expr' -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ QGenExpr context be s Bool
expr' 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
x forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. Columnar (QGenExpr context be s) a
y)
                                          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)
withConstraints @(HasSqlEqualityCheck be) 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) forall a. Maybe a
Nothing
            in forall a. a -> Maybe a -> a
fromMaybe (forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\Text
_ -> forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (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 = forall be context s.
BeamSqlBackend be =>
QGenExpr context be s Bool -> QGenExpr context be s Bool
not_ (tbl (QGenExpr context be s)
a 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) = forall s a. State s a -> s -> (a, s)
runState (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 (HasSqlEqualityCheck be) a
Columnar (HasConstraint (HasSqlEqualityCheck be)) a
HasConstraint :*: Columnar' Columnar (QGenExpr context be s) a
x)) (Columnar' Columnar (QGenExpr context be s) a
y) ->
                                        do 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 -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Columnar (QGenExpr context be s) a
x forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. Columnar (QGenExpr context be s) a
y
                                                       Just QGenExpr context be s SqlBool
expr' -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ QGenExpr context be s SqlBool
expr' 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
x forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. Columnar (QGenExpr context be s) a
y)
                                           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)
withConstraints @(HasSqlEqualityCheck be) 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) forall a. Maybe a
Nothing
            in forall a. a -> Maybe a -> a
fromMaybe (forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\Text
_ -> forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (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 = forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s SqlBool
sqlNot_ (tbl (QGenExpr context be s)
a 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) = forall s a. State s a -> s -> (a, s)
runState (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 (HasSqlEqualityCheck be) (Maybe a)
Columnar (Nullable (HasConstraint (HasSqlEqualityCheck be))) a
HasConstraint :*: Columnar' Columnar (Nullable (QGenExpr context be s)) a
x)) (Columnar' Columnar (Nullable (QGenExpr context be s)) a
y) -> do
                                          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 -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Columnar (Nullable (QGenExpr context be s)) a
x forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. Columnar (Nullable (QGenExpr context be s)) a
y
                                                      Just QGenExpr context be s Bool
expr' -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ QGenExpr context be s Bool
expr' 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
x forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. Columnar (Nullable (QGenExpr context be s)) a
y)
                                          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))
withNullableConstraints @(HasSqlEqualityCheck be) 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) forall a. Maybe a
Nothing
            in forall a. a -> Maybe a -> a
fromMaybe (forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\Text
_ -> forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (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 = forall be context s.
BeamSqlBackend be =>
QGenExpr context be s Bool -> QGenExpr context be s Bool
not_ (tbl (Nullable (QGenExpr context be s))
a 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) = forall s a. State s a -> s -> (a, s)
runState (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 (HasSqlEqualityCheck be) (Maybe a)
Columnar (Nullable (HasConstraint (HasSqlEqualityCheck be))) a
HasConstraint :*: Columnar' Columnar (Nullable (QGenExpr context be s)) a
x)) (Columnar' Columnar (Nullable (QGenExpr context be s)) a
y) ->
                                        do 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 -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Columnar (Nullable (QGenExpr context be s)) a
x forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. Columnar (Nullable (QGenExpr context be s)) a
y
                                                       Just QGenExpr context be s SqlBool
expr' -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ QGenExpr context be s SqlBool
expr' 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
x forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr SqlBool
==?. Columnar (Nullable (QGenExpr context be s)) a
y)
                                           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))
withNullableConstraints @(HasSqlEqualityCheck be) 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) forall a. Maybe a
Nothing
            in forall a. a -> Maybe a -> a
fromMaybe (forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\Text
_ -> forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (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 = forall be context s.
BeamSqlBackend be =>
QGenExpr context be s SqlBool -> QGenExpr context be s SqlBool
sqlNot_ (tbl (Nullable (QGenExpr context be s))
a 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
(<.) = 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 (forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
ltE forall a. Maybe a
Nothing)
  >. :: 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 (forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
gtE forall a. Maybe a
Nothing)
  <=. :: 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 (forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
leE forall a. Maybe a
Nothing)
  >=. :: 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 (forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
geE 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
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
b = 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 (forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
ltE (forall a. a -> Maybe a
Just BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
b = 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 (forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
leE (forall a. a -> Maybe a
Just BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
b = 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 (forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
gtE (forall a. a -> Maybe a
Just BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
b = 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 (forall expr.
IsSql92ExpressionSyntax expr =>
Maybe (Sql92ExpressionQuantifierSyntax expr)
-> expr -> expr -> expr
geE (forall a. a -> Maybe a
Just BeamSqlBackendExpressionQuantifierSyntax be
q)) QGenExpr context be s a
a (forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr WithExprContext
  (Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax 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)