-- | Postgres SQL DML
--
-- Provide types and combinators for defining Postgres SQL queries and mutations.
module Hasura.Backends.Postgres.SQL.DML
  ( ColumnAlias (..),
    TableAlias (..),
    BinOp (AndOp, OrOp),
    BoolExp (..),
    TopLevelCTE (CTEDelete, CTEInsert, CTESelect, CTEUpdate, CTEUnsafeRawSQL),
    InnerCTE (..),
    CompareOp (SContainedIn, SContains, SEQ, SGT, SGTE, SHasKey, SHasKeysAll, SHasKeysAny, SILIKE, SIREGEX, SLIKE, SLT, SLTE, SMatchesFulltext, SNE, SNILIKE, SNIREGEX, SNLIKE, SNREGEX, SNSIMILAR, SREGEX, SSIMILAR),
    CountType (CTDistinct, CTSimple, CTStar),
    DistinctExpr (DistinctOn, DistinctSimple),
    Extractor (..),
    FromExp (..),
    FromItem (..),
    FunctionAlias (FunctionAlias),
    FunctionDefinitionListItem (..),
    FunctionArgs (FunctionArgs),
    FunctionExp (FunctionExp),
    GroupByExp (GroupByExp),
    HavingExp (HavingExp),
    JoinCond (..),
    JoinExpr (JoinExpr),
    JoinType (Inner, LeftOuter),
    Lateral (Lateral),
    LimitExp (LimitExp),
    NullsOrder (NullsFirst, NullsLast),
    OffsetExp (OffsetExp),
    OrderByExp (..),
    OrderByItem (OrderByItem, oExpression),
    OrderType (OTAsc, OTDesc),
    QIdentifier (QIdentifier),
    Qual (QualTable, QualVar, QualifiedIdentifier),
    RetExp (RetExp),
    SQLConflict (..),
    SQLConflictTarget (SQLColumn, SQLConstraint),
    SQLDelete (SQLDelete),
    SQLExp (..),
    SQLInsert (SQLInsert, siCols, siConflict, siRet, siTable, siValues),
    SQLOp (SQLOp),
    ColumnOp (..),
    SQLUpdate (..),
    Select (Select, selCTEs, selDistinct, selExtr, selFrom, selLimit, selOffset, selOrderBy, selWhere),
    SelectWith,
    SelectWithG (..),
    SetExp (SetExp),
    SetExpItem (..),
    TupleExp (TupleExp),
    TypeAnn (TypeAnn),
    ValuesExp (ValuesExp),
    WhereFrag (WhereFrag),
    dummySelectList,
    applyJsonBuildArray,
    applyJsonBuildObj,
    applyRowToJson,
    applyUppercase,
    boolTypeAnn,
    buildUpsertSetExp,
    columnDefaultValue,
    countStar,
    handleIfNull,
    incOp,
    int64ToSQLExp,
    intToSQLExp,
    intTypeAnn,
    jsonTypeAnn,
    jsonbConcatOp,
    jsonbDeleteAtPathOp,
    jsonbDeleteOp,
    jsonbPathOp,
    jsonbTypeAnn,
    mkExists,
    mkExtr,
    mkFunctionAlias,
    mkIdenFromExp,
    mkLateralFromItem,
    mkQIdenExp,
    mkQIdentifier,
    mkQIdentifierTable,
    mkQual,
    mkRowExp,
    mkIdentifierSQLExp,
    mkSIdenExp,
    mkSQLOpExp,
    mkSelFromExp,
    mkSelFromItem,
    mkSelect,
    mkSelectWithFromItem,
    mkSimpleFromExp,
    mkTypeAnn,
    mulOp,
    numericTypeAnn,
    returningStar,
    selectStar,
    selectStar',
    simplifyBoolExp,
    textArrTypeAnn,
    textTypeAnn,
    mkColumnAlias,
    mkTableAlias,
    toTableAlias,
    tableAliasToIdentifier,
    toColumnAlias,
    tableIdentifierToColumnAlias,
  )
where

import Data.Aeson qualified as J
import Data.Aeson.Casing qualified as J
import Data.HashMap.Strict qualified as HashMap
import Data.Int (Int64)
import Data.String (fromString)
import Data.Text (pack)
import Data.Text.Extended
import Hasura.Backends.Postgres.SQL.Types
import Hasura.NativeQuery.Metadata
import Hasura.Prelude
import Hasura.SQL.Types
import Text.Builder qualified as TB

-- | An select statement that does not require mutation CTEs.
--
--   See 'SelectWithG' or 'SelectWith' for select statements with mutations as CTEs.
data Select = Select
  { -- | Unlike 'SelectWith', does not allow data-modifying statements (as those are only allowed at
    -- the top level of a query).
    Select -> [(TableAlias, InnerCTE)]
selCTEs :: [(TableAlias, InnerCTE)],
    Select -> Maybe DistinctExpr
selDistinct :: Maybe DistinctExpr,
    Select -> [Extractor]
selExtr :: [Extractor],
    Select -> Maybe FromExp
selFrom :: Maybe FromExp,
    Select -> Maybe WhereFrag
selWhere :: Maybe WhereFrag,
    Select -> Maybe GroupByExp
selGroupBy :: Maybe GroupByExp,
    Select -> Maybe HavingExp
selHaving :: Maybe HavingExp,
    Select -> Maybe OrderByExp
selOrderBy :: Maybe OrderByExp,
    Select -> Maybe LimitExp
selLimit :: Maybe LimitExp,
    Select -> Maybe OffsetExp
selOffset :: Maybe OffsetExp
  }
  deriving (Int -> Select -> ShowS
[Select] -> ShowS
Select -> String
(Int -> Select -> ShowS)
-> (Select -> String) -> ([Select] -> ShowS) -> Show Select
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Select -> ShowS
showsPrec :: Int -> Select -> ShowS
$cshow :: Select -> String
show :: Select -> String
$cshowList :: [Select] -> ShowS
showList :: [Select] -> ShowS
Show, Select -> Select -> Bool
(Select -> Select -> Bool)
-> (Select -> Select -> Bool) -> Eq Select
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Select -> Select -> Bool
== :: Select -> Select -> Bool
$c/= :: Select -> Select -> Bool
/= :: Select -> Select -> Bool
Eq, (forall x. Select -> Rep Select x)
-> (forall x. Rep Select x -> Select) -> Generic Select
forall x. Rep Select x -> Select
forall x. Select -> Rep Select x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Select -> Rep Select x
from :: forall x. Select -> Rep Select x
$cto :: forall x. Rep Select x -> Select
to :: forall x. Rep Select x -> Select
Generic, Typeable Select
Typeable Select
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Select -> c Select)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Select)
-> (Select -> Constr)
-> (Select -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Select))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Select))
-> ((forall b. Data b => b -> b) -> Select -> Select)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Select -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Select -> r)
-> (forall u. (forall d. Data d => d -> u) -> Select -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Select -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Select -> m Select)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Select -> m Select)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Select -> m Select)
-> Data Select
Select -> Constr
Select -> DataType
(forall b. Data b => b -> b) -> Select -> Select
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Select -> u
forall u. (forall d. Data d => d -> u) -> Select -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Select -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Select -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Select -> m Select
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Select -> m Select
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Select
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Select -> c Select
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Select)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Select)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Select -> c Select
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Select -> c Select
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Select
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Select
$ctoConstr :: Select -> Constr
toConstr :: Select -> Constr
$cdataTypeOf :: Select -> DataType
dataTypeOf :: Select -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Select)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Select)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Select)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Select)
$cgmapT :: (forall b. Data b => b -> b) -> Select -> Select
gmapT :: (forall b. Data b => b -> b) -> Select -> Select
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Select -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Select -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Select -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Select -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Select -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Select -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Select -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Select -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Select -> m Select
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Select -> m Select
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Select -> m Select
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Select -> m Select
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Select -> m Select
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Select -> m Select
Data)

instance NFData Select

instance Hashable Select

-- | An empty select statement.
mkSelect :: Select
mkSelect :: Select
mkSelect =
  [(TableAlias, InnerCTE)]
-> Maybe DistinctExpr
-> [Extractor]
-> Maybe FromExp
-> Maybe WhereFrag
-> Maybe GroupByExp
-> Maybe HavingExp
-> Maybe OrderByExp
-> Maybe LimitExp
-> Maybe OffsetExp
-> Select
Select
    []
    Maybe DistinctExpr
forall a. Maybe a
Nothing
    []
    Maybe FromExp
forall a. Maybe a
Nothing
    Maybe WhereFrag
forall a. Maybe a
Nothing
    Maybe GroupByExp
forall a. Maybe a
Nothing
    Maybe HavingExp
forall a. Maybe a
Nothing
    Maybe OrderByExp
forall a. Maybe a
Nothing
    Maybe LimitExp
forall a. Maybe a
Nothing
    Maybe OffsetExp
forall a. Maybe a
Nothing

-- | A dummy select list to avoid an empty select list, which doesn't work for cockroach db.
--   This is just the value @1@ without an alias.
dummySelectList :: [Extractor]
dummySelectList :: [Extractor]
dummySelectList = [SQLExp -> Maybe ColumnAlias -> Extractor
Extractor (Text -> SQLExp
SEUnsafe Text
"1") Maybe ColumnAlias
forall a. Maybe a
Nothing]

newtype LimitExp
  = LimitExp SQLExp
  deriving (Int -> LimitExp -> ShowS
[LimitExp] -> ShowS
LimitExp -> String
(Int -> LimitExp -> ShowS)
-> (LimitExp -> String) -> ([LimitExp] -> ShowS) -> Show LimitExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LimitExp -> ShowS
showsPrec :: Int -> LimitExp -> ShowS
$cshow :: LimitExp -> String
show :: LimitExp -> String
$cshowList :: [LimitExp] -> ShowS
showList :: [LimitExp] -> ShowS
Show, LimitExp -> LimitExp -> Bool
(LimitExp -> LimitExp -> Bool)
-> (LimitExp -> LimitExp -> Bool) -> Eq LimitExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LimitExp -> LimitExp -> Bool
== :: LimitExp -> LimitExp -> Bool
$c/= :: LimitExp -> LimitExp -> Bool
/= :: LimitExp -> LimitExp -> Bool
Eq, LimitExp -> ()
(LimitExp -> ()) -> NFData LimitExp
forall a. (a -> ()) -> NFData a
$crnf :: LimitExp -> ()
rnf :: LimitExp -> ()
NFData, Typeable LimitExp
Typeable LimitExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> LimitExp -> c LimitExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c LimitExp)
-> (LimitExp -> Constr)
-> (LimitExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c LimitExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LimitExp))
-> ((forall b. Data b => b -> b) -> LimitExp -> LimitExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> LimitExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> LimitExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> LimitExp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> LimitExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> LimitExp -> m LimitExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> LimitExp -> m LimitExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> LimitExp -> m LimitExp)
-> Data LimitExp
LimitExp -> Constr
LimitExp -> DataType
(forall b. Data b => b -> b) -> LimitExp -> LimitExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> LimitExp -> u
forall u. (forall d. Data d => d -> u) -> LimitExp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LimitExp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LimitExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> LimitExp -> m LimitExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LimitExp -> m LimitExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LimitExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LimitExp -> c LimitExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LimitExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LimitExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LimitExp -> c LimitExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LimitExp -> c LimitExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LimitExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LimitExp
$ctoConstr :: LimitExp -> Constr
toConstr :: LimitExp -> Constr
$cdataTypeOf :: LimitExp -> DataType
dataTypeOf :: LimitExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LimitExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LimitExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LimitExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LimitExp)
$cgmapT :: (forall b. Data b => b -> b) -> LimitExp -> LimitExp
gmapT :: (forall b. Data b => b -> b) -> LimitExp -> LimitExp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LimitExp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LimitExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LimitExp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LimitExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> LimitExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> LimitExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> LimitExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> LimitExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> LimitExp -> m LimitExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> LimitExp -> m LimitExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LimitExp -> m LimitExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LimitExp -> m LimitExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LimitExp -> m LimitExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LimitExp -> m LimitExp
Data, Eq LimitExp
Eq LimitExp
-> (Int -> LimitExp -> Int)
-> (LimitExp -> Int)
-> Hashable LimitExp
Int -> LimitExp -> Int
LimitExp -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> LimitExp -> Int
hashWithSalt :: Int -> LimitExp -> Int
$chash :: LimitExp -> Int
hash :: LimitExp -> Int
Hashable)

instance ToSQL LimitExp where
  toSQL :: LimitExp -> Builder
toSQL (LimitExp SQLExp
se) =
    Builder
"LIMIT" Builder -> Builder -> Builder
<~> SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
se

newtype OffsetExp
  = OffsetExp SQLExp
  deriving (Int -> OffsetExp -> ShowS
[OffsetExp] -> ShowS
OffsetExp -> String
(Int -> OffsetExp -> ShowS)
-> (OffsetExp -> String)
-> ([OffsetExp] -> ShowS)
-> Show OffsetExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OffsetExp -> ShowS
showsPrec :: Int -> OffsetExp -> ShowS
$cshow :: OffsetExp -> String
show :: OffsetExp -> String
$cshowList :: [OffsetExp] -> ShowS
showList :: [OffsetExp] -> ShowS
Show, OffsetExp -> OffsetExp -> Bool
(OffsetExp -> OffsetExp -> Bool)
-> (OffsetExp -> OffsetExp -> Bool) -> Eq OffsetExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OffsetExp -> OffsetExp -> Bool
== :: OffsetExp -> OffsetExp -> Bool
$c/= :: OffsetExp -> OffsetExp -> Bool
/= :: OffsetExp -> OffsetExp -> Bool
Eq, OffsetExp -> ()
(OffsetExp -> ()) -> NFData OffsetExp
forall a. (a -> ()) -> NFData a
$crnf :: OffsetExp -> ()
rnf :: OffsetExp -> ()
NFData, Typeable OffsetExp
Typeable OffsetExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> OffsetExp -> c OffsetExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c OffsetExp)
-> (OffsetExp -> Constr)
-> (OffsetExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c OffsetExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OffsetExp))
-> ((forall b. Data b => b -> b) -> OffsetExp -> OffsetExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> OffsetExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> OffsetExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> OffsetExp -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> OffsetExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp)
-> Data OffsetExp
OffsetExp -> Constr
OffsetExp -> DataType
(forall b. Data b => b -> b) -> OffsetExp -> OffsetExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> OffsetExp -> u
forall u. (forall d. Data d => d -> u) -> OffsetExp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetExp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OffsetExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OffsetExp -> c OffsetExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OffsetExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OffsetExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OffsetExp -> c OffsetExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OffsetExp -> c OffsetExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OffsetExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OffsetExp
$ctoConstr :: OffsetExp -> Constr
toConstr :: OffsetExp -> Constr
$cdataTypeOf :: OffsetExp -> DataType
dataTypeOf :: OffsetExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OffsetExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OffsetExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OffsetExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OffsetExp)
$cgmapT :: (forall b. Data b => b -> b) -> OffsetExp -> OffsetExp
gmapT :: (forall b. Data b => b -> b) -> OffsetExp -> OffsetExp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetExp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetExp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> OffsetExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> OffsetExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OffsetExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OffsetExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OffsetExp -> m OffsetExp
Data, Eq OffsetExp
Eq OffsetExp
-> (Int -> OffsetExp -> Int)
-> (OffsetExp -> Int)
-> Hashable OffsetExp
Int -> OffsetExp -> Int
OffsetExp -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> OffsetExp -> Int
hashWithSalt :: Int -> OffsetExp -> Int
$chash :: OffsetExp -> Int
hash :: OffsetExp -> Int
Hashable)

instance ToSQL OffsetExp where
  toSQL :: OffsetExp -> Builder
toSQL (OffsetExp SQLExp
se) =
    Builder
"OFFSET" Builder -> Builder -> Builder
<~> SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
se

newtype OrderByExp
  = OrderByExp (NonEmpty OrderByItem)
  deriving (Int -> OrderByExp -> ShowS
[OrderByExp] -> ShowS
OrderByExp -> String
(Int -> OrderByExp -> ShowS)
-> (OrderByExp -> String)
-> ([OrderByExp] -> ShowS)
-> Show OrderByExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OrderByExp -> ShowS
showsPrec :: Int -> OrderByExp -> ShowS
$cshow :: OrderByExp -> String
show :: OrderByExp -> String
$cshowList :: [OrderByExp] -> ShowS
showList :: [OrderByExp] -> ShowS
Show, OrderByExp -> OrderByExp -> Bool
(OrderByExp -> OrderByExp -> Bool)
-> (OrderByExp -> OrderByExp -> Bool) -> Eq OrderByExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OrderByExp -> OrderByExp -> Bool
== :: OrderByExp -> OrderByExp -> Bool
$c/= :: OrderByExp -> OrderByExp -> Bool
/= :: OrderByExp -> OrderByExp -> Bool
Eq, OrderByExp -> ()
(OrderByExp -> ()) -> NFData OrderByExp
forall a. (a -> ()) -> NFData a
$crnf :: OrderByExp -> ()
rnf :: OrderByExp -> ()
NFData, Typeable OrderByExp
Typeable OrderByExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> OrderByExp -> c OrderByExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c OrderByExp)
-> (OrderByExp -> Constr)
-> (OrderByExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c OrderByExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c OrderByExp))
-> ((forall b. Data b => b -> b) -> OrderByExp -> OrderByExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> OrderByExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> OrderByExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> OrderByExp -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> OrderByExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp)
-> Data OrderByExp
OrderByExp -> Constr
OrderByExp -> DataType
(forall b. Data b => b -> b) -> OrderByExp -> OrderByExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> OrderByExp -> u
forall u. (forall d. Data d => d -> u) -> OrderByExp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByExp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OrderByExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OrderByExp -> c OrderByExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OrderByExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OrderByExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OrderByExp -> c OrderByExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OrderByExp -> c OrderByExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OrderByExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OrderByExp
$ctoConstr :: OrderByExp -> Constr
toConstr :: OrderByExp -> Constr
$cdataTypeOf :: OrderByExp -> DataType
dataTypeOf :: OrderByExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OrderByExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OrderByExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OrderByExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OrderByExp)
$cgmapT :: (forall b. Data b => b -> b) -> OrderByExp -> OrderByExp
gmapT :: (forall b. Data b => b -> b) -> OrderByExp -> OrderByExp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByExp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByExp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> OrderByExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> OrderByExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OrderByExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OrderByExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderByExp -> m OrderByExp
Data, Eq OrderByExp
Eq OrderByExp
-> (Int -> OrderByExp -> Int)
-> (OrderByExp -> Int)
-> Hashable OrderByExp
Int -> OrderByExp -> Int
OrderByExp -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> OrderByExp -> Int
hashWithSalt :: Int -> OrderByExp -> Int
$chash :: OrderByExp -> Int
hash :: OrderByExp -> Int
Hashable)

data OrderByItem = OrderByItem
  { OrderByItem -> SQLExp
oExpression :: SQLExp,
    OrderByItem -> Maybe OrderType
oOrdering :: Maybe OrderType,
    OrderByItem -> Maybe NullsOrder
oNullsOrder :: Maybe NullsOrder
  }
  deriving (Int -> OrderByItem -> ShowS
[OrderByItem] -> ShowS
OrderByItem -> String
(Int -> OrderByItem -> ShowS)
-> (OrderByItem -> String)
-> ([OrderByItem] -> ShowS)
-> Show OrderByItem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OrderByItem -> ShowS
showsPrec :: Int -> OrderByItem -> ShowS
$cshow :: OrderByItem -> String
show :: OrderByItem -> String
$cshowList :: [OrderByItem] -> ShowS
showList :: [OrderByItem] -> ShowS
Show, OrderByItem -> OrderByItem -> Bool
(OrderByItem -> OrderByItem -> Bool)
-> (OrderByItem -> OrderByItem -> Bool) -> Eq OrderByItem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OrderByItem -> OrderByItem -> Bool
== :: OrderByItem -> OrderByItem -> Bool
$c/= :: OrderByItem -> OrderByItem -> Bool
/= :: OrderByItem -> OrderByItem -> Bool
Eq, (forall x. OrderByItem -> Rep OrderByItem x)
-> (forall x. Rep OrderByItem x -> OrderByItem)
-> Generic OrderByItem
forall x. Rep OrderByItem x -> OrderByItem
forall x. OrderByItem -> Rep OrderByItem x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OrderByItem -> Rep OrderByItem x
from :: forall x. OrderByItem -> Rep OrderByItem x
$cto :: forall x. Rep OrderByItem x -> OrderByItem
to :: forall x. Rep OrderByItem x -> OrderByItem
Generic, Typeable OrderByItem
Typeable OrderByItem
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> OrderByItem -> c OrderByItem)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c OrderByItem)
-> (OrderByItem -> Constr)
-> (OrderByItem -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c OrderByItem))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c OrderByItem))
-> ((forall b. Data b => b -> b) -> OrderByItem -> OrderByItem)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> OrderByItem -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> OrderByItem -> r)
-> (forall u. (forall d. Data d => d -> u) -> OrderByItem -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> OrderByItem -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem)
-> Data OrderByItem
OrderByItem -> Constr
OrderByItem -> DataType
(forall b. Data b => b -> b) -> OrderByItem -> OrderByItem
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> OrderByItem -> u
forall u. (forall d. Data d => d -> u) -> OrderByItem -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByItem -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByItem -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OrderByItem
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OrderByItem -> c OrderByItem
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OrderByItem)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c OrderByItem)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OrderByItem -> c OrderByItem
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OrderByItem -> c OrderByItem
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OrderByItem
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OrderByItem
$ctoConstr :: OrderByItem -> Constr
toConstr :: OrderByItem -> Constr
$cdataTypeOf :: OrderByItem -> DataType
dataTypeOf :: OrderByItem -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OrderByItem)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OrderByItem)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c OrderByItem)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c OrderByItem)
$cgmapT :: (forall b. Data b => b -> b) -> OrderByItem -> OrderByItem
gmapT :: (forall b. Data b => b -> b) -> OrderByItem -> OrderByItem
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByItem -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByItem -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByItem -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OrderByItem -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> OrderByItem -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> OrderByItem -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OrderByItem -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OrderByItem -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderByItem -> m OrderByItem
Data)

instance NFData OrderByItem

instance Hashable OrderByItem

instance ToSQL OrderByItem where
  toSQL :: OrderByItem -> Builder
toSQL (OrderByItem SQLExp
expr Maybe OrderType
ordering Maybe NullsOrder
nullsOrder) =
    SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
expr Builder -> Builder -> Builder
<~> Maybe OrderType -> Builder
forall a. ToSQL a => a -> Builder
toSQL Maybe OrderType
ordering Builder -> Builder -> Builder
<~> Maybe NullsOrder -> Builder
forall a. ToSQL a => a -> Builder
toSQL Maybe NullsOrder
nullsOrder

-- | Order by ascending or descending
data OrderType = OTAsc | OTDesc
  deriving (Int -> OrderType -> ShowS
[OrderType] -> ShowS
OrderType -> String
(Int -> OrderType -> ShowS)
-> (OrderType -> String)
-> ([OrderType] -> ShowS)
-> Show OrderType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OrderType -> ShowS
showsPrec :: Int -> OrderType -> ShowS
$cshow :: OrderType -> String
show :: OrderType -> String
$cshowList :: [OrderType] -> ShowS
showList :: [OrderType] -> ShowS
Show, OrderType -> OrderType -> Bool
(OrderType -> OrderType -> Bool)
-> (OrderType -> OrderType -> Bool) -> Eq OrderType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OrderType -> OrderType -> Bool
== :: OrderType -> OrderType -> Bool
$c/= :: OrderType -> OrderType -> Bool
/= :: OrderType -> OrderType -> Bool
Eq, (forall x. OrderType -> Rep OrderType x)
-> (forall x. Rep OrderType x -> OrderType) -> Generic OrderType
forall x. Rep OrderType x -> OrderType
forall x. OrderType -> Rep OrderType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OrderType -> Rep OrderType x
from :: forall x. OrderType -> Rep OrderType x
$cto :: forall x. Rep OrderType x -> OrderType
to :: forall x. Rep OrderType x -> OrderType
Generic, Typeable OrderType
Typeable OrderType
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> OrderType -> c OrderType)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c OrderType)
-> (OrderType -> Constr)
-> (OrderType -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c OrderType))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OrderType))
-> ((forall b. Data b => b -> b) -> OrderType -> OrderType)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> OrderType -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> OrderType -> r)
-> (forall u. (forall d. Data d => d -> u) -> OrderType -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> OrderType -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> OrderType -> m OrderType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OrderType -> m OrderType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OrderType -> m OrderType)
-> Data OrderType
OrderType -> Constr
OrderType -> DataType
(forall b. Data b => b -> b) -> OrderType -> OrderType
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> OrderType -> u
forall u. (forall d. Data d => d -> u) -> OrderType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OrderType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OrderType -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OrderType -> m OrderType
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderType -> m OrderType
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OrderType
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OrderType -> c OrderType
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OrderType)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OrderType)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OrderType -> c OrderType
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OrderType -> c OrderType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OrderType
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OrderType
$ctoConstr :: OrderType -> Constr
toConstr :: OrderType -> Constr
$cdataTypeOf :: OrderType -> DataType
dataTypeOf :: OrderType -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OrderType)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OrderType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OrderType)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OrderType)
$cgmapT :: (forall b. Data b => b -> b) -> OrderType -> OrderType
gmapT :: (forall b. Data b => b -> b) -> OrderType -> OrderType
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OrderType -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OrderType -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OrderType -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OrderType -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> OrderType -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> OrderType -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OrderType -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OrderType -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OrderType -> m OrderType
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OrderType -> m OrderType
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderType -> m OrderType
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderType -> m OrderType
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderType -> m OrderType
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OrderType -> m OrderType
Data)

instance NFData OrderType

instance Hashable OrderType

instance ToSQL OrderType where
  toSQL :: OrderType -> Builder
toSQL OrderType
OTAsc = Builder
"ASC"
  toSQL OrderType
OTDesc = Builder
"DESC"

instance J.FromJSON OrderType where
  parseJSON :: Value -> Parser OrderType
parseJSON = Options -> Value -> Parser OrderType
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
J.genericParseJSON (Options -> Value -> Parser OrderType)
-> Options -> Value -> Parser OrderType
forall a b. (a -> b) -> a -> b
$ Options
J.defaultOptions {constructorTagModifier :: ShowS
J.constructorTagModifier = ShowS
J.snakeCase ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
2}

instance J.ToJSON OrderType where
  toJSON :: OrderType -> Value
toJSON = Options -> OrderType -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
J.genericToJSON (Options -> OrderType -> Value) -> Options -> OrderType -> Value
forall a b. (a -> b) -> a -> b
$ Options
J.defaultOptions {constructorTagModifier :: ShowS
J.constructorTagModifier = ShowS
J.snakeCase ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
2}

data NullsOrder
  = NullsFirst
  | NullsLast
  deriving (Int -> NullsOrder -> ShowS
[NullsOrder] -> ShowS
NullsOrder -> String
(Int -> NullsOrder -> ShowS)
-> (NullsOrder -> String)
-> ([NullsOrder] -> ShowS)
-> Show NullsOrder
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NullsOrder -> ShowS
showsPrec :: Int -> NullsOrder -> ShowS
$cshow :: NullsOrder -> String
show :: NullsOrder -> String
$cshowList :: [NullsOrder] -> ShowS
showList :: [NullsOrder] -> ShowS
Show, NullsOrder -> NullsOrder -> Bool
(NullsOrder -> NullsOrder -> Bool)
-> (NullsOrder -> NullsOrder -> Bool) -> Eq NullsOrder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NullsOrder -> NullsOrder -> Bool
== :: NullsOrder -> NullsOrder -> Bool
$c/= :: NullsOrder -> NullsOrder -> Bool
/= :: NullsOrder -> NullsOrder -> Bool
Eq, (forall x. NullsOrder -> Rep NullsOrder x)
-> (forall x. Rep NullsOrder x -> NullsOrder) -> Generic NullsOrder
forall x. Rep NullsOrder x -> NullsOrder
forall x. NullsOrder -> Rep NullsOrder x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NullsOrder -> Rep NullsOrder x
from :: forall x. NullsOrder -> Rep NullsOrder x
$cto :: forall x. Rep NullsOrder x -> NullsOrder
to :: forall x. Rep NullsOrder x -> NullsOrder
Generic, Typeable NullsOrder
Typeable NullsOrder
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> NullsOrder -> c NullsOrder)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NullsOrder)
-> (NullsOrder -> Constr)
-> (NullsOrder -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NullsOrder))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c NullsOrder))
-> ((forall b. Data b => b -> b) -> NullsOrder -> NullsOrder)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NullsOrder -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NullsOrder -> r)
-> (forall u. (forall d. Data d => d -> u) -> NullsOrder -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> NullsOrder -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder)
-> Data NullsOrder
NullsOrder -> Constr
NullsOrder -> DataType
(forall b. Data b => b -> b) -> NullsOrder -> NullsOrder
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NullsOrder -> u
forall u. (forall d. Data d => d -> u) -> NullsOrder -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NullsOrder -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NullsOrder -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NullsOrder
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NullsOrder -> c NullsOrder
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NullsOrder)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NullsOrder)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NullsOrder -> c NullsOrder
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NullsOrder -> c NullsOrder
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NullsOrder
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NullsOrder
$ctoConstr :: NullsOrder -> Constr
toConstr :: NullsOrder -> Constr
$cdataTypeOf :: NullsOrder -> DataType
dataTypeOf :: NullsOrder -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NullsOrder)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NullsOrder)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NullsOrder)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NullsOrder)
$cgmapT :: (forall b. Data b => b -> b) -> NullsOrder -> NullsOrder
gmapT :: (forall b. Data b => b -> b) -> NullsOrder -> NullsOrder
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NullsOrder -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NullsOrder -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NullsOrder -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NullsOrder -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NullsOrder -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> NullsOrder -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NullsOrder -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NullsOrder -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NullsOrder -> m NullsOrder
Data)

instance NFData NullsOrder

instance Hashable NullsOrder

instance ToSQL NullsOrder where
  toSQL :: NullsOrder -> Builder
toSQL NullsOrder
NullsFirst = Builder
"NULLS FIRST"
  toSQL NullsOrder
NullsLast = Builder
"NULLS LAST"

instance J.FromJSON NullsOrder where
  -- Todo: write a proper parser https://github.com/hasura/graphql-engine-mono/issues/5484
  parseJSON :: Value -> Parser NullsOrder
parseJSON = Options -> Value -> Parser NullsOrder
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
J.genericParseJSON (Options -> Value -> Parser NullsOrder)
-> Options -> Value -> Parser NullsOrder
forall a b. (a -> b) -> a -> b
$ Options
J.defaultOptions {constructorTagModifier :: ShowS
J.constructorTagModifier = ShowS
J.snakeCase ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
5}

instance J.ToJSON NullsOrder where
  -- Todo: write a proper parser https://github.com/hasura/graphql-engine-mono/issues/5484
  toJSON :: NullsOrder -> Value
toJSON = Options -> NullsOrder -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
J.genericToJSON (Options -> NullsOrder -> Value) -> Options -> NullsOrder -> Value
forall a b. (a -> b) -> a -> b
$ Options
J.defaultOptions {constructorTagModifier :: ShowS
J.constructorTagModifier = ShowS
J.snakeCase ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
5}

instance ToSQL OrderByExp where
  toSQL :: OrderByExp -> Builder
toSQL (OrderByExp NonEmpty OrderByItem
l) =
    Builder
"ORDER BY" Builder -> Builder -> Builder
<~> (Text
", " Text -> [OrderByItem] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> NonEmpty OrderByItem -> [OrderByItem]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty OrderByItem
l)

newtype GroupByExp
  = GroupByExp [SQLExp]
  deriving (Int -> GroupByExp -> ShowS
[GroupByExp] -> ShowS
GroupByExp -> String
(Int -> GroupByExp -> ShowS)
-> (GroupByExp -> String)
-> ([GroupByExp] -> ShowS)
-> Show GroupByExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GroupByExp -> ShowS
showsPrec :: Int -> GroupByExp -> ShowS
$cshow :: GroupByExp -> String
show :: GroupByExp -> String
$cshowList :: [GroupByExp] -> ShowS
showList :: [GroupByExp] -> ShowS
Show, GroupByExp -> GroupByExp -> Bool
(GroupByExp -> GroupByExp -> Bool)
-> (GroupByExp -> GroupByExp -> Bool) -> Eq GroupByExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GroupByExp -> GroupByExp -> Bool
== :: GroupByExp -> GroupByExp -> Bool
$c/= :: GroupByExp -> GroupByExp -> Bool
/= :: GroupByExp -> GroupByExp -> Bool
Eq, GroupByExp -> ()
(GroupByExp -> ()) -> NFData GroupByExp
forall a. (a -> ()) -> NFData a
$crnf :: GroupByExp -> ()
rnf :: GroupByExp -> ()
NFData, Typeable GroupByExp
Typeable GroupByExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> GroupByExp -> c GroupByExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c GroupByExp)
-> (GroupByExp -> Constr)
-> (GroupByExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c GroupByExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c GroupByExp))
-> ((forall b. Data b => b -> b) -> GroupByExp -> GroupByExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> GroupByExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> GroupByExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> GroupByExp -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> GroupByExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp)
-> Data GroupByExp
GroupByExp -> Constr
GroupByExp -> DataType
(forall b. Data b => b -> b) -> GroupByExp -> GroupByExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> GroupByExp -> u
forall u. (forall d. Data d => d -> u) -> GroupByExp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> GroupByExp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> GroupByExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c GroupByExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GroupByExp -> c GroupByExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c GroupByExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GroupByExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GroupByExp -> c GroupByExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GroupByExp -> c GroupByExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c GroupByExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c GroupByExp
$ctoConstr :: GroupByExp -> Constr
toConstr :: GroupByExp -> Constr
$cdataTypeOf :: GroupByExp -> DataType
dataTypeOf :: GroupByExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c GroupByExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c GroupByExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GroupByExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GroupByExp)
$cgmapT :: (forall b. Data b => b -> b) -> GroupByExp -> GroupByExp
gmapT :: (forall b. Data b => b -> b) -> GroupByExp -> GroupByExp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> GroupByExp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> GroupByExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> GroupByExp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> GroupByExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> GroupByExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> GroupByExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> GroupByExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> GroupByExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GroupByExp -> m GroupByExp
Data, Eq GroupByExp
Eq GroupByExp
-> (Int -> GroupByExp -> Int)
-> (GroupByExp -> Int)
-> Hashable GroupByExp
Int -> GroupByExp -> Int
GroupByExp -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> GroupByExp -> Int
hashWithSalt :: Int -> GroupByExp -> Int
$chash :: GroupByExp -> Int
hash :: GroupByExp -> Int
Hashable)

instance ToSQL GroupByExp where
  toSQL :: GroupByExp -> Builder
toSQL (GroupByExp [SQLExp]
idens) =
    Builder
"GROUP BY" Builder -> Builder -> Builder
<~> (Text
", " Text -> [SQLExp] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [SQLExp]
idens)

newtype FromExp
  = FromExp [FromItem]
  deriving (Int -> FromExp -> ShowS
[FromExp] -> ShowS
FromExp -> String
(Int -> FromExp -> ShowS)
-> (FromExp -> String) -> ([FromExp] -> ShowS) -> Show FromExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FromExp -> ShowS
showsPrec :: Int -> FromExp -> ShowS
$cshow :: FromExp -> String
show :: FromExp -> String
$cshowList :: [FromExp] -> ShowS
showList :: [FromExp] -> ShowS
Show, FromExp -> FromExp -> Bool
(FromExp -> FromExp -> Bool)
-> (FromExp -> FromExp -> Bool) -> Eq FromExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FromExp -> FromExp -> Bool
== :: FromExp -> FromExp -> Bool
$c/= :: FromExp -> FromExp -> Bool
/= :: FromExp -> FromExp -> Bool
Eq, FromExp -> ()
(FromExp -> ()) -> NFData FromExp
forall a. (a -> ()) -> NFData a
$crnf :: FromExp -> ()
rnf :: FromExp -> ()
NFData, Typeable FromExp
Typeable FromExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> FromExp -> c FromExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c FromExp)
-> (FromExp -> Constr)
-> (FromExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c FromExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FromExp))
-> ((forall b. Data b => b -> b) -> FromExp -> FromExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> FromExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> FromExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> FromExp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> FromExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> FromExp -> m FromExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FromExp -> m FromExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FromExp -> m FromExp)
-> Data FromExp
FromExp -> Constr
FromExp -> DataType
(forall b. Data b => b -> b) -> FromExp -> FromExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FromExp -> u
forall u. (forall d. Data d => d -> u) -> FromExp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FromExp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FromExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FromExp -> m FromExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FromExp -> m FromExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FromExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromExp -> c FromExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FromExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FromExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromExp -> c FromExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromExp -> c FromExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FromExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FromExp
$ctoConstr :: FromExp -> Constr
toConstr :: FromExp -> Constr
$cdataTypeOf :: FromExp -> DataType
dataTypeOf :: FromExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FromExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FromExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FromExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FromExp)
$cgmapT :: (forall b. Data b => b -> b) -> FromExp -> FromExp
gmapT :: (forall b. Data b => b -> b) -> FromExp -> FromExp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FromExp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FromExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FromExp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FromExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FromExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> FromExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FromExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FromExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FromExp -> m FromExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FromExp -> m FromExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FromExp -> m FromExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FromExp -> m FromExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FromExp -> m FromExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FromExp -> m FromExp
Data, Eq FromExp
Eq FromExp
-> (Int -> FromExp -> Int) -> (FromExp -> Int) -> Hashable FromExp
Int -> FromExp -> Int
FromExp -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> FromExp -> Int
hashWithSalt :: Int -> FromExp -> Int
$chash :: FromExp -> Int
hash :: FromExp -> Int
Hashable)

instance ToSQL FromExp where
  toSQL :: FromExp -> Builder
toSQL (FromExp [FromItem]
items) =
    Builder
"FROM" Builder -> Builder -> Builder
<~> (Text
", " Text -> [FromItem] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [FromItem]
items)

mkIdenFromExp :: TableIdentifier -> FromExp
mkIdenFromExp :: TableIdentifier -> FromExp
mkIdenFromExp TableIdentifier
ident =
  [FromItem] -> FromExp
FromExp [TableIdentifier -> FromItem
FIIdentifier TableIdentifier
ident]

mkSimpleFromExp :: QualifiedTable -> FromExp
mkSimpleFromExp :: QualifiedTable -> FromExp
mkSimpleFromExp QualifiedTable
qt =
  [FromItem] -> FromExp
FromExp [QualifiedTable -> Maybe TableAlias -> FromItem
FISimple QualifiedTable
qt Maybe TableAlias
forall a. Maybe a
Nothing]

mkSelFromExp :: Bool -> Select -> TableName -> FromItem
mkSelFromExp :: Bool -> Select -> TableName -> FromItem
mkSelFromExp Bool
isLateral Select
sel TableName
tn =
  Lateral -> Select -> TableAlias -> FromItem
FISelect (Bool -> Lateral
Lateral Bool
isLateral) Select
sel TableAlias
alias
  where
    alias :: TableAlias
alias = Identifier -> TableAlias
forall a. IsIdentifier a => a -> TableAlias
toTableAlias (Identifier -> TableAlias) -> Identifier -> TableAlias
forall a b. (a -> b) -> a -> b
$ TableName -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier TableName
tn

mkRowExp :: [Extractor] -> SQLExp
mkRowExp :: [Extractor] -> SQLExp
mkRowExp [Extractor]
extrs =
  let innerSel :: Select
innerSel = Select
mkSelect {selExtr :: [Extractor]
selExtr = [Extractor]
extrs}

      innerSelName :: TableName
innerSelName = Text -> TableName
TableName Text
"e"

      -- SELECT r FROM (SELECT col1, col2, .. ) AS r
      outerSel :: Select
outerSel =
        Select
mkSelect
          { selExtr :: [Extractor]
selExtr = [SQLExp -> Maybe ColumnAlias -> Extractor
Extractor (Identifier -> SQLExp
SERowIdentifier (Identifier -> SQLExp) -> Identifier -> SQLExp
forall a b. (a -> b) -> a -> b
$ TableName -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier TableName
innerSelName) Maybe ColumnAlias
forall a. Maybe a
Nothing],
            selFrom :: Maybe FromExp
selFrom =
              FromExp -> Maybe FromExp
forall a. a -> Maybe a
Just
                (FromExp -> Maybe FromExp) -> FromExp -> Maybe FromExp
forall a b. (a -> b) -> a -> b
$ [FromItem] -> FromExp
FromExp
                  [Bool -> Select -> TableName -> FromItem
mkSelFromExp Bool
False Select
innerSel TableName
innerSelName]
          }
   in Select -> SQLExp
SESelect Select
outerSel

newtype HavingExp
  = HavingExp BoolExp
  deriving (Int -> HavingExp -> ShowS
[HavingExp] -> ShowS
HavingExp -> String
(Int -> HavingExp -> ShowS)
-> (HavingExp -> String)
-> ([HavingExp] -> ShowS)
-> Show HavingExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HavingExp -> ShowS
showsPrec :: Int -> HavingExp -> ShowS
$cshow :: HavingExp -> String
show :: HavingExp -> String
$cshowList :: [HavingExp] -> ShowS
showList :: [HavingExp] -> ShowS
Show, HavingExp -> HavingExp -> Bool
(HavingExp -> HavingExp -> Bool)
-> (HavingExp -> HavingExp -> Bool) -> Eq HavingExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HavingExp -> HavingExp -> Bool
== :: HavingExp -> HavingExp -> Bool
$c/= :: HavingExp -> HavingExp -> Bool
/= :: HavingExp -> HavingExp -> Bool
Eq, HavingExp -> ()
(HavingExp -> ()) -> NFData HavingExp
forall a. (a -> ()) -> NFData a
$crnf :: HavingExp -> ()
rnf :: HavingExp -> ()
NFData, Typeable HavingExp
Typeable HavingExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> HavingExp -> c HavingExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c HavingExp)
-> (HavingExp -> Constr)
-> (HavingExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c HavingExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HavingExp))
-> ((forall b. Data b => b -> b) -> HavingExp -> HavingExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> HavingExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> HavingExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> HavingExp -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> HavingExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> HavingExp -> m HavingExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> HavingExp -> m HavingExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> HavingExp -> m HavingExp)
-> Data HavingExp
HavingExp -> Constr
HavingExp -> DataType
(forall b. Data b => b -> b) -> HavingExp -> HavingExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> HavingExp -> u
forall u. (forall d. Data d => d -> u) -> HavingExp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HavingExp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HavingExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HavingExp -> m HavingExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HavingExp -> m HavingExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HavingExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HavingExp -> c HavingExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HavingExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HavingExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HavingExp -> c HavingExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HavingExp -> c HavingExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HavingExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HavingExp
$ctoConstr :: HavingExp -> Constr
toConstr :: HavingExp -> Constr
$cdataTypeOf :: HavingExp -> DataType
dataTypeOf :: HavingExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HavingExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HavingExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HavingExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HavingExp)
$cgmapT :: (forall b. Data b => b -> b) -> HavingExp -> HavingExp
gmapT :: (forall b. Data b => b -> b) -> HavingExp -> HavingExp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HavingExp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HavingExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HavingExp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HavingExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> HavingExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> HavingExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HavingExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HavingExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HavingExp -> m HavingExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HavingExp -> m HavingExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HavingExp -> m HavingExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HavingExp -> m HavingExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HavingExp -> m HavingExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HavingExp -> m HavingExp
Data, Eq HavingExp
Eq HavingExp
-> (Int -> HavingExp -> Int)
-> (HavingExp -> Int)
-> Hashable HavingExp
Int -> HavingExp -> Int
HavingExp -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> HavingExp -> Int
hashWithSalt :: Int -> HavingExp -> Int
$chash :: HavingExp -> Int
hash :: HavingExp -> Int
Hashable)

instance ToSQL HavingExp where
  toSQL :: HavingExp -> Builder
toSQL (HavingExp BoolExp
be) =
    Builder
"HAVING" Builder -> Builder -> Builder
<~> BoolExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL BoolExp
be

newtype WhereFrag = WhereFrag {WhereFrag -> BoolExp
getWFBoolExp :: BoolExp}
  deriving (Int -> WhereFrag -> ShowS
[WhereFrag] -> ShowS
WhereFrag -> String
(Int -> WhereFrag -> ShowS)
-> (WhereFrag -> String)
-> ([WhereFrag] -> ShowS)
-> Show WhereFrag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WhereFrag -> ShowS
showsPrec :: Int -> WhereFrag -> ShowS
$cshow :: WhereFrag -> String
show :: WhereFrag -> String
$cshowList :: [WhereFrag] -> ShowS
showList :: [WhereFrag] -> ShowS
Show, WhereFrag -> WhereFrag -> Bool
(WhereFrag -> WhereFrag -> Bool)
-> (WhereFrag -> WhereFrag -> Bool) -> Eq WhereFrag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WhereFrag -> WhereFrag -> Bool
== :: WhereFrag -> WhereFrag -> Bool
$c/= :: WhereFrag -> WhereFrag -> Bool
/= :: WhereFrag -> WhereFrag -> Bool
Eq, WhereFrag -> ()
(WhereFrag -> ()) -> NFData WhereFrag
forall a. (a -> ()) -> NFData a
$crnf :: WhereFrag -> ()
rnf :: WhereFrag -> ()
NFData, Typeable WhereFrag
Typeable WhereFrag
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> WhereFrag -> c WhereFrag)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c WhereFrag)
-> (WhereFrag -> Constr)
-> (WhereFrag -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c WhereFrag))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c WhereFrag))
-> ((forall b. Data b => b -> b) -> WhereFrag -> WhereFrag)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> WhereFrag -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> WhereFrag -> r)
-> (forall u. (forall d. Data d => d -> u) -> WhereFrag -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> WhereFrag -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag)
-> Data WhereFrag
WhereFrag -> Constr
WhereFrag -> DataType
(forall b. Data b => b -> b) -> WhereFrag -> WhereFrag
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> WhereFrag -> u
forall u. (forall d. Data d => d -> u) -> WhereFrag -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> WhereFrag -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> WhereFrag -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c WhereFrag
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> WhereFrag -> c WhereFrag
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c WhereFrag)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c WhereFrag)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> WhereFrag -> c WhereFrag
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> WhereFrag -> c WhereFrag
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c WhereFrag
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c WhereFrag
$ctoConstr :: WhereFrag -> Constr
toConstr :: WhereFrag -> Constr
$cdataTypeOf :: WhereFrag -> DataType
dataTypeOf :: WhereFrag -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c WhereFrag)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c WhereFrag)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c WhereFrag)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c WhereFrag)
$cgmapT :: (forall b. Data b => b -> b) -> WhereFrag -> WhereFrag
gmapT :: (forall b. Data b => b -> b) -> WhereFrag -> WhereFrag
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> WhereFrag -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> WhereFrag -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> WhereFrag -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> WhereFrag -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> WhereFrag -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> WhereFrag -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> WhereFrag -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> WhereFrag -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> WhereFrag -> m WhereFrag
Data, Eq WhereFrag
Eq WhereFrag
-> (Int -> WhereFrag -> Int)
-> (WhereFrag -> Int)
-> Hashable WhereFrag
Int -> WhereFrag -> Int
WhereFrag -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> WhereFrag -> Int
hashWithSalt :: Int -> WhereFrag -> Int
$chash :: WhereFrag -> Int
hash :: WhereFrag -> Int
Hashable)

instance ToSQL WhereFrag where
  toSQL :: WhereFrag -> Builder
toSQL (WhereFrag BoolExp
be) =
    Builder
"WHERE" Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (BoolExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL BoolExp
be)

instance ToSQL Select where
  toSQL :: Select -> Builder
toSQL Select
sel = case Select -> [(TableAlias, InnerCTE)]
selCTEs Select
sel of
    [] ->
      Builder
"SELECT"
        Builder -> Builder -> Builder
<~> Maybe DistinctExpr -> Builder
forall a. ToSQL a => a -> Builder
toSQL (Select -> Maybe DistinctExpr
selDistinct Select
sel)
        Builder -> Builder -> Builder
<~> (Text
", " Text -> [Extractor] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> Select -> [Extractor]
selExtr Select
sel)
        Builder -> Builder -> Builder
<~> Maybe FromExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (Select -> Maybe FromExp
selFrom Select
sel)
        Builder -> Builder -> Builder
<~> Maybe WhereFrag -> Builder
forall a. ToSQL a => a -> Builder
toSQL (Select -> Maybe WhereFrag
selWhere Select
sel)
        Builder -> Builder -> Builder
<~> Maybe GroupByExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (Select -> Maybe GroupByExp
selGroupBy Select
sel)
        Builder -> Builder -> Builder
<~> Maybe HavingExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (Select -> Maybe HavingExp
selHaving Select
sel)
        Builder -> Builder -> Builder
<~> Maybe OrderByExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (Select -> Maybe OrderByExp
selOrderBy Select
sel)
        Builder -> Builder -> Builder
<~> Maybe LimitExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (Select -> Maybe LimitExp
selLimit Select
sel)
        Builder -> Builder -> Builder
<~> Maybe OffsetExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (Select -> Maybe OffsetExp
selOffset Select
sel)
    -- reuse SelectWith if there are any CTEs, since the generated SQL is the same
    [(TableAlias, InnerCTE)]
ctes -> SelectWithG TopLevelCTE -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SelectWithG TopLevelCTE -> Builder)
-> SelectWithG TopLevelCTE -> Builder
forall a b. (a -> b) -> a -> b
$ [(TableAlias, TopLevelCTE)] -> Select -> SelectWithG TopLevelCTE
forall statement.
[(TableAlias, statement)] -> Select -> SelectWithG statement
SelectWith (((TableAlias, InnerCTE) -> (TableAlias, TopLevelCTE))
-> [(TableAlias, InnerCTE)] -> [(TableAlias, TopLevelCTE)]
forall a b. (a -> b) -> [a] -> [b]
map (InnerCTE -> TopLevelCTE
toTopLevelCTE (InnerCTE -> TopLevelCTE)
-> (TableAlias, InnerCTE) -> (TableAlias, TopLevelCTE)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) [(TableAlias, InnerCTE)]
ctes) Select
sel {selCTEs :: [(TableAlias, InnerCTE)]
selCTEs = []}

mkSIdenExp :: (IsIdentifier a) => a -> SQLExp
mkSIdenExp :: forall a. IsIdentifier a => a -> SQLExp
mkSIdenExp = Identifier -> SQLExp
SEIdentifier (Identifier -> SQLExp) -> (a -> Identifier) -> a -> SQLExp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier

mkQIdenExp :: (IsIdentifier b) => TableIdentifier -> b -> SQLExp
mkQIdenExp :: forall b. IsIdentifier b => TableIdentifier -> b -> SQLExp
mkQIdenExp TableIdentifier
q b
t = QIdentifier -> SQLExp
SEQIdentifier (QIdentifier -> SQLExp) -> QIdentifier -> SQLExp
forall a b. (a -> b) -> a -> b
$ TableIdentifier -> b -> QIdentifier
forall b. IsIdentifier b => TableIdentifier -> b -> QIdentifier
mkQIdentifier TableIdentifier
q b
t

data Qual
  = QualifiedIdentifier TableIdentifier (Maybe TypeAnn)
  | QualTable QualifiedTable
  | QualVar Text
  deriving (Int -> Qual -> ShowS
[Qual] -> ShowS
Qual -> String
(Int -> Qual -> ShowS)
-> (Qual -> String) -> ([Qual] -> ShowS) -> Show Qual
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Qual -> ShowS
showsPrec :: Int -> Qual -> ShowS
$cshow :: Qual -> String
show :: Qual -> String
$cshowList :: [Qual] -> ShowS
showList :: [Qual] -> ShowS
Show, Qual -> Qual -> Bool
(Qual -> Qual -> Bool) -> (Qual -> Qual -> Bool) -> Eq Qual
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Qual -> Qual -> Bool
== :: Qual -> Qual -> Bool
$c/= :: Qual -> Qual -> Bool
/= :: Qual -> Qual -> Bool
Eq, (forall x. Qual -> Rep Qual x)
-> (forall x. Rep Qual x -> Qual) -> Generic Qual
forall x. Rep Qual x -> Qual
forall x. Qual -> Rep Qual x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Qual -> Rep Qual x
from :: forall x. Qual -> Rep Qual x
$cto :: forall x. Rep Qual x -> Qual
to :: forall x. Rep Qual x -> Qual
Generic, Typeable Qual
Typeable Qual
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Qual -> c Qual)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Qual)
-> (Qual -> Constr)
-> (Qual -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Qual))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Qual))
-> ((forall b. Data b => b -> b) -> Qual -> Qual)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Qual -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Qual -> r)
-> (forall u. (forall d. Data d => d -> u) -> Qual -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Qual -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Qual -> m Qual)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Qual -> m Qual)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Qual -> m Qual)
-> Data Qual
Qual -> Constr
Qual -> DataType
(forall b. Data b => b -> b) -> Qual -> Qual
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Qual -> u
forall u. (forall d. Data d => d -> u) -> Qual -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Qual -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Qual -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Qual -> m Qual
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Qual -> m Qual
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Qual
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Qual -> c Qual
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Qual)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Qual)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Qual -> c Qual
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Qual -> c Qual
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Qual
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Qual
$ctoConstr :: Qual -> Constr
toConstr :: Qual -> Constr
$cdataTypeOf :: Qual -> DataType
dataTypeOf :: Qual -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Qual)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Qual)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Qual)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Qual)
$cgmapT :: (forall b. Data b => b -> b) -> Qual -> Qual
gmapT :: (forall b. Data b => b -> b) -> Qual -> Qual
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Qual -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Qual -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Qual -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Qual -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Qual -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Qual -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Qual -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Qual -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Qual -> m Qual
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Qual -> m Qual
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Qual -> m Qual
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Qual -> m Qual
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Qual -> m Qual
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Qual -> m Qual
Data)

instance NFData Qual

instance Hashable Qual

mkQual :: QualifiedTable -> Qual
mkQual :: QualifiedTable -> Qual
mkQual = QualifiedTable -> Qual
QualTable

instance ToSQL Qual where
  toSQL :: Qual -> Builder
toSQL (QualifiedIdentifier TableIdentifier
i Maybe TypeAnn
Nothing) = TableIdentifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL TableIdentifier
i
  toSQL (QualifiedIdentifier TableIdentifier
i (Just TypeAnn
ty)) = Builder -> Builder
parenB (TableIdentifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL TableIdentifier
i Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> TypeAnn -> Builder
forall a. ToSQL a => a -> Builder
toSQL TypeAnn
ty)
  toSQL (QualTable QualifiedTable
qt) = QualifiedTable -> Builder
forall a. ToSQL a => a -> Builder
toSQL QualifiedTable
qt
  toSQL (QualVar Text
v) = Text -> Builder
TB.text Text
v

mkQIdentifier :: (IsIdentifier b) => TableIdentifier -> b -> QIdentifier
mkQIdentifier :: forall b. IsIdentifier b => TableIdentifier -> b -> QIdentifier
mkQIdentifier TableIdentifier
q b
t = Qual -> Identifier -> QIdentifier
QIdentifier (TableIdentifier -> Maybe TypeAnn -> Qual
QualifiedIdentifier TableIdentifier
q Maybe TypeAnn
forall a. Maybe a
Nothing) (b -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier b
t)

mkQIdentifierTable :: (IsIdentifier a) => QualifiedTable -> a -> QIdentifier
mkQIdentifierTable :: forall a. IsIdentifier a => QualifiedTable -> a -> QIdentifier
mkQIdentifierTable QualifiedTable
q = Qual -> Identifier -> QIdentifier
QIdentifier (QualifiedTable -> Qual
mkQual QualifiedTable
q) (Identifier -> QIdentifier)
-> (a -> Identifier) -> a -> QIdentifier
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier

mkIdentifierSQLExp :: forall a. (IsIdentifier a) => Qual -> a -> SQLExp
mkIdentifierSQLExp :: forall a. IsIdentifier a => Qual -> a -> SQLExp
mkIdentifierSQLExp Qual
q = QIdentifier -> SQLExp
SEQIdentifier (QIdentifier -> SQLExp) -> (a -> QIdentifier) -> a -> SQLExp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Qual -> Identifier -> QIdentifier
QIdentifier Qual
q (Identifier -> QIdentifier)
-> (a -> Identifier) -> a -> QIdentifier
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier

data QIdentifier
  = QIdentifier Qual Identifier
  deriving (Int -> QIdentifier -> ShowS
[QIdentifier] -> ShowS
QIdentifier -> String
(Int -> QIdentifier -> ShowS)
-> (QIdentifier -> String)
-> ([QIdentifier] -> ShowS)
-> Show QIdentifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> QIdentifier -> ShowS
showsPrec :: Int -> QIdentifier -> ShowS
$cshow :: QIdentifier -> String
show :: QIdentifier -> String
$cshowList :: [QIdentifier] -> ShowS
showList :: [QIdentifier] -> ShowS
Show, QIdentifier -> QIdentifier -> Bool
(QIdentifier -> QIdentifier -> Bool)
-> (QIdentifier -> QIdentifier -> Bool) -> Eq QIdentifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: QIdentifier -> QIdentifier -> Bool
== :: QIdentifier -> QIdentifier -> Bool
$c/= :: QIdentifier -> QIdentifier -> Bool
/= :: QIdentifier -> QIdentifier -> Bool
Eq, (forall x. QIdentifier -> Rep QIdentifier x)
-> (forall x. Rep QIdentifier x -> QIdentifier)
-> Generic QIdentifier
forall x. Rep QIdentifier x -> QIdentifier
forall x. QIdentifier -> Rep QIdentifier x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. QIdentifier -> Rep QIdentifier x
from :: forall x. QIdentifier -> Rep QIdentifier x
$cto :: forall x. Rep QIdentifier x -> QIdentifier
to :: forall x. Rep QIdentifier x -> QIdentifier
Generic, Typeable QIdentifier
Typeable QIdentifier
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> QIdentifier -> c QIdentifier)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c QIdentifier)
-> (QIdentifier -> Constr)
-> (QIdentifier -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c QIdentifier))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c QIdentifier))
-> ((forall b. Data b => b -> b) -> QIdentifier -> QIdentifier)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> QIdentifier -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> QIdentifier -> r)
-> (forall u. (forall d. Data d => d -> u) -> QIdentifier -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> QIdentifier -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier)
-> Data QIdentifier
QIdentifier -> Constr
QIdentifier -> DataType
(forall b. Data b => b -> b) -> QIdentifier -> QIdentifier
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> QIdentifier -> u
forall u. (forall d. Data d => d -> u) -> QIdentifier -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> QIdentifier -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> QIdentifier -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c QIdentifier
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> QIdentifier -> c QIdentifier
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c QIdentifier)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c QIdentifier)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> QIdentifier -> c QIdentifier
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> QIdentifier -> c QIdentifier
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c QIdentifier
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c QIdentifier
$ctoConstr :: QIdentifier -> Constr
toConstr :: QIdentifier -> Constr
$cdataTypeOf :: QIdentifier -> DataType
dataTypeOf :: QIdentifier -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c QIdentifier)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c QIdentifier)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c QIdentifier)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c QIdentifier)
$cgmapT :: (forall b. Data b => b -> b) -> QIdentifier -> QIdentifier
gmapT :: (forall b. Data b => b -> b) -> QIdentifier -> QIdentifier
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> QIdentifier -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> QIdentifier -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> QIdentifier -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> QIdentifier -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> QIdentifier -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> QIdentifier -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> QIdentifier -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> QIdentifier -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QIdentifier -> m QIdentifier
Data)

instance NFData QIdentifier

instance Hashable QIdentifier

instance ToSQL QIdentifier where
  toSQL :: QIdentifier -> Builder
toSQL (QIdentifier Qual
qual Identifier
iden) =
    [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat [Qual -> Builder
forall a. ToSQL a => a -> Builder
toSQL Qual
qual, Char -> Builder
TB.char Char
'.', Identifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL Identifier
iden]

data ColumnOp = ColumnOp
  { ColumnOp -> SQLOp
_colOp :: SQLOp,
    ColumnOp -> SQLExp
_colExp :: SQLExp
  }
  deriving (Int -> ColumnOp -> ShowS
[ColumnOp] -> ShowS
ColumnOp -> String
(Int -> ColumnOp -> ShowS)
-> (ColumnOp -> String) -> ([ColumnOp] -> ShowS) -> Show ColumnOp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ColumnOp -> ShowS
showsPrec :: Int -> ColumnOp -> ShowS
$cshow :: ColumnOp -> String
show :: ColumnOp -> String
$cshowList :: [ColumnOp] -> ShowS
showList :: [ColumnOp] -> ShowS
Show, ColumnOp -> ColumnOp -> Bool
(ColumnOp -> ColumnOp -> Bool)
-> (ColumnOp -> ColumnOp -> Bool) -> Eq ColumnOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ColumnOp -> ColumnOp -> Bool
== :: ColumnOp -> ColumnOp -> Bool
$c/= :: ColumnOp -> ColumnOp -> Bool
/= :: ColumnOp -> ColumnOp -> Bool
Eq, (forall x. ColumnOp -> Rep ColumnOp x)
-> (forall x. Rep ColumnOp x -> ColumnOp) -> Generic ColumnOp
forall x. Rep ColumnOp x -> ColumnOp
forall x. ColumnOp -> Rep ColumnOp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ColumnOp -> Rep ColumnOp x
from :: forall x. ColumnOp -> Rep ColumnOp x
$cto :: forall x. Rep ColumnOp x -> ColumnOp
to :: forall x. Rep ColumnOp x -> ColumnOp
Generic, Typeable ColumnOp
Typeable ColumnOp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ColumnOp -> c ColumnOp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ColumnOp)
-> (ColumnOp -> Constr)
-> (ColumnOp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ColumnOp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ColumnOp))
-> ((forall b. Data b => b -> b) -> ColumnOp -> ColumnOp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ColumnOp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ColumnOp -> r)
-> (forall u. (forall d. Data d => d -> u) -> ColumnOp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> ColumnOp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp)
-> Data ColumnOp
ColumnOp -> Constr
ColumnOp -> DataType
(forall b. Data b => b -> b) -> ColumnOp -> ColumnOp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ColumnOp -> u
forall u. (forall d. Data d => d -> u) -> ColumnOp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnOp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnOp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ColumnOp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ColumnOp -> c ColumnOp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ColumnOp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ColumnOp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ColumnOp -> c ColumnOp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ColumnOp -> c ColumnOp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ColumnOp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ColumnOp
$ctoConstr :: ColumnOp -> Constr
toConstr :: ColumnOp -> Constr
$cdataTypeOf :: ColumnOp -> DataType
dataTypeOf :: ColumnOp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ColumnOp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ColumnOp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ColumnOp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ColumnOp)
$cgmapT :: (forall b. Data b => b -> b) -> ColumnOp -> ColumnOp
gmapT :: (forall b. Data b => b -> b) -> ColumnOp -> ColumnOp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnOp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnOp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnOp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnOp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ColumnOp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> ColumnOp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ColumnOp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ColumnOp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ColumnOp -> m ColumnOp
Data)

instance NFData ColumnOp

instance Hashable ColumnOp

newtype SQLOp = SQLOp {SQLOp -> Text
sqlOpTxt :: Text}
  deriving (Int -> SQLOp -> ShowS
[SQLOp] -> ShowS
SQLOp -> String
(Int -> SQLOp -> ShowS)
-> (SQLOp -> String) -> ([SQLOp] -> ShowS) -> Show SQLOp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SQLOp -> ShowS
showsPrec :: Int -> SQLOp -> ShowS
$cshow :: SQLOp -> String
show :: SQLOp -> String
$cshowList :: [SQLOp] -> ShowS
showList :: [SQLOp] -> ShowS
Show, SQLOp -> SQLOp -> Bool
(SQLOp -> SQLOp -> Bool) -> (SQLOp -> SQLOp -> Bool) -> Eq SQLOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SQLOp -> SQLOp -> Bool
== :: SQLOp -> SQLOp -> Bool
$c/= :: SQLOp -> SQLOp -> Bool
/= :: SQLOp -> SQLOp -> Bool
Eq, SQLOp -> ()
(SQLOp -> ()) -> NFData SQLOp
forall a. (a -> ()) -> NFData a
$crnf :: SQLOp -> ()
rnf :: SQLOp -> ()
NFData, Typeable SQLOp
Typeable SQLOp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> SQLOp -> c SQLOp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c SQLOp)
-> (SQLOp -> Constr)
-> (SQLOp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c SQLOp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SQLOp))
-> ((forall b. Data b => b -> b) -> SQLOp -> SQLOp)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SQLOp -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SQLOp -> r)
-> (forall u. (forall d. Data d => d -> u) -> SQLOp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> SQLOp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> SQLOp -> m SQLOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SQLOp -> m SQLOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SQLOp -> m SQLOp)
-> Data SQLOp
SQLOp -> Constr
SQLOp -> DataType
(forall b. Data b => b -> b) -> SQLOp -> SQLOp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> SQLOp -> u
forall u. (forall d. Data d => d -> u) -> SQLOp -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SQLOp -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SQLOp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SQLOp -> m SQLOp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SQLOp -> m SQLOp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SQLOp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SQLOp -> c SQLOp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SQLOp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SQLOp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SQLOp -> c SQLOp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SQLOp -> c SQLOp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SQLOp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SQLOp
$ctoConstr :: SQLOp -> Constr
toConstr :: SQLOp -> Constr
$cdataTypeOf :: SQLOp -> DataType
dataTypeOf :: SQLOp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SQLOp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SQLOp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SQLOp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SQLOp)
$cgmapT :: (forall b. Data b => b -> b) -> SQLOp -> SQLOp
gmapT :: (forall b. Data b => b -> b) -> SQLOp -> SQLOp
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SQLOp -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SQLOp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SQLOp -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SQLOp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> SQLOp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> SQLOp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SQLOp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SQLOp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SQLOp -> m SQLOp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SQLOp -> m SQLOp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SQLOp -> m SQLOp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SQLOp -> m SQLOp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SQLOp -> m SQLOp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SQLOp -> m SQLOp
Data, Eq SQLOp
Eq SQLOp
-> (Int -> SQLOp -> Int) -> (SQLOp -> Int) -> Hashable SQLOp
Int -> SQLOp -> Int
SQLOp -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> SQLOp -> Int
hashWithSalt :: Int -> SQLOp -> Int
$chash :: SQLOp -> Int
hash :: SQLOp -> Int
Hashable)

incOp :: SQLOp
incOp :: SQLOp
incOp = Text -> SQLOp
SQLOp Text
"+"

mulOp :: SQLOp
mulOp :: SQLOp
mulOp = Text -> SQLOp
SQLOp Text
"*"

jsonbPathOp :: SQLOp
jsonbPathOp :: SQLOp
jsonbPathOp = Text -> SQLOp
SQLOp Text
"#>"

jsonbConcatOp :: SQLOp
jsonbConcatOp :: SQLOp
jsonbConcatOp = Text -> SQLOp
SQLOp Text
"||"

jsonbDeleteOp :: SQLOp
jsonbDeleteOp :: SQLOp
jsonbDeleteOp = Text -> SQLOp
SQLOp Text
"-"

jsonbDeleteAtPathOp :: SQLOp
jsonbDeleteAtPathOp :: SQLOp
jsonbDeleteAtPathOp = Text -> SQLOp
SQLOp Text
"#-"

newtype TypeAnn = TypeAnn {TypeAnn -> Text
unTypeAnn :: Text}
  deriving (Int -> TypeAnn -> ShowS
[TypeAnn] -> ShowS
TypeAnn -> String
(Int -> TypeAnn -> ShowS)
-> (TypeAnn -> String) -> ([TypeAnn] -> ShowS) -> Show TypeAnn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TypeAnn -> ShowS
showsPrec :: Int -> TypeAnn -> ShowS
$cshow :: TypeAnn -> String
show :: TypeAnn -> String
$cshowList :: [TypeAnn] -> ShowS
showList :: [TypeAnn] -> ShowS
Show, TypeAnn -> TypeAnn -> Bool
(TypeAnn -> TypeAnn -> Bool)
-> (TypeAnn -> TypeAnn -> Bool) -> Eq TypeAnn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TypeAnn -> TypeAnn -> Bool
== :: TypeAnn -> TypeAnn -> Bool
$c/= :: TypeAnn -> TypeAnn -> Bool
/= :: TypeAnn -> TypeAnn -> Bool
Eq, TypeAnn -> ()
(TypeAnn -> ()) -> NFData TypeAnn
forall a. (a -> ()) -> NFData a
$crnf :: TypeAnn -> ()
rnf :: TypeAnn -> ()
NFData, Typeable TypeAnn
Typeable TypeAnn
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> TypeAnn -> c TypeAnn)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c TypeAnn)
-> (TypeAnn -> Constr)
-> (TypeAnn -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c TypeAnn))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TypeAnn))
-> ((forall b. Data b => b -> b) -> TypeAnn -> TypeAnn)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> TypeAnn -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> TypeAnn -> r)
-> (forall u. (forall d. Data d => d -> u) -> TypeAnn -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> TypeAnn -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn)
-> Data TypeAnn
TypeAnn -> Constr
TypeAnn -> DataType
(forall b. Data b => b -> b) -> TypeAnn -> TypeAnn
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> TypeAnn -> u
forall u. (forall d. Data d => d -> u) -> TypeAnn -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TypeAnn -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TypeAnn -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TypeAnn
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TypeAnn -> c TypeAnn
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TypeAnn)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TypeAnn)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TypeAnn -> c TypeAnn
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TypeAnn -> c TypeAnn
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TypeAnn
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TypeAnn
$ctoConstr :: TypeAnn -> Constr
toConstr :: TypeAnn -> Constr
$cdataTypeOf :: TypeAnn -> DataType
dataTypeOf :: TypeAnn -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TypeAnn)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TypeAnn)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TypeAnn)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TypeAnn)
$cgmapT :: (forall b. Data b => b -> b) -> TypeAnn -> TypeAnn
gmapT :: (forall b. Data b => b -> b) -> TypeAnn -> TypeAnn
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TypeAnn -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TypeAnn -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TypeAnn -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TypeAnn -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TypeAnn -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> TypeAnn -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TypeAnn -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TypeAnn -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TypeAnn -> m TypeAnn
Data, Eq TypeAnn
Eq TypeAnn
-> (Int -> TypeAnn -> Int) -> (TypeAnn -> Int) -> Hashable TypeAnn
Int -> TypeAnn -> Int
TypeAnn -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> TypeAnn -> Int
hashWithSalt :: Int -> TypeAnn -> Int
$chash :: TypeAnn -> Int
hash :: TypeAnn -> Int
Hashable)

instance ToSQL TypeAnn where
  toSQL :: TypeAnn -> Builder
toSQL (TypeAnn Text
ty) = Builder
"::" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
TB.text Text
ty

mkTypeAnn :: CollectableType PGScalarType -> TypeAnn
mkTypeAnn :: CollectableType PGScalarType -> TypeAnn
mkTypeAnn = Text -> TypeAnn
TypeAnn (Text -> TypeAnn)
-> (CollectableType PGScalarType -> Text)
-> CollectableType PGScalarType
-> TypeAnn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CollectableType PGScalarType -> Text
forall a. ToSQL a => a -> Text
toSQLTxt

intTypeAnn :: TypeAnn
intTypeAnn :: TypeAnn
intTypeAnn = CollectableType PGScalarType -> TypeAnn
mkTypeAnn (CollectableType PGScalarType -> TypeAnn)
-> CollectableType PGScalarType -> TypeAnn
forall a b. (a -> b) -> a -> b
$ PGScalarType -> CollectableType PGScalarType
forall a. a -> CollectableType a
CollectableTypeScalar PGScalarType
PGInteger

numericTypeAnn :: TypeAnn
numericTypeAnn :: TypeAnn
numericTypeAnn = CollectableType PGScalarType -> TypeAnn
mkTypeAnn (CollectableType PGScalarType -> TypeAnn)
-> CollectableType PGScalarType -> TypeAnn
forall a b. (a -> b) -> a -> b
$ PGScalarType -> CollectableType PGScalarType
forall a. a -> CollectableType a
CollectableTypeScalar PGScalarType
PGNumeric

textTypeAnn :: TypeAnn
textTypeAnn :: TypeAnn
textTypeAnn = CollectableType PGScalarType -> TypeAnn
mkTypeAnn (CollectableType PGScalarType -> TypeAnn)
-> CollectableType PGScalarType -> TypeAnn
forall a b. (a -> b) -> a -> b
$ PGScalarType -> CollectableType PGScalarType
forall a. a -> CollectableType a
CollectableTypeScalar PGScalarType
PGText

textArrTypeAnn :: TypeAnn
textArrTypeAnn :: TypeAnn
textArrTypeAnn = CollectableType PGScalarType -> TypeAnn
mkTypeAnn (CollectableType PGScalarType -> TypeAnn)
-> CollectableType PGScalarType -> TypeAnn
forall a b. (a -> b) -> a -> b
$ PGScalarType -> CollectableType PGScalarType
forall a. a -> CollectableType a
CollectableTypeArray PGScalarType
PGText

jsonTypeAnn :: TypeAnn
jsonTypeAnn :: TypeAnn
jsonTypeAnn = CollectableType PGScalarType -> TypeAnn
mkTypeAnn (CollectableType PGScalarType -> TypeAnn)
-> CollectableType PGScalarType -> TypeAnn
forall a b. (a -> b) -> a -> b
$ PGScalarType -> CollectableType PGScalarType
forall a. a -> CollectableType a
CollectableTypeScalar PGScalarType
PGJSON

jsonbTypeAnn :: TypeAnn
jsonbTypeAnn :: TypeAnn
jsonbTypeAnn = CollectableType PGScalarType -> TypeAnn
mkTypeAnn (CollectableType PGScalarType -> TypeAnn)
-> CollectableType PGScalarType -> TypeAnn
forall a b. (a -> b) -> a -> b
$ PGScalarType -> CollectableType PGScalarType
forall a. a -> CollectableType a
CollectableTypeScalar PGScalarType
PGJSONB

boolTypeAnn :: TypeAnn
boolTypeAnn :: TypeAnn
boolTypeAnn = CollectableType PGScalarType -> TypeAnn
mkTypeAnn (CollectableType PGScalarType -> TypeAnn)
-> CollectableType PGScalarType -> TypeAnn
forall a b. (a -> b) -> a -> b
$ PGScalarType -> CollectableType PGScalarType
forall a. a -> CollectableType a
CollectableTypeScalar PGScalarType
PGBoolean

data CountType columnType
  = CTStar
  | CTSimple [columnType]
  | CTDistinct [columnType]
  deriving (Int -> CountType columnType -> ShowS
[CountType columnType] -> ShowS
CountType columnType -> String
(Int -> CountType columnType -> ShowS)
-> (CountType columnType -> String)
-> ([CountType columnType] -> ShowS)
-> Show (CountType columnType)
forall columnType.
Show columnType =>
Int -> CountType columnType -> ShowS
forall columnType.
Show columnType =>
[CountType columnType] -> ShowS
forall columnType.
Show columnType =>
CountType columnType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall columnType.
Show columnType =>
Int -> CountType columnType -> ShowS
showsPrec :: Int -> CountType columnType -> ShowS
$cshow :: forall columnType.
Show columnType =>
CountType columnType -> String
show :: CountType columnType -> String
$cshowList :: forall columnType.
Show columnType =>
[CountType columnType] -> ShowS
showList :: [CountType columnType] -> ShowS
Show, CountType columnType -> CountType columnType -> Bool
(CountType columnType -> CountType columnType -> Bool)
-> (CountType columnType -> CountType columnType -> Bool)
-> Eq (CountType columnType)
forall columnType.
Eq columnType =>
CountType columnType -> CountType columnType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall columnType.
Eq columnType =>
CountType columnType -> CountType columnType -> Bool
== :: CountType columnType -> CountType columnType -> Bool
$c/= :: forall columnType.
Eq columnType =>
CountType columnType -> CountType columnType -> Bool
/= :: CountType columnType -> CountType columnType -> Bool
Eq, (forall x. CountType columnType -> Rep (CountType columnType) x)
-> (forall x. Rep (CountType columnType) x -> CountType columnType)
-> Generic (CountType columnType)
forall x. Rep (CountType columnType) x -> CountType columnType
forall x. CountType columnType -> Rep (CountType columnType) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall columnType x.
Rep (CountType columnType) x -> CountType columnType
forall columnType x.
CountType columnType -> Rep (CountType columnType) x
$cfrom :: forall columnType x.
CountType columnType -> Rep (CountType columnType) x
from :: forall x. CountType columnType -> Rep (CountType columnType) x
$cto :: forall columnType x.
Rep (CountType columnType) x -> CountType columnType
to :: forall x. Rep (CountType columnType) x -> CountType columnType
Generic, Typeable (CountType columnType)
Typeable (CountType columnType)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> CountType columnType
    -> c (CountType columnType))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (CountType columnType))
-> (CountType columnType -> Constr)
-> (CountType columnType -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (CountType columnType)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (CountType columnType)))
-> ((forall b. Data b => b -> b)
    -> CountType columnType -> CountType columnType)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CountType columnType -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CountType columnType -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> CountType columnType -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> CountType columnType -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> CountType columnType -> m (CountType columnType))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> CountType columnType -> m (CountType columnType))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> CountType columnType -> m (CountType columnType))
-> Data (CountType columnType)
CountType columnType -> Constr
CountType columnType -> DataType
(forall b. Data b => b -> b)
-> CountType columnType -> CountType columnType
forall {columnType}.
Data columnType =>
Typeable (CountType columnType)
forall columnType.
Data columnType =>
CountType columnType -> Constr
forall columnType.
Data columnType =>
CountType columnType -> DataType
forall columnType.
Data columnType =>
(forall b. Data b => b -> b)
-> CountType columnType -> CountType columnType
forall columnType u.
Data columnType =>
Int -> (forall d. Data d => d -> u) -> CountType columnType -> u
forall columnType u.
Data columnType =>
(forall d. Data d => d -> u) -> CountType columnType -> [u]
forall columnType r r'.
Data columnType =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CountType columnType -> r
forall columnType r r'.
Data columnType =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CountType columnType -> r
forall columnType (m :: * -> *).
(Data columnType, Monad m) =>
(forall d. Data d => d -> m d)
-> CountType columnType -> m (CountType columnType)
forall columnType (m :: * -> *).
(Data columnType, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> CountType columnType -> m (CountType columnType)
forall columnType (c :: * -> *).
Data columnType =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CountType columnType)
forall columnType (c :: * -> *).
Data columnType =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> CountType columnType
-> c (CountType columnType)
forall columnType (t :: * -> *) (c :: * -> *).
(Data columnType, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (CountType columnType))
forall columnType (t :: * -> * -> *) (c :: * -> *).
(Data columnType, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (CountType columnType))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> CountType columnType -> u
forall u.
(forall d. Data d => d -> u) -> CountType columnType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CountType columnType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CountType columnType -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> CountType columnType -> m (CountType columnType)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CountType columnType -> m (CountType columnType)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CountType columnType)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> CountType columnType
-> c (CountType columnType)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (CountType columnType))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (CountType columnType))
$cgfoldl :: forall columnType (c :: * -> *).
Data columnType =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> CountType columnType
-> c (CountType columnType)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> CountType columnType
-> c (CountType columnType)
$cgunfold :: forall columnType (c :: * -> *).
Data columnType =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CountType columnType)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CountType columnType)
$ctoConstr :: forall columnType.
Data columnType =>
CountType columnType -> Constr
toConstr :: CountType columnType -> Constr
$cdataTypeOf :: forall columnType.
Data columnType =>
CountType columnType -> DataType
dataTypeOf :: CountType columnType -> DataType
$cdataCast1 :: forall columnType (t :: * -> *) (c :: * -> *).
(Data columnType, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (CountType columnType))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (CountType columnType))
$cdataCast2 :: forall columnType (t :: * -> * -> *) (c :: * -> *).
(Data columnType, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (CountType columnType))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (CountType columnType))
$cgmapT :: forall columnType.
Data columnType =>
(forall b. Data b => b -> b)
-> CountType columnType -> CountType columnType
gmapT :: (forall b. Data b => b -> b)
-> CountType columnType -> CountType columnType
$cgmapQl :: forall columnType r r'.
Data columnType =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CountType columnType -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CountType columnType -> r
$cgmapQr :: forall columnType r r'.
Data columnType =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CountType columnType -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CountType columnType -> r
$cgmapQ :: forall columnType u.
Data columnType =>
(forall d. Data d => d -> u) -> CountType columnType -> [u]
gmapQ :: forall u.
(forall d. Data d => d -> u) -> CountType columnType -> [u]
$cgmapQi :: forall columnType u.
Data columnType =>
Int -> (forall d. Data d => d -> u) -> CountType columnType -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> CountType columnType -> u
$cgmapM :: forall columnType (m :: * -> *).
(Data columnType, Monad m) =>
(forall d. Data d => d -> m d)
-> CountType columnType -> m (CountType columnType)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> CountType columnType -> m (CountType columnType)
$cgmapMp :: forall columnType (m :: * -> *).
(Data columnType, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> CountType columnType -> m (CountType columnType)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CountType columnType -> m (CountType columnType)
$cgmapMo :: forall columnType (m :: * -> *).
(Data columnType, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> CountType columnType -> m (CountType columnType)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CountType columnType -> m (CountType columnType)
Data, (forall a b. (a -> b) -> CountType a -> CountType b)
-> (forall a b. a -> CountType b -> CountType a)
-> Functor CountType
forall a b. a -> CountType b -> CountType a
forall a b. (a -> b) -> CountType a -> CountType b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> CountType a -> CountType b
fmap :: forall a b. (a -> b) -> CountType a -> CountType b
$c<$ :: forall a b. a -> CountType b -> CountType a
<$ :: forall a b. a -> CountType b -> CountType a
Functor, (forall m. Monoid m => CountType m -> m)
-> (forall m a. Monoid m => (a -> m) -> CountType a -> m)
-> (forall m a. Monoid m => (a -> m) -> CountType a -> m)
-> (forall a b. (a -> b -> b) -> b -> CountType a -> b)
-> (forall a b. (a -> b -> b) -> b -> CountType a -> b)
-> (forall b a. (b -> a -> b) -> b -> CountType a -> b)
-> (forall b a. (b -> a -> b) -> b -> CountType a -> b)
-> (forall a. (a -> a -> a) -> CountType a -> a)
-> (forall a. (a -> a -> a) -> CountType a -> a)
-> (forall a. CountType a -> [a])
-> (forall a. CountType a -> Bool)
-> (forall a. CountType a -> Int)
-> (forall a. Eq a => a -> CountType a -> Bool)
-> (forall a. Ord a => CountType a -> a)
-> (forall a. Ord a => CountType a -> a)
-> (forall a. Num a => CountType a -> a)
-> (forall a. Num a => CountType a -> a)
-> Foldable CountType
forall a. Eq a => a -> CountType a -> Bool
forall a. Num a => CountType a -> a
forall a. Ord a => CountType a -> a
forall m. Monoid m => CountType m -> m
forall a. CountType a -> Bool
forall a. CountType a -> Int
forall a. CountType a -> [a]
forall a. (a -> a -> a) -> CountType a -> a
forall m a. Monoid m => (a -> m) -> CountType a -> m
forall b a. (b -> a -> b) -> b -> CountType a -> b
forall a b. (a -> b -> b) -> b -> CountType a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => CountType m -> m
fold :: forall m. Monoid m => CountType m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> CountType a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> CountType a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> CountType a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> CountType a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> CountType a -> b
foldr :: forall a b. (a -> b -> b) -> b -> CountType a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> CountType a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> CountType a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> CountType a -> b
foldl :: forall b a. (b -> a -> b) -> b -> CountType a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> CountType a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> CountType a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> CountType a -> a
foldr1 :: forall a. (a -> a -> a) -> CountType a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> CountType a -> a
foldl1 :: forall a. (a -> a -> a) -> CountType a -> a
$ctoList :: forall a. CountType a -> [a]
toList :: forall a. CountType a -> [a]
$cnull :: forall a. CountType a -> Bool
null :: forall a. CountType a -> Bool
$clength :: forall a. CountType a -> Int
length :: forall a. CountType a -> Int
$celem :: forall a. Eq a => a -> CountType a -> Bool
elem :: forall a. Eq a => a -> CountType a -> Bool
$cmaximum :: forall a. Ord a => CountType a -> a
maximum :: forall a. Ord a => CountType a -> a
$cminimum :: forall a. Ord a => CountType a -> a
minimum :: forall a. Ord a => CountType a -> a
$csum :: forall a. Num a => CountType a -> a
sum :: forall a. Num a => CountType a -> a
$cproduct :: forall a. Num a => CountType a -> a
product :: forall a. Num a => CountType a -> a
Foldable, Functor CountType
Foldable CountType
Functor CountType
-> Foldable CountType
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> CountType a -> f (CountType b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    CountType (f a) -> f (CountType a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> CountType a -> m (CountType b))
-> (forall (m :: * -> *) a.
    Monad m =>
    CountType (m a) -> m (CountType a))
-> Traversable CountType
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
CountType (m a) -> m (CountType a)
forall (f :: * -> *) a.
Applicative f =>
CountType (f a) -> f (CountType a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> CountType a -> m (CountType b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> CountType a -> f (CountType b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> CountType a -> f (CountType b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> CountType a -> f (CountType b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
CountType (f a) -> f (CountType a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
CountType (f a) -> f (CountType a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> CountType a -> m (CountType b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> CountType a -> m (CountType b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
CountType (m a) -> m (CountType a)
sequence :: forall (m :: * -> *) a.
Monad m =>
CountType (m a) -> m (CountType a)
Traversable)

instance (NFData columnType) => NFData (CountType columnType)

instance (Hashable columnType) => Hashable (CountType columnType)

instance ToSQL (CountType QIdentifier) where
  toSQL :: CountType QIdentifier -> Builder
toSQL CountType QIdentifier
CTStar = Builder
"*"
  toSQL (CTSimple [QIdentifier]
cols) =
    Builder -> Builder
parenB (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$ Text
", " Text -> [QIdentifier] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [QIdentifier]
cols
  toSQL (CTDistinct [QIdentifier]
cols) =
    Builder
"DISTINCT" Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (Text
", " Text -> [QIdentifier] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [QIdentifier]
cols)

newtype TupleExp
  = TupleExp [SQLExp]
  deriving (Int -> TupleExp -> ShowS
[TupleExp] -> ShowS
TupleExp -> String
(Int -> TupleExp -> ShowS)
-> (TupleExp -> String) -> ([TupleExp] -> ShowS) -> Show TupleExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TupleExp -> ShowS
showsPrec :: Int -> TupleExp -> ShowS
$cshow :: TupleExp -> String
show :: TupleExp -> String
$cshowList :: [TupleExp] -> ShowS
showList :: [TupleExp] -> ShowS
Show, TupleExp -> TupleExp -> Bool
(TupleExp -> TupleExp -> Bool)
-> (TupleExp -> TupleExp -> Bool) -> Eq TupleExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TupleExp -> TupleExp -> Bool
== :: TupleExp -> TupleExp -> Bool
$c/= :: TupleExp -> TupleExp -> Bool
/= :: TupleExp -> TupleExp -> Bool
Eq, TupleExp -> ()
(TupleExp -> ()) -> NFData TupleExp
forall a. (a -> ()) -> NFData a
$crnf :: TupleExp -> ()
rnf :: TupleExp -> ()
NFData, Typeable TupleExp
Typeable TupleExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> TupleExp -> c TupleExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c TupleExp)
-> (TupleExp -> Constr)
-> (TupleExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c TupleExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TupleExp))
-> ((forall b. Data b => b -> b) -> TupleExp -> TupleExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> TupleExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> TupleExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> TupleExp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> TupleExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> TupleExp -> m TupleExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TupleExp -> m TupleExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TupleExp -> m TupleExp)
-> Data TupleExp
TupleExp -> Constr
TupleExp -> DataType
(forall b. Data b => b -> b) -> TupleExp -> TupleExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> TupleExp -> u
forall u. (forall d. Data d => d -> u) -> TupleExp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TupleExp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TupleExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TupleExp -> m TupleExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TupleExp -> m TupleExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TupleExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TupleExp -> c TupleExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TupleExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TupleExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TupleExp -> c TupleExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TupleExp -> c TupleExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TupleExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TupleExp
$ctoConstr :: TupleExp -> Constr
toConstr :: TupleExp -> Constr
$cdataTypeOf :: TupleExp -> DataType
dataTypeOf :: TupleExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TupleExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TupleExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TupleExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TupleExp)
$cgmapT :: (forall b. Data b => b -> b) -> TupleExp -> TupleExp
gmapT :: (forall b. Data b => b -> b) -> TupleExp -> TupleExp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TupleExp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TupleExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TupleExp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TupleExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TupleExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> TupleExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TupleExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TupleExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TupleExp -> m TupleExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TupleExp -> m TupleExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TupleExp -> m TupleExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TupleExp -> m TupleExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TupleExp -> m TupleExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TupleExp -> m TupleExp
Data, Eq TupleExp
Eq TupleExp
-> (Int -> TupleExp -> Int)
-> (TupleExp -> Int)
-> Hashable TupleExp
Int -> TupleExp -> Int
TupleExp -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> TupleExp -> Int
hashWithSalt :: Int -> TupleExp -> Int
$chash :: TupleExp -> Int
hash :: TupleExp -> Int
Hashable)

instance ToSQL TupleExp where
  toSQL :: TupleExp -> Builder
toSQL (TupleExp [SQLExp]
exps) =
    Builder -> Builder
parenB (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$ Text
", " Text -> [SQLExp] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [SQLExp]
exps

data SQLExp
  = SEPrep Int
  | SENull
  | SELit Text
  | SEUnsafe Text
  | SESelect Select
  | -- | all fields (@*@) or all fields from relation (@iden.*@)
    SEStar (Maybe Qual)
  | -- | A column name
    SEIdentifier Identifier
  | -- | SEIdentifier and SERowIdentifier are distinguished for easier rewrite rules
    SERowIdentifier Identifier
  | -- | A qualified column name
    SEQIdentifier QIdentifier
  | -- | this is used to apply a sql function to an expression. The 'Text' is the function name
    SEFnApp Text [SQLExp] (Maybe OrderByExp)
  | SEOpApp SQLOp [SQLExp]
  | SETyAnn SQLExp TypeAnn
  | SECond BoolExp SQLExp SQLExp
  | SEBool BoolExp
  | SEExcluded Identifier
  | SEArray [SQLExp]
  | SEArrayIndex SQLExp SQLExp
  | SETuple TupleExp
  | SECount (CountType QIdentifier)
  | SENamedArg Identifier SQLExp
  | SEFunction FunctionExp
  deriving (Int -> SQLExp -> ShowS
[SQLExp] -> ShowS
SQLExp -> String
(Int -> SQLExp -> ShowS)
-> (SQLExp -> String) -> ([SQLExp] -> ShowS) -> Show SQLExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SQLExp -> ShowS
showsPrec :: Int -> SQLExp -> ShowS
$cshow :: SQLExp -> String
show :: SQLExp -> String
$cshowList :: [SQLExp] -> ShowS
showList :: [SQLExp] -> ShowS
Show, SQLExp -> SQLExp -> Bool
(SQLExp -> SQLExp -> Bool)
-> (SQLExp -> SQLExp -> Bool) -> Eq SQLExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SQLExp -> SQLExp -> Bool
== :: SQLExp -> SQLExp -> Bool
$c/= :: SQLExp -> SQLExp -> Bool
/= :: SQLExp -> SQLExp -> Bool
Eq, (forall x. SQLExp -> Rep SQLExp x)
-> (forall x. Rep SQLExp x -> SQLExp) -> Generic SQLExp
forall x. Rep SQLExp x -> SQLExp
forall x. SQLExp -> Rep SQLExp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SQLExp -> Rep SQLExp x
from :: forall x. SQLExp -> Rep SQLExp x
$cto :: forall x. Rep SQLExp x -> SQLExp
to :: forall x. Rep SQLExp x -> SQLExp
Generic, Typeable SQLExp
Typeable SQLExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> SQLExp -> c SQLExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c SQLExp)
-> (SQLExp -> Constr)
-> (SQLExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c SQLExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SQLExp))
-> ((forall b. Data b => b -> b) -> SQLExp -> SQLExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> SQLExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> SQLExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> SQLExp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> SQLExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> SQLExp -> m SQLExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SQLExp -> m SQLExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SQLExp -> m SQLExp)
-> Data SQLExp
SQLExp -> Constr
SQLExp -> DataType
(forall b. Data b => b -> b) -> SQLExp -> SQLExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> SQLExp -> u
forall u. (forall d. Data d => d -> u) -> SQLExp -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SQLExp -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SQLExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SQLExp -> m SQLExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SQLExp -> m SQLExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SQLExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SQLExp -> c SQLExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SQLExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SQLExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SQLExp -> c SQLExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SQLExp -> c SQLExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SQLExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SQLExp
$ctoConstr :: SQLExp -> Constr
toConstr :: SQLExp -> Constr
$cdataTypeOf :: SQLExp -> DataType
dataTypeOf :: SQLExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SQLExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SQLExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SQLExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SQLExp)
$cgmapT :: (forall b. Data b => b -> b) -> SQLExp -> SQLExp
gmapT :: (forall b. Data b => b -> b) -> SQLExp -> SQLExp
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SQLExp -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SQLExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SQLExp -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SQLExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> SQLExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> SQLExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SQLExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SQLExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SQLExp -> m SQLExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SQLExp -> m SQLExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SQLExp -> m SQLExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SQLExp -> m SQLExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SQLExp -> m SQLExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SQLExp -> m SQLExp
Data)

instance NFData SQLExp

instance Hashable SQLExp

instance J.ToJSON SQLExp where
  toJSON :: SQLExp -> Value
toJSON = Text -> Value
forall a. ToJSON a => a -> Value
J.toJSON (Text -> Value) -> (SQLExp -> Text) -> SQLExp -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SQLExp -> Text
forall a. ToSQL a => a -> Text
toSQLTxt

-- | Represents an alias assignment for a column
newtype ColumnAlias = ColumnAlias {ColumnAlias -> Identifier
getColumnAlias :: Identifier}
  deriving (Int -> ColumnAlias -> ShowS
[ColumnAlias] -> ShowS
ColumnAlias -> String
(Int -> ColumnAlias -> ShowS)
-> (ColumnAlias -> String)
-> ([ColumnAlias] -> ShowS)
-> Show ColumnAlias
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ColumnAlias -> ShowS
showsPrec :: Int -> ColumnAlias -> ShowS
$cshow :: ColumnAlias -> String
show :: ColumnAlias -> String
$cshowList :: [ColumnAlias] -> ShowS
showList :: [ColumnAlias] -> ShowS
Show, ColumnAlias -> ColumnAlias -> Bool
(ColumnAlias -> ColumnAlias -> Bool)
-> (ColumnAlias -> ColumnAlias -> Bool) -> Eq ColumnAlias
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ColumnAlias -> ColumnAlias -> Bool
== :: ColumnAlias -> ColumnAlias -> Bool
$c/= :: ColumnAlias -> ColumnAlias -> Bool
/= :: ColumnAlias -> ColumnAlias -> Bool
Eq, ColumnAlias -> ()
(ColumnAlias -> ()) -> NFData ColumnAlias
forall a. (a -> ()) -> NFData a
$crnf :: ColumnAlias -> ()
rnf :: ColumnAlias -> ()
NFData, Typeable ColumnAlias
Typeable ColumnAlias
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ColumnAlias -> c ColumnAlias)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ColumnAlias)
-> (ColumnAlias -> Constr)
-> (ColumnAlias -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ColumnAlias))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ColumnAlias))
-> ((forall b. Data b => b -> b) -> ColumnAlias -> ColumnAlias)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ColumnAlias -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ColumnAlias -> r)
-> (forall u. (forall d. Data d => d -> u) -> ColumnAlias -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ColumnAlias -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias)
-> Data ColumnAlias
ColumnAlias -> Constr
ColumnAlias -> DataType
(forall b. Data b => b -> b) -> ColumnAlias -> ColumnAlias
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ColumnAlias -> u
forall u. (forall d. Data d => d -> u) -> ColumnAlias -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnAlias -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnAlias -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ColumnAlias
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ColumnAlias -> c ColumnAlias
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ColumnAlias)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ColumnAlias)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ColumnAlias -> c ColumnAlias
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ColumnAlias -> c ColumnAlias
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ColumnAlias
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ColumnAlias
$ctoConstr :: ColumnAlias -> Constr
toConstr :: ColumnAlias -> Constr
$cdataTypeOf :: ColumnAlias -> DataType
dataTypeOf :: ColumnAlias -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ColumnAlias)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ColumnAlias)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ColumnAlias)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ColumnAlias)
$cgmapT :: (forall b. Data b => b -> b) -> ColumnAlias -> ColumnAlias
gmapT :: (forall b. Data b => b -> b) -> ColumnAlias -> ColumnAlias
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnAlias -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnAlias -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnAlias -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ColumnAlias -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ColumnAlias -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> ColumnAlias -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ColumnAlias -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ColumnAlias -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ColumnAlias -> m ColumnAlias
Data, Eq ColumnAlias
Eq ColumnAlias
-> (Int -> ColumnAlias -> Int)
-> (ColumnAlias -> Int)
-> Hashable ColumnAlias
Int -> ColumnAlias -> Int
ColumnAlias -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> ColumnAlias -> Int
hashWithSalt :: Int -> ColumnAlias -> Int
$chash :: ColumnAlias -> Int
hash :: ColumnAlias -> Int
Hashable)

instance IsString ColumnAlias where
  fromString :: String -> ColumnAlias
fromString = Text -> ColumnAlias
mkColumnAlias (Text -> ColumnAlias) -> (String -> Text) -> String -> ColumnAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
pack

instance Semigroup ColumnAlias where
  (ColumnAlias Identifier
ca1) <> :: ColumnAlias -> ColumnAlias -> ColumnAlias
<> (ColumnAlias Identifier
ca2) = Identifier -> ColumnAlias
ColumnAlias (Identifier
ca1 Identifier -> Identifier -> Identifier
forall a. Semigroup a => a -> a -> a
<> Identifier
ca2)

mkColumnAlias :: Text -> ColumnAlias
mkColumnAlias :: Text -> ColumnAlias
mkColumnAlias = Identifier -> ColumnAlias
ColumnAlias (Identifier -> ColumnAlias)
-> (Text -> Identifier) -> Text -> ColumnAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Identifier
Identifier

instance IsIdentifier ColumnAlias where
  toIdentifier :: ColumnAlias -> Identifier
toIdentifier (ColumnAlias Identifier
identifier) = Identifier
identifier

tableIdentifierToColumnAlias :: TableIdentifier -> ColumnAlias
tableIdentifierToColumnAlias :: TableIdentifier -> ColumnAlias
tableIdentifierToColumnAlias = Text -> ColumnAlias
mkColumnAlias (Text -> ColumnAlias)
-> (TableIdentifier -> Text) -> TableIdentifier -> ColumnAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableIdentifier -> Text
unTableIdentifier

toColumnAlias :: (IsIdentifier a) => a -> ColumnAlias
toColumnAlias :: forall a. IsIdentifier a => a -> ColumnAlias
toColumnAlias = Identifier -> ColumnAlias
ColumnAlias (Identifier -> ColumnAlias)
-> (a -> Identifier) -> a -> ColumnAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier

-- | Convert a column alias assignment to SQL _with_ @AS@ prefix
columnAliasToSqlWithAs :: ColumnAlias -> TB.Builder
columnAliasToSqlWithAs :: ColumnAlias -> Builder
columnAliasToSqlWithAs (ColumnAlias Identifier
alias) = Builder
"AS" Builder -> Builder -> Builder
<~> Identifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL Identifier
alias

-- | Convert a column alias assignment to SQL _without_ @AS@ prefix
columnAliasToSqlWithoutAs :: ColumnAlias -> TB.Builder
columnAliasToSqlWithoutAs :: ColumnAlias -> Builder
columnAliasToSqlWithoutAs ColumnAlias
alias = Identifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL (ColumnAlias -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier ColumnAlias
alias)

-- | Represents an alias assignment for a table, relation or row
newtype TableAlias = TableAlias {TableAlias -> Identifier
getTableAlias :: Identifier}
  deriving (Int -> TableAlias -> ShowS
[TableAlias] -> ShowS
TableAlias -> String
(Int -> TableAlias -> ShowS)
-> (TableAlias -> String)
-> ([TableAlias] -> ShowS)
-> Show TableAlias
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TableAlias -> ShowS
showsPrec :: Int -> TableAlias -> ShowS
$cshow :: TableAlias -> String
show :: TableAlias -> String
$cshowList :: [TableAlias] -> ShowS
showList :: [TableAlias] -> ShowS
Show, TableAlias -> TableAlias -> Bool
(TableAlias -> TableAlias -> Bool)
-> (TableAlias -> TableAlias -> Bool) -> Eq TableAlias
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TableAlias -> TableAlias -> Bool
== :: TableAlias -> TableAlias -> Bool
$c/= :: TableAlias -> TableAlias -> Bool
/= :: TableAlias -> TableAlias -> Bool
Eq, TableAlias -> ()
(TableAlias -> ()) -> NFData TableAlias
forall a. (a -> ()) -> NFData a
$crnf :: TableAlias -> ()
rnf :: TableAlias -> ()
NFData, Typeable TableAlias
Typeable TableAlias
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> TableAlias -> c TableAlias)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c TableAlias)
-> (TableAlias -> Constr)
-> (TableAlias -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c TableAlias))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c TableAlias))
-> ((forall b. Data b => b -> b) -> TableAlias -> TableAlias)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> TableAlias -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> TableAlias -> r)
-> (forall u. (forall d. Data d => d -> u) -> TableAlias -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> TableAlias -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> TableAlias -> m TableAlias)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TableAlias -> m TableAlias)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TableAlias -> m TableAlias)
-> Data TableAlias
TableAlias -> Constr
TableAlias -> DataType
(forall b. Data b => b -> b) -> TableAlias -> TableAlias
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> TableAlias -> u
forall u. (forall d. Data d => d -> u) -> TableAlias -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TableAlias -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TableAlias -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TableAlias -> m TableAlias
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TableAlias -> m TableAlias
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TableAlias
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TableAlias -> c TableAlias
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TableAlias)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TableAlias)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TableAlias -> c TableAlias
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TableAlias -> c TableAlias
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TableAlias
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TableAlias
$ctoConstr :: TableAlias -> Constr
toConstr :: TableAlias -> Constr
$cdataTypeOf :: TableAlias -> DataType
dataTypeOf :: TableAlias -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TableAlias)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TableAlias)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TableAlias)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TableAlias)
$cgmapT :: (forall b. Data b => b -> b) -> TableAlias -> TableAlias
gmapT :: (forall b. Data b => b -> b) -> TableAlias -> TableAlias
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TableAlias -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TableAlias -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TableAlias -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TableAlias -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TableAlias -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> TableAlias -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TableAlias -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TableAlias -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TableAlias -> m TableAlias
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TableAlias -> m TableAlias
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TableAlias -> m TableAlias
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TableAlias -> m TableAlias
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TableAlias -> m TableAlias
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TableAlias -> m TableAlias
Data, (forall x. TableAlias -> Rep TableAlias x)
-> (forall x. Rep TableAlias x -> TableAlias) -> Generic TableAlias
forall x. Rep TableAlias x -> TableAlias
forall x. TableAlias -> Rep TableAlias x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TableAlias -> Rep TableAlias x
from :: forall x. TableAlias -> Rep TableAlias x
$cto :: forall x. Rep TableAlias x -> TableAlias
to :: forall x. Rep TableAlias x -> TableAlias
Generic, Eq TableAlias
Eq TableAlias
-> (Int -> TableAlias -> Int)
-> (TableAlias -> Int)
-> Hashable TableAlias
Int -> TableAlias -> Int
TableAlias -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> TableAlias -> Int
hashWithSalt :: Int -> TableAlias -> Int
$chash :: TableAlias -> Int
hash :: TableAlias -> Int
Hashable)

instance IsString TableAlias where
  fromString :: String -> TableAlias
fromString = Text -> TableAlias
mkTableAlias (Text -> TableAlias) -> (String -> Text) -> String -> TableAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
pack

instance Semigroup TableAlias where
  (TableAlias Identifier
ta1) <> :: TableAlias -> TableAlias -> TableAlias
<> (TableAlias Identifier
ta2) = Identifier -> TableAlias
TableAlias (Identifier
ta1 Identifier -> Identifier -> Identifier
forall a. Semigroup a => a -> a -> a
<> Identifier
ta2)

-- | Create a table alias.
mkTableAlias :: Text -> TableAlias
mkTableAlias :: Text -> TableAlias
mkTableAlias = Identifier -> TableAlias
TableAlias (Identifier -> TableAlias)
-> (Text -> Identifier) -> Text -> TableAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Identifier
Identifier

-- | Create a table identifier from a table alias.
tableAliasToIdentifier :: TableAlias -> TableIdentifier
tableAliasToIdentifier :: TableAlias -> TableIdentifier
tableAliasToIdentifier = Text -> TableIdentifier
TableIdentifier (Text -> TableIdentifier)
-> (TableAlias -> Text) -> TableAlias -> TableIdentifier
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> Text
getIdenTxt (Identifier -> Text)
-> (TableAlias -> Identifier) -> TableAlias -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableAlias -> Identifier
getTableAlias

instance IsIdentifier TableAlias where
  toIdentifier :: TableAlias -> Identifier
toIdentifier (TableAlias Identifier
identifier) = Identifier
identifier

-- TODO: Remove when we remove 'Identifier'. We should only be able to create
-- identifiers from aliases, not aliases from identifiers. Aliases represent
-- definition sites and identifiers usage sites.
toTableAlias :: (IsIdentifier a) => a -> TableAlias
toTableAlias :: forall a. IsIdentifier a => a -> TableAlias
toTableAlias = Identifier -> TableAlias
TableAlias (Identifier -> TableAlias) -> (a -> Identifier) -> a -> TableAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier

-- | Convert a table alias assignment to SQL _with_ @AS@ prefix
tableAliasToSqlWithAs :: TableAlias -> TB.Builder
tableAliasToSqlWithAs :: TableAlias -> Builder
tableAliasToSqlWithAs TableAlias
alias = Builder
"AS" Builder -> Builder -> Builder
<~> Identifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL (TableAlias -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier TableAlias
alias)

-- | Convert a table alias assignment to SQL _without_ @AS@ prefix
tableAliasToSqlWithoutAs :: TableAlias -> TB.Builder
tableAliasToSqlWithoutAs :: TableAlias -> Builder
tableAliasToSqlWithoutAs TableAlias
alias = Identifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL (TableAlias -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier TableAlias
alias)

countStar :: SQLExp
countStar :: SQLExp
countStar = CountType QIdentifier -> SQLExp
SECount CountType QIdentifier
forall columnType. CountType columnType
CTStar

instance ToSQL SQLExp where
  toSQL :: SQLExp -> Builder
toSQL (SEPrep Int
argNumber) =
    Char -> Builder
TB.char Char
'$' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
forall a. IsString a => String -> a
fromString (Int -> String
forall a. Show a => a -> String
show Int
argNumber)
  toSQL SQLExp
SENull =
    Text -> Builder
TB.text Text
"NULL"
  toSQL (SELit Text
tv) =
    Text -> Builder
TB.text (Text -> Builder) -> Text -> Builder
forall a b. (a -> b) -> a -> b
$ Text -> Text
pgFmtLit Text
tv
  toSQL (SEUnsafe Text
t) =
    Text -> Builder
TB.text Text
t
  toSQL (SESelect Select
se) =
    Builder -> Builder
parenB (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$ Select -> Builder
forall a. ToSQL a => a -> Builder
toSQL Select
se
  toSQL (SEStar Maybe Qual
Nothing) =
    Char -> Builder
TB.char Char
'*'
  toSQL (SEStar (Just Qual
qual)) =
    [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat [Qual -> Builder
forall a. ToSQL a => a -> Builder
toSQL Qual
qual, Char -> Builder
TB.char Char
'.', Char -> Builder
TB.char Char
'*']
  toSQL (SEIdentifier Identifier
iden) =
    Identifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL Identifier
iden
  toSQL (SERowIdentifier Identifier
iden) =
    Identifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL Identifier
iden
  toSQL (SEQIdentifier QIdentifier
qIdentifier) =
    QIdentifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL QIdentifier
qIdentifier
  -- https://www.postgresql.org/docs/10/static/sql-expressions.html#SYNTAX-AGGREGATES
  toSQL (SEFnApp Text
name [SQLExp]
args Maybe OrderByExp
mObe) =
    Text -> Builder
TB.text Text
name Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parenB ((Text
", " Text -> [SQLExp] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [SQLExp]
args) Builder -> Builder -> Builder
<~> Maybe OrderByExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL Maybe OrderByExp
mObe)
  toSQL (SEOpApp SQLOp
op [SQLExp]
args) =
    Builder -> Builder
parenB (SQLOp -> Text
sqlOpTxt SQLOp
op Text -> [SQLExp] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [SQLExp]
args)
  toSQL (SETyAnn SQLExp
e TypeAnn
ty) =
    Builder -> Builder
parenB (SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
e) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> TypeAnn -> Builder
forall a. ToSQL a => a -> Builder
toSQL TypeAnn
ty
  toSQL (SECond BoolExp
cond SQLExp
te SQLExp
fe) =
    Builder
"CASE WHEN"
      Builder -> Builder -> Builder
<~> BoolExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL BoolExp
cond
      Builder -> Builder -> Builder
<~> Builder
"THEN"
      Builder -> Builder -> Builder
<~> SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
te
      Builder -> Builder -> Builder
<~> Builder
"ELSE"
      Builder -> Builder -> Builder
<~> SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
fe
      Builder -> Builder -> Builder
<~> Builder
"END"
  toSQL (SEBool BoolExp
be) = BoolExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL BoolExp
be
  toSQL (SEExcluded Identifier
i) =
    Builder
"EXCLUDED."
      Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Identifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL Identifier
i
  toSQL (SEArray [SQLExp]
exps) =
    Builder
"ARRAY"
      Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Char -> Builder
TB.char Char
'['
      Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> (Text
", " Text -> [SQLExp] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [SQLExp]
exps)
      Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Char -> Builder
TB.char Char
']'
  toSQL (SEArrayIndex SQLExp
arrayExp SQLExp
indexExp) =
    Builder -> Builder
parenB (SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
arrayExp)
      Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Char -> Builder
TB.char Char
'['
      Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
indexExp
      Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Char -> Builder
TB.char Char
']'
  toSQL (SETuple TupleExp
tup) = TupleExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL TupleExp
tup
  toSQL (SECount CountType QIdentifier
ty) = Builder
"COUNT" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parenB (CountType QIdentifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL CountType QIdentifier
ty)
  -- https://www.postgresql.org/docs/current/sql-syntax-calling-funcs.html
  toSQL (SENamedArg Identifier
arg SQLExp
val) = Identifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL Identifier
arg Builder -> Builder -> Builder
<~> Builder
"=>" Builder -> Builder -> Builder
<~> SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
val
  toSQL (SEFunction FunctionExp
funcExp) = FunctionExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL FunctionExp
funcExp

intToSQLExp :: Int -> SQLExp
intToSQLExp :: Int -> SQLExp
intToSQLExp = Text -> SQLExp
SEUnsafe (Text -> SQLExp) -> (Int -> Text) -> Int -> SQLExp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text
forall a. Show a => a -> Text
tshow

int64ToSQLExp :: Int64 -> SQLExp
int64ToSQLExp :: Int64 -> SQLExp
int64ToSQLExp = Text -> SQLExp
SEUnsafe (Text -> SQLExp) -> (Int64 -> Text) -> Int64 -> SQLExp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Text
forall a. Show a => a -> Text
tshow

-- | Extractor can be used to apply Postgres alias to a column
data Extractor = Extractor SQLExp (Maybe ColumnAlias)
  deriving (Int -> Extractor -> ShowS
[Extractor] -> ShowS
Extractor -> String
(Int -> Extractor -> ShowS)
-> (Extractor -> String)
-> ([Extractor] -> ShowS)
-> Show Extractor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Extractor -> ShowS
showsPrec :: Int -> Extractor -> ShowS
$cshow :: Extractor -> String
show :: Extractor -> String
$cshowList :: [Extractor] -> ShowS
showList :: [Extractor] -> ShowS
Show, Extractor -> Extractor -> Bool
(Extractor -> Extractor -> Bool)
-> (Extractor -> Extractor -> Bool) -> Eq Extractor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Extractor -> Extractor -> Bool
== :: Extractor -> Extractor -> Bool
$c/= :: Extractor -> Extractor -> Bool
/= :: Extractor -> Extractor -> Bool
Eq, (forall x. Extractor -> Rep Extractor x)
-> (forall x. Rep Extractor x -> Extractor) -> Generic Extractor
forall x. Rep Extractor x -> Extractor
forall x. Extractor -> Rep Extractor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Extractor -> Rep Extractor x
from :: forall x. Extractor -> Rep Extractor x
$cto :: forall x. Rep Extractor x -> Extractor
to :: forall x. Rep Extractor x -> Extractor
Generic, Typeable Extractor
Typeable Extractor
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Extractor -> c Extractor)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Extractor)
-> (Extractor -> Constr)
-> (Extractor -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Extractor))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Extractor))
-> ((forall b. Data b => b -> b) -> Extractor -> Extractor)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Extractor -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Extractor -> r)
-> (forall u. (forall d. Data d => d -> u) -> Extractor -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Extractor -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Extractor -> m Extractor)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Extractor -> m Extractor)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Extractor -> m Extractor)
-> Data Extractor
Extractor -> Constr
Extractor -> DataType
(forall b. Data b => b -> b) -> Extractor -> Extractor
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Extractor -> u
forall u. (forall d. Data d => d -> u) -> Extractor -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Extractor -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Extractor -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Extractor -> m Extractor
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Extractor -> m Extractor
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Extractor
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Extractor -> c Extractor
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Extractor)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Extractor)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Extractor -> c Extractor
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Extractor -> c Extractor
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Extractor
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Extractor
$ctoConstr :: Extractor -> Constr
toConstr :: Extractor -> Constr
$cdataTypeOf :: Extractor -> DataType
dataTypeOf :: Extractor -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Extractor)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Extractor)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Extractor)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Extractor)
$cgmapT :: (forall b. Data b => b -> b) -> Extractor -> Extractor
gmapT :: (forall b. Data b => b -> b) -> Extractor -> Extractor
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Extractor -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Extractor -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Extractor -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Extractor -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Extractor -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Extractor -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Extractor -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Extractor -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Extractor -> m Extractor
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Extractor -> m Extractor
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Extractor -> m Extractor
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Extractor -> m Extractor
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Extractor -> m Extractor
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Extractor -> m Extractor
Data)

instance NFData Extractor

instance Hashable Extractor

mkSQLOpExp ::
  SQLOp ->
  SQLExp -> -- lhs
  SQLExp -> -- rhs
  SQLExp -- result
mkSQLOpExp :: SQLOp -> SQLExp -> SQLExp -> SQLExp
mkSQLOpExp SQLOp
op SQLExp
lhs SQLExp
rhs = SQLOp -> [SQLExp] -> SQLExp
SEOpApp SQLOp
op [SQLExp
lhs, SQLExp
rhs]

columnDefaultValue :: SQLExp
columnDefaultValue :: SQLExp
columnDefaultValue = Text -> SQLExp
SEUnsafe Text
"DEFAULT"

handleIfNull :: SQLExp -> SQLExp -> SQLExp
handleIfNull :: SQLExp -> SQLExp -> SQLExp
handleIfNull SQLExp
l SQLExp
e = Text -> [SQLExp] -> Maybe OrderByExp -> SQLExp
SEFnApp Text
"coalesce" [SQLExp
e, SQLExp
l] Maybe OrderByExp
forall a. Maybe a
Nothing

applyJsonBuildObj :: [SQLExp] -> SQLExp
applyJsonBuildObj :: [SQLExp] -> SQLExp
applyJsonBuildObj [SQLExp]
args =
  Text -> [SQLExp] -> Maybe OrderByExp -> SQLExp
SEFnApp Text
"json_build_object" [SQLExp]
args Maybe OrderByExp
forall a. Maybe a
Nothing

applyJsonBuildArray :: [SQLExp] -> SQLExp
applyJsonBuildArray :: [SQLExp] -> SQLExp
applyJsonBuildArray [SQLExp]
args =
  Text -> [SQLExp] -> Maybe OrderByExp -> SQLExp
SEFnApp Text
"json_build_array" [SQLExp]
args Maybe OrderByExp
forall a. Maybe a
Nothing

applyRowToJson :: [Extractor] -> SQLExp
applyRowToJson :: [Extractor] -> SQLExp
applyRowToJson [Extractor]
extrs =
  Text -> [SQLExp] -> Maybe OrderByExp -> SQLExp
SEFnApp Text
"row_to_json" [[Extractor] -> SQLExp
mkRowExp [Extractor]
extrs] Maybe OrderByExp
forall a. Maybe a
Nothing

applyUppercase :: SQLExp -> SQLExp
applyUppercase :: SQLExp -> SQLExp
applyUppercase SQLExp
arg =
  Text -> [SQLExp] -> Maybe OrderByExp -> SQLExp
SEFnApp Text
"upper" [SQLExp
arg] Maybe OrderByExp
forall a. Maybe a
Nothing

mkExtr :: (IsIdentifier a) => a -> Extractor
mkExtr :: forall a. IsIdentifier a => a -> Extractor
mkExtr a
t = SQLExp -> Maybe ColumnAlias -> Extractor
Extractor (a -> SQLExp
forall a. IsIdentifier a => a -> SQLExp
mkSIdenExp a
t) Maybe ColumnAlias
forall a. Maybe a
Nothing

instance ToSQL Extractor where
  toSQL :: Extractor -> Builder
toSQL (Extractor SQLExp
ce Maybe ColumnAlias
mal) =
    SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
ce Builder -> Builder -> Builder
<~> Builder -> (ColumnAlias -> Builder) -> Maybe ColumnAlias -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
"" ColumnAlias -> Builder
columnAliasToSqlWithAs Maybe ColumnAlias
mal

data DistinctExpr
  = DistinctSimple
  | DistinctOn [SQLExp]
  deriving (Int -> DistinctExpr -> ShowS
[DistinctExpr] -> ShowS
DistinctExpr -> String
(Int -> DistinctExpr -> ShowS)
-> (DistinctExpr -> String)
-> ([DistinctExpr] -> ShowS)
-> Show DistinctExpr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DistinctExpr -> ShowS
showsPrec :: Int -> DistinctExpr -> ShowS
$cshow :: DistinctExpr -> String
show :: DistinctExpr -> String
$cshowList :: [DistinctExpr] -> ShowS
showList :: [DistinctExpr] -> ShowS
Show, DistinctExpr -> DistinctExpr -> Bool
(DistinctExpr -> DistinctExpr -> Bool)
-> (DistinctExpr -> DistinctExpr -> Bool) -> Eq DistinctExpr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DistinctExpr -> DistinctExpr -> Bool
== :: DistinctExpr -> DistinctExpr -> Bool
$c/= :: DistinctExpr -> DistinctExpr -> Bool
/= :: DistinctExpr -> DistinctExpr -> Bool
Eq, (forall x. DistinctExpr -> Rep DistinctExpr x)
-> (forall x. Rep DistinctExpr x -> DistinctExpr)
-> Generic DistinctExpr
forall x. Rep DistinctExpr x -> DistinctExpr
forall x. DistinctExpr -> Rep DistinctExpr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DistinctExpr -> Rep DistinctExpr x
from :: forall x. DistinctExpr -> Rep DistinctExpr x
$cto :: forall x. Rep DistinctExpr x -> DistinctExpr
to :: forall x. Rep DistinctExpr x -> DistinctExpr
Generic, Typeable DistinctExpr
Typeable DistinctExpr
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> DistinctExpr -> c DistinctExpr)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c DistinctExpr)
-> (DistinctExpr -> Constr)
-> (DistinctExpr -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c DistinctExpr))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c DistinctExpr))
-> ((forall b. Data b => b -> b) -> DistinctExpr -> DistinctExpr)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> DistinctExpr -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> DistinctExpr -> r)
-> (forall u. (forall d. Data d => d -> u) -> DistinctExpr -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> DistinctExpr -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr)
-> Data DistinctExpr
DistinctExpr -> Constr
DistinctExpr -> DataType
(forall b. Data b => b -> b) -> DistinctExpr -> DistinctExpr
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> DistinctExpr -> u
forall u. (forall d. Data d => d -> u) -> DistinctExpr -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DistinctExpr -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DistinctExpr -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DistinctExpr
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DistinctExpr -> c DistinctExpr
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DistinctExpr)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DistinctExpr)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DistinctExpr -> c DistinctExpr
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DistinctExpr -> c DistinctExpr
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DistinctExpr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DistinctExpr
$ctoConstr :: DistinctExpr -> Constr
toConstr :: DistinctExpr -> Constr
$cdataTypeOf :: DistinctExpr -> DataType
dataTypeOf :: DistinctExpr -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DistinctExpr)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DistinctExpr)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DistinctExpr)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DistinctExpr)
$cgmapT :: (forall b. Data b => b -> b) -> DistinctExpr -> DistinctExpr
gmapT :: (forall b. Data b => b -> b) -> DistinctExpr -> DistinctExpr
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DistinctExpr -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DistinctExpr -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DistinctExpr -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DistinctExpr -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> DistinctExpr -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> DistinctExpr -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DistinctExpr -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DistinctExpr -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DistinctExpr -> m DistinctExpr
Data)

instance NFData DistinctExpr

instance Hashable DistinctExpr

instance ToSQL DistinctExpr where
  toSQL :: DistinctExpr -> Builder
toSQL DistinctExpr
DistinctSimple = Builder
"DISTINCT"
  toSQL (DistinctOn [SQLExp]
exprs) =
    Builder
"DISTINCT ON" Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (Text
"," Text -> [SQLExp] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [SQLExp]
exprs)

data FunctionArgs = FunctionArgs
  { FunctionArgs -> [SQLExp]
fasPostional :: [SQLExp],
    FunctionArgs -> HashMap Text SQLExp
fasNamed :: (HashMap.HashMap Text SQLExp)
  }
  deriving (Int -> FunctionArgs -> ShowS
[FunctionArgs] -> ShowS
FunctionArgs -> String
(Int -> FunctionArgs -> ShowS)
-> (FunctionArgs -> String)
-> ([FunctionArgs] -> ShowS)
-> Show FunctionArgs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FunctionArgs -> ShowS
showsPrec :: Int -> FunctionArgs -> ShowS
$cshow :: FunctionArgs -> String
show :: FunctionArgs -> String
$cshowList :: [FunctionArgs] -> ShowS
showList :: [FunctionArgs] -> ShowS
Show, FunctionArgs -> FunctionArgs -> Bool
(FunctionArgs -> FunctionArgs -> Bool)
-> (FunctionArgs -> FunctionArgs -> Bool) -> Eq FunctionArgs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FunctionArgs -> FunctionArgs -> Bool
== :: FunctionArgs -> FunctionArgs -> Bool
$c/= :: FunctionArgs -> FunctionArgs -> Bool
/= :: FunctionArgs -> FunctionArgs -> Bool
Eq, (forall x. FunctionArgs -> Rep FunctionArgs x)
-> (forall x. Rep FunctionArgs x -> FunctionArgs)
-> Generic FunctionArgs
forall x. Rep FunctionArgs x -> FunctionArgs
forall x. FunctionArgs -> Rep FunctionArgs x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FunctionArgs -> Rep FunctionArgs x
from :: forall x. FunctionArgs -> Rep FunctionArgs x
$cto :: forall x. Rep FunctionArgs x -> FunctionArgs
to :: forall x. Rep FunctionArgs x -> FunctionArgs
Generic, Typeable FunctionArgs
Typeable FunctionArgs
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> FunctionArgs -> c FunctionArgs)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c FunctionArgs)
-> (FunctionArgs -> Constr)
-> (FunctionArgs -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c FunctionArgs))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c FunctionArgs))
-> ((forall b. Data b => b -> b) -> FunctionArgs -> FunctionArgs)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> FunctionArgs -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> FunctionArgs -> r)
-> (forall u. (forall d. Data d => d -> u) -> FunctionArgs -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> FunctionArgs -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs)
-> Data FunctionArgs
FunctionArgs -> Constr
FunctionArgs -> DataType
(forall b. Data b => b -> b) -> FunctionArgs -> FunctionArgs
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FunctionArgs -> u
forall u. (forall d. Data d => d -> u) -> FunctionArgs -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionArgs -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionArgs -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionArgs
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FunctionArgs -> c FunctionArgs
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FunctionArgs)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionArgs)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FunctionArgs -> c FunctionArgs
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FunctionArgs -> c FunctionArgs
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionArgs
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionArgs
$ctoConstr :: FunctionArgs -> Constr
toConstr :: FunctionArgs -> Constr
$cdataTypeOf :: FunctionArgs -> DataType
dataTypeOf :: FunctionArgs -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FunctionArgs)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FunctionArgs)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionArgs)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionArgs)
$cgmapT :: (forall b. Data b => b -> b) -> FunctionArgs -> FunctionArgs
gmapT :: (forall b. Data b => b -> b) -> FunctionArgs -> FunctionArgs
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionArgs -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionArgs -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionArgs -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionArgs -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FunctionArgs -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> FunctionArgs -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FunctionArgs -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FunctionArgs -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionArgs -> m FunctionArgs
Data)

instance NFData FunctionArgs

instance Hashable FunctionArgs

instance ToSQL FunctionArgs where
  toSQL :: FunctionArgs -> Builder
toSQL (FunctionArgs [SQLExp]
positionalArgs HashMap Text SQLExp
namedArgsMap) =
    let namedArgs :: [SQLExp]
namedArgs = (((Text, SQLExp) -> SQLExp) -> [(Text, SQLExp)] -> [SQLExp])
-> [(Text, SQLExp)] -> ((Text, SQLExp) -> SQLExp) -> [SQLExp]
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Text, SQLExp) -> SQLExp) -> [(Text, SQLExp)] -> [SQLExp]
forall a b. (a -> b) -> [a] -> [b]
map (HashMap Text SQLExp -> [(Text, SQLExp)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList HashMap Text SQLExp
namedArgsMap)
          (((Text, SQLExp) -> SQLExp) -> [SQLExp])
-> ((Text, SQLExp) -> SQLExp) -> [SQLExp]
forall a b. (a -> b) -> a -> b
$ \(Text
argName, SQLExp
argVal) -> Identifier -> SQLExp -> SQLExp
SENamedArg (Text -> Identifier
Identifier Text
argName) SQLExp
argVal
     in Builder -> Builder
parenB (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$ Text
", " Text -> [SQLExp] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> ([SQLExp]
positionalArgs [SQLExp] -> [SQLExp] -> [SQLExp]
forall a. Semigroup a => a -> a -> a
<> [SQLExp]
namedArgs)

data FunctionDefinitionListItem = FunctionDefinitionListItem
  { FunctionDefinitionListItem -> ColumnAlias
_dliColumn :: ColumnAlias,
    FunctionDefinitionListItem -> PGScalarType
_dliType :: PGScalarType
  }
  deriving (Int -> FunctionDefinitionListItem -> ShowS
[FunctionDefinitionListItem] -> ShowS
FunctionDefinitionListItem -> String
(Int -> FunctionDefinitionListItem -> ShowS)
-> (FunctionDefinitionListItem -> String)
-> ([FunctionDefinitionListItem] -> ShowS)
-> Show FunctionDefinitionListItem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FunctionDefinitionListItem -> ShowS
showsPrec :: Int -> FunctionDefinitionListItem -> ShowS
$cshow :: FunctionDefinitionListItem -> String
show :: FunctionDefinitionListItem -> String
$cshowList :: [FunctionDefinitionListItem] -> ShowS
showList :: [FunctionDefinitionListItem] -> ShowS
Show, FunctionDefinitionListItem -> FunctionDefinitionListItem -> Bool
(FunctionDefinitionListItem -> FunctionDefinitionListItem -> Bool)
-> (FunctionDefinitionListItem
    -> FunctionDefinitionListItem -> Bool)
-> Eq FunctionDefinitionListItem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FunctionDefinitionListItem -> FunctionDefinitionListItem -> Bool
== :: FunctionDefinitionListItem -> FunctionDefinitionListItem -> Bool
$c/= :: FunctionDefinitionListItem -> FunctionDefinitionListItem -> Bool
/= :: FunctionDefinitionListItem -> FunctionDefinitionListItem -> Bool
Eq, Typeable FunctionDefinitionListItem
Typeable FunctionDefinitionListItem
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> FunctionDefinitionListItem
    -> c FunctionDefinitionListItem)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c FunctionDefinitionListItem)
-> (FunctionDefinitionListItem -> Constr)
-> (FunctionDefinitionListItem -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d))
    -> Maybe (c FunctionDefinitionListItem))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c FunctionDefinitionListItem))
-> ((forall b. Data b => b -> b)
    -> FunctionDefinitionListItem -> FunctionDefinitionListItem)
-> (forall r r'.
    (r -> r' -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> FunctionDefinitionListItem
    -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> FunctionDefinitionListItem
    -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> FunctionDefinitionListItem -> [u])
-> (forall u.
    Int
    -> (forall d. Data d => d -> u) -> FunctionDefinitionListItem -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> FunctionDefinitionListItem -> m FunctionDefinitionListItem)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> FunctionDefinitionListItem -> m FunctionDefinitionListItem)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> FunctionDefinitionListItem -> m FunctionDefinitionListItem)
-> Data FunctionDefinitionListItem
FunctionDefinitionListItem -> Constr
FunctionDefinitionListItem -> DataType
(forall b. Data b => b -> b)
-> FunctionDefinitionListItem -> FunctionDefinitionListItem
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int
-> (forall d. Data d => d -> u) -> FunctionDefinitionListItem -> u
forall u.
(forall d. Data d => d -> u) -> FunctionDefinitionListItem -> [u]
forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> FunctionDefinitionListItem
-> r
forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> FunctionDefinitionListItem
-> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> FunctionDefinitionListItem -> m FunctionDefinitionListItem
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> FunctionDefinitionListItem -> m FunctionDefinitionListItem
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionDefinitionListItem
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> FunctionDefinitionListItem
-> c FunctionDefinitionListItem
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c FunctionDefinitionListItem)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionDefinitionListItem)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> FunctionDefinitionListItem
-> c FunctionDefinitionListItem
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> FunctionDefinitionListItem
-> c FunctionDefinitionListItem
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionDefinitionListItem
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionDefinitionListItem
$ctoConstr :: FunctionDefinitionListItem -> Constr
toConstr :: FunctionDefinitionListItem -> Constr
$cdataTypeOf :: FunctionDefinitionListItem -> DataType
dataTypeOf :: FunctionDefinitionListItem -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c FunctionDefinitionListItem)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c FunctionDefinitionListItem)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionDefinitionListItem)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionDefinitionListItem)
$cgmapT :: (forall b. Data b => b -> b)
-> FunctionDefinitionListItem -> FunctionDefinitionListItem
gmapT :: (forall b. Data b => b -> b)
-> FunctionDefinitionListItem -> FunctionDefinitionListItem
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> FunctionDefinitionListItem
-> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> FunctionDefinitionListItem
-> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> FunctionDefinitionListItem
-> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> FunctionDefinitionListItem
-> r
$cgmapQ :: forall u.
(forall d. Data d => d -> u) -> FunctionDefinitionListItem -> [u]
gmapQ :: forall u.
(forall d. Data d => d -> u) -> FunctionDefinitionListItem -> [u]
$cgmapQi :: forall u.
Int
-> (forall d. Data d => d -> u) -> FunctionDefinitionListItem -> u
gmapQi :: forall u.
Int
-> (forall d. Data d => d -> u) -> FunctionDefinitionListItem -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> FunctionDefinitionListItem -> m FunctionDefinitionListItem
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> FunctionDefinitionListItem -> m FunctionDefinitionListItem
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> FunctionDefinitionListItem -> m FunctionDefinitionListItem
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> FunctionDefinitionListItem -> m FunctionDefinitionListItem
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> FunctionDefinitionListItem -> m FunctionDefinitionListItem
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> FunctionDefinitionListItem -> m FunctionDefinitionListItem
Data, (forall x.
 FunctionDefinitionListItem -> Rep FunctionDefinitionListItem x)
-> (forall x.
    Rep FunctionDefinitionListItem x -> FunctionDefinitionListItem)
-> Generic FunctionDefinitionListItem
forall x.
Rep FunctionDefinitionListItem x -> FunctionDefinitionListItem
forall x.
FunctionDefinitionListItem -> Rep FunctionDefinitionListItem x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
FunctionDefinitionListItem -> Rep FunctionDefinitionListItem x
from :: forall x.
FunctionDefinitionListItem -> Rep FunctionDefinitionListItem x
$cto :: forall x.
Rep FunctionDefinitionListItem x -> FunctionDefinitionListItem
to :: forall x.
Rep FunctionDefinitionListItem x -> FunctionDefinitionListItem
Generic)

instance NFData FunctionDefinitionListItem

instance Hashable FunctionDefinitionListItem

instance ToSQL FunctionDefinitionListItem where
  toSQL :: FunctionDefinitionListItem -> Builder
toSQL (FunctionDefinitionListItem ColumnAlias
column PGScalarType
columnType) =
    ColumnAlias -> Builder
columnAliasToSqlWithoutAs ColumnAlias
column Builder -> Builder -> Builder
<~> PGScalarType -> Builder
forall a. ToSQL a => a -> Builder
toSQL PGScalarType
columnType

-- | We can alias the result of a function call that returns a @SETOF RECORD@
--   by naming the result relation, and the columns and their types. For example:
--
-- > SELECT * FROM
-- > function_returns_record(arg1, arg2 ...) AS relation_name(column_1 column_1_type, column_2 column_2_type, ...)
--
--   Note: a function that returns a table (instead of a record) cannot name the types
--         as seen in the above example.
data FunctionAlias = FunctionAlias
  { FunctionAlias -> TableAlias
_faIdentifier :: TableAlias, -- TODO: Rename to _faAlias
    FunctionAlias -> Maybe [FunctionDefinitionListItem]
_faDefinitionList :: Maybe [FunctionDefinitionListItem]
  }
  deriving (Int -> FunctionAlias -> ShowS
[FunctionAlias] -> ShowS
FunctionAlias -> String
(Int -> FunctionAlias -> ShowS)
-> (FunctionAlias -> String)
-> ([FunctionAlias] -> ShowS)
-> Show FunctionAlias
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FunctionAlias -> ShowS
showsPrec :: Int -> FunctionAlias -> ShowS
$cshow :: FunctionAlias -> String
show :: FunctionAlias -> String
$cshowList :: [FunctionAlias] -> ShowS
showList :: [FunctionAlias] -> ShowS
Show, FunctionAlias -> FunctionAlias -> Bool
(FunctionAlias -> FunctionAlias -> Bool)
-> (FunctionAlias -> FunctionAlias -> Bool) -> Eq FunctionAlias
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FunctionAlias -> FunctionAlias -> Bool
== :: FunctionAlias -> FunctionAlias -> Bool
$c/= :: FunctionAlias -> FunctionAlias -> Bool
/= :: FunctionAlias -> FunctionAlias -> Bool
Eq, Typeable FunctionAlias
Typeable FunctionAlias
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> FunctionAlias -> c FunctionAlias)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c FunctionAlias)
-> (FunctionAlias -> Constr)
-> (FunctionAlias -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c FunctionAlias))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c FunctionAlias))
-> ((forall b. Data b => b -> b) -> FunctionAlias -> FunctionAlias)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> FunctionAlias -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> FunctionAlias -> r)
-> (forall u. (forall d. Data d => d -> u) -> FunctionAlias -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> FunctionAlias -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias)
-> Data FunctionAlias
FunctionAlias -> Constr
FunctionAlias -> DataType
(forall b. Data b => b -> b) -> FunctionAlias -> FunctionAlias
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FunctionAlias -> u
forall u. (forall d. Data d => d -> u) -> FunctionAlias -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionAlias -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionAlias -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionAlias
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FunctionAlias -> c FunctionAlias
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FunctionAlias)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionAlias)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FunctionAlias -> c FunctionAlias
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FunctionAlias -> c FunctionAlias
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionAlias
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionAlias
$ctoConstr :: FunctionAlias -> Constr
toConstr :: FunctionAlias -> Constr
$cdataTypeOf :: FunctionAlias -> DataType
dataTypeOf :: FunctionAlias -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FunctionAlias)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FunctionAlias)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionAlias)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionAlias)
$cgmapT :: (forall b. Data b => b -> b) -> FunctionAlias -> FunctionAlias
gmapT :: (forall b. Data b => b -> b) -> FunctionAlias -> FunctionAlias
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionAlias -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionAlias -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionAlias -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionAlias -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FunctionAlias -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> FunctionAlias -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FunctionAlias -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FunctionAlias -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionAlias -> m FunctionAlias
Data, (forall x. FunctionAlias -> Rep FunctionAlias x)
-> (forall x. Rep FunctionAlias x -> FunctionAlias)
-> Generic FunctionAlias
forall x. Rep FunctionAlias x -> FunctionAlias
forall x. FunctionAlias -> Rep FunctionAlias x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FunctionAlias -> Rep FunctionAlias x
from :: forall x. FunctionAlias -> Rep FunctionAlias x
$cto :: forall x. Rep FunctionAlias x -> FunctionAlias
to :: forall x. Rep FunctionAlias x -> FunctionAlias
Generic)

instance NFData FunctionAlias

instance Hashable FunctionAlias

functionNameToTableAlias :: QualifiedFunction -> TableAlias
functionNameToTableAlias :: QualifiedFunction -> TableAlias
functionNameToTableAlias = Text -> TableAlias
mkTableAlias (Text -> TableAlias)
-> (QualifiedFunction -> Text) -> QualifiedFunction -> TableAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QualifiedFunction -> Text
forall a. ToTxt a => QualifiedObject a -> Text
qualifiedObjectToText

-- | Construct a function alias which represents the "relation signature" for the function invocation,
--   Using the function name as the relation name, and the columns as the relation schema.
mkFunctionAlias :: QualifiedObject FunctionName -> Maybe [(ColumnAlias, PGScalarType)] -> FunctionAlias
mkFunctionAlias :: QualifiedFunction
-> Maybe [(ColumnAlias, PGScalarType)] -> FunctionAlias
mkFunctionAlias QualifiedFunction
alias Maybe [(ColumnAlias, PGScalarType)]
listM =
  TableAlias -> Maybe [FunctionDefinitionListItem] -> FunctionAlias
FunctionAlias (QualifiedFunction -> TableAlias
functionNameToTableAlias QualifiedFunction
alias)
    (Maybe [FunctionDefinitionListItem] -> FunctionAlias)
-> Maybe [FunctionDefinitionListItem] -> FunctionAlias
forall a b. (a -> b) -> a -> b
$ ([(ColumnAlias, PGScalarType)] -> [FunctionDefinitionListItem])
-> Maybe [(ColumnAlias, PGScalarType)]
-> Maybe [FunctionDefinitionListItem]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((ColumnAlias, PGScalarType) -> FunctionDefinitionListItem)
-> [(ColumnAlias, PGScalarType)] -> [FunctionDefinitionListItem]
forall a b. (a -> b) -> [a] -> [b]
map ((ColumnAlias -> PGScalarType -> FunctionDefinitionListItem)
-> (ColumnAlias, PGScalarType) -> FunctionDefinitionListItem
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ColumnAlias -> PGScalarType -> FunctionDefinitionListItem
FunctionDefinitionListItem)) Maybe [(ColumnAlias, PGScalarType)]
listM

instance ToSQL FunctionAlias where
  toSQL :: FunctionAlias -> Builder
toSQL (FunctionAlias TableAlias
tableAlias (Just [FunctionDefinitionListItem]
definitionList)) =
    TableAlias -> Builder
tableAliasToSqlWithAs TableAlias
tableAlias Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parenB (Text
", " Text -> [FunctionDefinitionListItem] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [FunctionDefinitionListItem]
definitionList)
  toSQL (FunctionAlias TableAlias
tableAlias Maybe [FunctionDefinitionListItem]
Nothing) =
    TableAlias -> Builder
tableAliasToSqlWithAs TableAlias
tableAlias

-- | A function call
data FunctionExp = FunctionExp
  { FunctionExp -> QualifiedFunction
feName :: QualifiedFunction,
    FunctionExp -> FunctionArgs
feArgs :: FunctionArgs,
    FunctionExp -> Maybe FunctionAlias
feAlias :: Maybe FunctionAlias
  }
  deriving (Int -> FunctionExp -> ShowS
[FunctionExp] -> ShowS
FunctionExp -> String
(Int -> FunctionExp -> ShowS)
-> (FunctionExp -> String)
-> ([FunctionExp] -> ShowS)
-> Show FunctionExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FunctionExp -> ShowS
showsPrec :: Int -> FunctionExp -> ShowS
$cshow :: FunctionExp -> String
show :: FunctionExp -> String
$cshowList :: [FunctionExp] -> ShowS
showList :: [FunctionExp] -> ShowS
Show, FunctionExp -> FunctionExp -> Bool
(FunctionExp -> FunctionExp -> Bool)
-> (FunctionExp -> FunctionExp -> Bool) -> Eq FunctionExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FunctionExp -> FunctionExp -> Bool
== :: FunctionExp -> FunctionExp -> Bool
$c/= :: FunctionExp -> FunctionExp -> Bool
/= :: FunctionExp -> FunctionExp -> Bool
Eq, (forall x. FunctionExp -> Rep FunctionExp x)
-> (forall x. Rep FunctionExp x -> FunctionExp)
-> Generic FunctionExp
forall x. Rep FunctionExp x -> FunctionExp
forall x. FunctionExp -> Rep FunctionExp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FunctionExp -> Rep FunctionExp x
from :: forall x. FunctionExp -> Rep FunctionExp x
$cto :: forall x. Rep FunctionExp x -> FunctionExp
to :: forall x. Rep FunctionExp x -> FunctionExp
Generic, Typeable FunctionExp
Typeable FunctionExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> FunctionExp -> c FunctionExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c FunctionExp)
-> (FunctionExp -> Constr)
-> (FunctionExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c FunctionExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c FunctionExp))
-> ((forall b. Data b => b -> b) -> FunctionExp -> FunctionExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> FunctionExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> FunctionExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> FunctionExp -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> FunctionExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp)
-> Data FunctionExp
FunctionExp -> Constr
FunctionExp -> DataType
(forall b. Data b => b -> b) -> FunctionExp -> FunctionExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FunctionExp -> u
forall u. (forall d. Data d => d -> u) -> FunctionExp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionExp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FunctionExp -> c FunctionExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FunctionExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FunctionExp -> c FunctionExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FunctionExp -> c FunctionExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FunctionExp
$ctoConstr :: FunctionExp -> Constr
toConstr :: FunctionExp -> Constr
$cdataTypeOf :: FunctionExp -> DataType
dataTypeOf :: FunctionExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FunctionExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FunctionExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FunctionExp)
$cgmapT :: (forall b. Data b => b -> b) -> FunctionExp -> FunctionExp
gmapT :: (forall b. Data b => b -> b) -> FunctionExp -> FunctionExp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionExp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionExp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FunctionExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FunctionExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> FunctionExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FunctionExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FunctionExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FunctionExp -> m FunctionExp
Data)

instance NFData FunctionExp

instance Hashable FunctionExp

instance ToSQL FunctionExp where
  toSQL :: FunctionExp -> Builder
toSQL (FunctionExp QualifiedFunction
qf FunctionArgs
args Maybe FunctionAlias
alsM) =
    QualifiedFunction -> Builder
forall a. ToSQL a => a -> Builder
toSQL QualifiedFunction
qf Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> FunctionArgs -> Builder
forall a. ToSQL a => a -> Builder
toSQL FunctionArgs
args Builder -> Builder -> Builder
<~> Maybe FunctionAlias -> Builder
forall a. ToSQL a => a -> Builder
toSQL Maybe FunctionAlias
alsM

-- | See @from_item@ in <https://www.postgresql.org/docs/current/sql-select.html>
data FromItem
  = -- | A simple table
    FISimple QualifiedTable (Maybe TableAlias)
  | -- | An identifier (from CTEs)
    FIIdentifier TableIdentifier
  | -- | A function call (that should return a relation (@SETOF@) and not a scalar)
    FIFunc FunctionExp
  | -- | @unnest@ converts (an) array(s) to a relation.
    --
    --   We have:
    --   * The unnest function arguments
    --   * The relation alias
    --   * A list of column aliases
    --
    --   See @unnest@ in <https://www.postgresql.org/docs/current/functions-array.html>.
    FIUnnest [SQLExp] TableAlias [ColumnAlias]
  | FISelect Lateral Select TableAlias
  | FISelectWith Lateral (SelectWithG Select) TableAlias
  | FIValues ValuesExp TableAlias (Maybe [ColumnAlias])
  | FIJoin JoinExpr
  deriving (Int -> FromItem -> ShowS
[FromItem] -> ShowS
FromItem -> String
(Int -> FromItem -> ShowS)
-> (FromItem -> String) -> ([FromItem] -> ShowS) -> Show FromItem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FromItem -> ShowS
showsPrec :: Int -> FromItem -> ShowS
$cshow :: FromItem -> String
show :: FromItem -> String
$cshowList :: [FromItem] -> ShowS
showList :: [FromItem] -> ShowS
Show, FromItem -> FromItem -> Bool
(FromItem -> FromItem -> Bool)
-> (FromItem -> FromItem -> Bool) -> Eq FromItem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FromItem -> FromItem -> Bool
== :: FromItem -> FromItem -> Bool
$c/= :: FromItem -> FromItem -> Bool
/= :: FromItem -> FromItem -> Bool
Eq, (forall x. FromItem -> Rep FromItem x)
-> (forall x. Rep FromItem x -> FromItem) -> Generic FromItem
forall x. Rep FromItem x -> FromItem
forall x. FromItem -> Rep FromItem x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FromItem -> Rep FromItem x
from :: forall x. FromItem -> Rep FromItem x
$cto :: forall x. Rep FromItem x -> FromItem
to :: forall x. Rep FromItem x -> FromItem
Generic, Typeable FromItem
Typeable FromItem
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> FromItem -> c FromItem)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c FromItem)
-> (FromItem -> Constr)
-> (FromItem -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c FromItem))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FromItem))
-> ((forall b. Data b => b -> b) -> FromItem -> FromItem)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> FromItem -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> FromItem -> r)
-> (forall u. (forall d. Data d => d -> u) -> FromItem -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> FromItem -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> FromItem -> m FromItem)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FromItem -> m FromItem)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FromItem -> m FromItem)
-> Data FromItem
FromItem -> Constr
FromItem -> DataType
(forall b. Data b => b -> b) -> FromItem -> FromItem
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FromItem -> u
forall u. (forall d. Data d => d -> u) -> FromItem -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FromItem -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FromItem -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FromItem -> m FromItem
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FromItem -> m FromItem
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FromItem
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromItem -> c FromItem
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FromItem)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FromItem)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromItem -> c FromItem
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromItem -> c FromItem
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FromItem
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FromItem
$ctoConstr :: FromItem -> Constr
toConstr :: FromItem -> Constr
$cdataTypeOf :: FromItem -> DataType
dataTypeOf :: FromItem -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FromItem)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FromItem)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FromItem)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FromItem)
$cgmapT :: (forall b. Data b => b -> b) -> FromItem -> FromItem
gmapT :: (forall b. Data b => b -> b) -> FromItem -> FromItem
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FromItem -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FromItem -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FromItem -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FromItem -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FromItem -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> FromItem -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FromItem -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FromItem -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FromItem -> m FromItem
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FromItem -> m FromItem
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FromItem -> m FromItem
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FromItem -> m FromItem
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FromItem -> m FromItem
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FromItem -> m FromItem
Data)

instance NFData FromItem

instance Hashable FromItem

mkSelFromItem :: Select -> TableAlias -> FromItem
mkSelFromItem :: Select -> TableAlias -> FromItem
mkSelFromItem = Lateral -> Select -> TableAlias -> FromItem
FISelect (Bool -> Lateral
Lateral Bool
False)

mkSelectWithFromItem :: SelectWithG Select -> TableAlias -> FromItem
mkSelectWithFromItem :: SelectWithG Select -> TableAlias -> FromItem
mkSelectWithFromItem = Lateral -> SelectWithG Select -> TableAlias -> FromItem
FISelectWith (Bool -> Lateral
Lateral Bool
False)

mkLateralFromItem :: Select -> TableAlias -> FromItem
mkLateralFromItem :: Select -> TableAlias -> FromItem
mkLateralFromItem = Lateral -> Select -> TableAlias -> FromItem
FISelect (Bool -> Lateral
Lateral Bool
True)

instance ToSQL FromItem where
  toSQL :: FromItem -> Builder
toSQL (FISimple QualifiedTable
qualifiedTable Maybe TableAlias
tableAlias) =
    QualifiedTable -> Builder
forall a. ToSQL a => a -> Builder
toSQL QualifiedTable
qualifiedTable Builder -> Builder -> Builder
<~> Builder -> (TableAlias -> Builder) -> Maybe TableAlias -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
"" TableAlias -> Builder
tableAliasToSqlWithAs Maybe TableAlias
tableAlias
  toSQL (FIIdentifier TableIdentifier
iden) =
    TableIdentifier -> Builder
forall a. ToSQL a => a -> Builder
toSQL TableIdentifier
iden
  toSQL (FIFunc FunctionExp
funcExp) = FunctionExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL FunctionExp
funcExp
  -- unnest(expressions) alias(columns)
  toSQL (FIUnnest [SQLExp]
args TableAlias
tableAlias [ColumnAlias]
cols) =
    Builder
"UNNEST"
      Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parenB (Text
", " Text -> [SQLExp] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [SQLExp]
args)
      Builder -> Builder -> Builder
<~> TableAlias -> Builder
tableAliasToSqlWithAs TableAlias
tableAlias
      Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parenB (Text
", " Text -> [Builder] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> (ColumnAlias -> Builder) -> [ColumnAlias] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map ColumnAlias -> Builder
columnAliasToSqlWithoutAs [ColumnAlias]
cols)
  toSQL (FISelect Lateral
isLateral Select
select TableAlias
alias) =
    Lateral -> Builder
forall a. ToSQL a => a -> Builder
toSQL Lateral
isLateral Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (Select -> Builder
forall a. ToSQL a => a -> Builder
toSQL Select
select) Builder -> Builder -> Builder
<~> TableAlias -> Builder
tableAliasToSqlWithAs TableAlias
alias
  toSQL (FISelectWith Lateral
isLateral SelectWithG Select
selectWith TableAlias
alias) =
    Lateral -> Builder
forall a. ToSQL a => a -> Builder
toSQL Lateral
isLateral Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (SelectWithG Select -> Builder
forall a. ToSQL a => a -> Builder
toSQL SelectWithG Select
selectWith) Builder -> Builder -> Builder
<~> TableAlias -> Builder
tableAliasToSqlWithAs TableAlias
alias
  toSQL (FIValues ValuesExp
valsExp TableAlias
alias Maybe [ColumnAlias]
columnAliases) =
    Builder -> Builder
parenB (ValuesExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL ValuesExp
valsExp)
      Builder -> Builder -> Builder
<~> TableAlias -> Builder
tableAliasToSqlWithAs TableAlias
alias
      Builder -> Builder -> Builder
<~> case Maybe [ColumnAlias]
columnAliases of
        Maybe [ColumnAlias]
Nothing -> Builder
""
        Just [ColumnAlias]
cols -> Builder -> Builder
parenB (Text
", " Text -> [Builder] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> (ColumnAlias -> Builder) -> [ColumnAlias] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map ColumnAlias -> Builder
columnAliasToSqlWithoutAs [ColumnAlias]
cols)
  toSQL (FIJoin JoinExpr
je) =
    JoinExpr -> Builder
forall a. ToSQL a => a -> Builder
toSQL JoinExpr
je

newtype Lateral = Lateral Bool
  deriving (Int -> Lateral -> ShowS
[Lateral] -> ShowS
Lateral -> String
(Int -> Lateral -> ShowS)
-> (Lateral -> String) -> ([Lateral] -> ShowS) -> Show Lateral
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Lateral -> ShowS
showsPrec :: Int -> Lateral -> ShowS
$cshow :: Lateral -> String
show :: Lateral -> String
$cshowList :: [Lateral] -> ShowS
showList :: [Lateral] -> ShowS
Show, Lateral -> Lateral -> Bool
(Lateral -> Lateral -> Bool)
-> (Lateral -> Lateral -> Bool) -> Eq Lateral
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Lateral -> Lateral -> Bool
== :: Lateral -> Lateral -> Bool
$c/= :: Lateral -> Lateral -> Bool
/= :: Lateral -> Lateral -> Bool
Eq, Typeable Lateral
Typeable Lateral
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Lateral -> c Lateral)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Lateral)
-> (Lateral -> Constr)
-> (Lateral -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Lateral))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Lateral))
-> ((forall b. Data b => b -> b) -> Lateral -> Lateral)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Lateral -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Lateral -> r)
-> (forall u. (forall d. Data d => d -> u) -> Lateral -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Lateral -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Lateral -> m Lateral)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Lateral -> m Lateral)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Lateral -> m Lateral)
-> Data Lateral
Lateral -> Constr
Lateral -> DataType
(forall b. Data b => b -> b) -> Lateral -> Lateral
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Lateral -> u
forall u. (forall d. Data d => d -> u) -> Lateral -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Lateral -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Lateral -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Lateral -> m Lateral
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Lateral -> m Lateral
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Lateral
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Lateral -> c Lateral
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Lateral)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Lateral)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Lateral -> c Lateral
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Lateral -> c Lateral
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Lateral
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Lateral
$ctoConstr :: Lateral -> Constr
toConstr :: Lateral -> Constr
$cdataTypeOf :: Lateral -> DataType
dataTypeOf :: Lateral -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Lateral)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Lateral)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Lateral)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Lateral)
$cgmapT :: (forall b. Data b => b -> b) -> Lateral -> Lateral
gmapT :: (forall b. Data b => b -> b) -> Lateral -> Lateral
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Lateral -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Lateral -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Lateral -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Lateral -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Lateral -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Lateral -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Lateral -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Lateral -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Lateral -> m Lateral
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Lateral -> m Lateral
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Lateral -> m Lateral
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Lateral -> m Lateral
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Lateral -> m Lateral
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Lateral -> m Lateral
Data, Lateral -> ()
(Lateral -> ()) -> NFData Lateral
forall a. (a -> ()) -> NFData a
$crnf :: Lateral -> ()
rnf :: Lateral -> ()
NFData, Eq Lateral
Eq Lateral
-> (Int -> Lateral -> Int) -> (Lateral -> Int) -> Hashable Lateral
Int -> Lateral -> Int
Lateral -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> Lateral -> Int
hashWithSalt :: Int -> Lateral -> Int
$chash :: Lateral -> Int
hash :: Lateral -> Int
Hashable)

instance ToSQL Lateral where
  toSQL :: Lateral -> Builder
toSQL (Lateral Bool
True) = Builder
"LATERAL"
  toSQL (Lateral Bool
False) = Builder
forall a. Monoid a => a
mempty

data JoinExpr = JoinExpr
  { JoinExpr -> FromItem
tjeLeft :: FromItem,
    JoinExpr -> JoinType
tjeType :: JoinType,
    JoinExpr -> FromItem
tjeRight :: FromItem,
    JoinExpr -> JoinCond
tjeJC :: JoinCond
  }
  deriving (Int -> JoinExpr -> ShowS
[JoinExpr] -> ShowS
JoinExpr -> String
(Int -> JoinExpr -> ShowS)
-> (JoinExpr -> String) -> ([JoinExpr] -> ShowS) -> Show JoinExpr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JoinExpr -> ShowS
showsPrec :: Int -> JoinExpr -> ShowS
$cshow :: JoinExpr -> String
show :: JoinExpr -> String
$cshowList :: [JoinExpr] -> ShowS
showList :: [JoinExpr] -> ShowS
Show, JoinExpr -> JoinExpr -> Bool
(JoinExpr -> JoinExpr -> Bool)
-> (JoinExpr -> JoinExpr -> Bool) -> Eq JoinExpr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JoinExpr -> JoinExpr -> Bool
== :: JoinExpr -> JoinExpr -> Bool
$c/= :: JoinExpr -> JoinExpr -> Bool
/= :: JoinExpr -> JoinExpr -> Bool
Eq, (forall x. JoinExpr -> Rep JoinExpr x)
-> (forall x. Rep JoinExpr x -> JoinExpr) -> Generic JoinExpr
forall x. Rep JoinExpr x -> JoinExpr
forall x. JoinExpr -> Rep JoinExpr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. JoinExpr -> Rep JoinExpr x
from :: forall x. JoinExpr -> Rep JoinExpr x
$cto :: forall x. Rep JoinExpr x -> JoinExpr
to :: forall x. Rep JoinExpr x -> JoinExpr
Generic, Typeable JoinExpr
Typeable JoinExpr
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> JoinExpr -> c JoinExpr)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c JoinExpr)
-> (JoinExpr -> Constr)
-> (JoinExpr -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c JoinExpr))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinExpr))
-> ((forall b. Data b => b -> b) -> JoinExpr -> JoinExpr)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> JoinExpr -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> JoinExpr -> r)
-> (forall u. (forall d. Data d => d -> u) -> JoinExpr -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> JoinExpr -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr)
-> Data JoinExpr
JoinExpr -> Constr
JoinExpr -> DataType
(forall b. Data b => b -> b) -> JoinExpr -> JoinExpr
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> JoinExpr -> u
forall u. (forall d. Data d => d -> u) -> JoinExpr -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> JoinExpr -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> JoinExpr -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c JoinExpr
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> JoinExpr -> c JoinExpr
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c JoinExpr)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinExpr)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> JoinExpr -> c JoinExpr
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> JoinExpr -> c JoinExpr
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c JoinExpr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c JoinExpr
$ctoConstr :: JoinExpr -> Constr
toConstr :: JoinExpr -> Constr
$cdataTypeOf :: JoinExpr -> DataType
dataTypeOf :: JoinExpr -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c JoinExpr)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c JoinExpr)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinExpr)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinExpr)
$cgmapT :: (forall b. Data b => b -> b) -> JoinExpr -> JoinExpr
gmapT :: (forall b. Data b => b -> b) -> JoinExpr -> JoinExpr
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> JoinExpr -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> JoinExpr -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> JoinExpr -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> JoinExpr -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> JoinExpr -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> JoinExpr -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> JoinExpr -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> JoinExpr -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinExpr -> m JoinExpr
Data)

instance NFData JoinExpr

instance Hashable JoinExpr

instance ToSQL JoinExpr where
  toSQL :: JoinExpr -> Builder
toSQL JoinExpr
je =
    FromItem -> Builder
forall a. ToSQL a => a -> Builder
toSQL (JoinExpr -> FromItem
tjeLeft JoinExpr
je)
      Builder -> Builder -> Builder
<~> JoinType -> Builder
forall a. ToSQL a => a -> Builder
toSQL (JoinExpr -> JoinType
tjeType JoinExpr
je)
      Builder -> Builder -> Builder
<~> FromItem -> Builder
forall a. ToSQL a => a -> Builder
toSQL (JoinExpr -> FromItem
tjeRight JoinExpr
je)
      Builder -> Builder -> Builder
<~> JoinCond -> Builder
forall a. ToSQL a => a -> Builder
toSQL (JoinExpr -> JoinCond
tjeJC JoinExpr
je)

data JoinType
  = Inner
  | LeftOuter
  | RightOuter
  | FullOuter
  deriving (JoinType -> JoinType -> Bool
(JoinType -> JoinType -> Bool)
-> (JoinType -> JoinType -> Bool) -> Eq JoinType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JoinType -> JoinType -> Bool
== :: JoinType -> JoinType -> Bool
$c/= :: JoinType -> JoinType -> Bool
/= :: JoinType -> JoinType -> Bool
Eq, Int -> JoinType -> ShowS
[JoinType] -> ShowS
JoinType -> String
(Int -> JoinType -> ShowS)
-> (JoinType -> String) -> ([JoinType] -> ShowS) -> Show JoinType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JoinType -> ShowS
showsPrec :: Int -> JoinType -> ShowS
$cshow :: JoinType -> String
show :: JoinType -> String
$cshowList :: [JoinType] -> ShowS
showList :: [JoinType] -> ShowS
Show, (forall x. JoinType -> Rep JoinType x)
-> (forall x. Rep JoinType x -> JoinType) -> Generic JoinType
forall x. Rep JoinType x -> JoinType
forall x. JoinType -> Rep JoinType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. JoinType -> Rep JoinType x
from :: forall x. JoinType -> Rep JoinType x
$cto :: forall x. Rep JoinType x -> JoinType
to :: forall x. Rep JoinType x -> JoinType
Generic, Typeable JoinType
Typeable JoinType
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> JoinType -> c JoinType)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c JoinType)
-> (JoinType -> Constr)
-> (JoinType -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c JoinType))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinType))
-> ((forall b. Data b => b -> b) -> JoinType -> JoinType)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> JoinType -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> JoinType -> r)
-> (forall u. (forall d. Data d => d -> u) -> JoinType -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> JoinType -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> JoinType -> m JoinType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> JoinType -> m JoinType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> JoinType -> m JoinType)
-> Data JoinType
JoinType -> Constr
JoinType -> DataType
(forall b. Data b => b -> b) -> JoinType -> JoinType
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> JoinType -> u
forall u. (forall d. Data d => d -> u) -> JoinType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> JoinType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> JoinType -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> JoinType -> m JoinType
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinType -> m JoinType
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c JoinType
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> JoinType -> c JoinType
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c JoinType)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinType)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> JoinType -> c JoinType
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> JoinType -> c JoinType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c JoinType
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c JoinType
$ctoConstr :: JoinType -> Constr
toConstr :: JoinType -> Constr
$cdataTypeOf :: JoinType -> DataType
dataTypeOf :: JoinType -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c JoinType)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c JoinType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinType)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinType)
$cgmapT :: (forall b. Data b => b -> b) -> JoinType -> JoinType
gmapT :: (forall b. Data b => b -> b) -> JoinType -> JoinType
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> JoinType -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> JoinType -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> JoinType -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> JoinType -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> JoinType -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> JoinType -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> JoinType -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> JoinType -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> JoinType -> m JoinType
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> JoinType -> m JoinType
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinType -> m JoinType
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinType -> m JoinType
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinType -> m JoinType
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinType -> m JoinType
Data)

instance NFData JoinType

instance Hashable JoinType

instance ToSQL JoinType where
  toSQL :: JoinType -> Builder
toSQL JoinType
Inner = Builder
"INNER JOIN"
  toSQL JoinType
LeftOuter = Builder
"LEFT OUTER JOIN"
  toSQL JoinType
RightOuter = Builder
"RIGHT OUTER JOIN"
  toSQL JoinType
FullOuter = Builder
"FULL OUTER JOIN"

data JoinCond
  = JoinOn BoolExp
  | JoinUsing [Identifier]
  deriving (Int -> JoinCond -> ShowS
[JoinCond] -> ShowS
JoinCond -> String
(Int -> JoinCond -> ShowS)
-> (JoinCond -> String) -> ([JoinCond] -> ShowS) -> Show JoinCond
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JoinCond -> ShowS
showsPrec :: Int -> JoinCond -> ShowS
$cshow :: JoinCond -> String
show :: JoinCond -> String
$cshowList :: [JoinCond] -> ShowS
showList :: [JoinCond] -> ShowS
Show, JoinCond -> JoinCond -> Bool
(JoinCond -> JoinCond -> Bool)
-> (JoinCond -> JoinCond -> Bool) -> Eq JoinCond
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JoinCond -> JoinCond -> Bool
== :: JoinCond -> JoinCond -> Bool
$c/= :: JoinCond -> JoinCond -> Bool
/= :: JoinCond -> JoinCond -> Bool
Eq, (forall x. JoinCond -> Rep JoinCond x)
-> (forall x. Rep JoinCond x -> JoinCond) -> Generic JoinCond
forall x. Rep JoinCond x -> JoinCond
forall x. JoinCond -> Rep JoinCond x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. JoinCond -> Rep JoinCond x
from :: forall x. JoinCond -> Rep JoinCond x
$cto :: forall x. Rep JoinCond x -> JoinCond
to :: forall x. Rep JoinCond x -> JoinCond
Generic, Typeable JoinCond
Typeable JoinCond
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> JoinCond -> c JoinCond)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c JoinCond)
-> (JoinCond -> Constr)
-> (JoinCond -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c JoinCond))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinCond))
-> ((forall b. Data b => b -> b) -> JoinCond -> JoinCond)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> JoinCond -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> JoinCond -> r)
-> (forall u. (forall d. Data d => d -> u) -> JoinCond -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> JoinCond -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> JoinCond -> m JoinCond)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> JoinCond -> m JoinCond)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> JoinCond -> m JoinCond)
-> Data JoinCond
JoinCond -> Constr
JoinCond -> DataType
(forall b. Data b => b -> b) -> JoinCond -> JoinCond
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> JoinCond -> u
forall u. (forall d. Data d => d -> u) -> JoinCond -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> JoinCond -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> JoinCond -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> JoinCond -> m JoinCond
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinCond -> m JoinCond
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c JoinCond
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> JoinCond -> c JoinCond
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c JoinCond)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinCond)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> JoinCond -> c JoinCond
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> JoinCond -> c JoinCond
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c JoinCond
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c JoinCond
$ctoConstr :: JoinCond -> Constr
toConstr :: JoinCond -> Constr
$cdataTypeOf :: JoinCond -> DataType
dataTypeOf :: JoinCond -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c JoinCond)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c JoinCond)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinCond)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JoinCond)
$cgmapT :: (forall b. Data b => b -> b) -> JoinCond -> JoinCond
gmapT :: (forall b. Data b => b -> b) -> JoinCond -> JoinCond
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> JoinCond -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> JoinCond -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> JoinCond -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> JoinCond -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> JoinCond -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> JoinCond -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> JoinCond -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> JoinCond -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> JoinCond -> m JoinCond
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> JoinCond -> m JoinCond
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinCond -> m JoinCond
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinCond -> m JoinCond
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinCond -> m JoinCond
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> JoinCond -> m JoinCond
Data)

instance NFData JoinCond

instance Hashable JoinCond

instance ToSQL JoinCond where
  toSQL :: JoinCond -> Builder
toSQL (JoinOn BoolExp
be) =
    Builder
"ON" Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (BoolExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL BoolExp
be)
  toSQL (JoinUsing [Identifier]
cols) =
    Builder
"USING" Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (Text
"," Text -> [Identifier] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [Identifier]
cols)

data BoolExp
  = BELit Bool
  | BEBin BinOp BoolExp BoolExp
  | BENot BoolExp
  | BECompare CompareOp SQLExp SQLExp
  | -- this is because l = (ANY (e)) is not valid
    -- i.e, (ANY(e)) is not same as ANY(e)
    BECompareAny CompareOp SQLExp SQLExp
  | BENull SQLExp
  | BENotNull SQLExp
  | BEExists Select
  | BEIN SQLExp [SQLExp]
  | BEExp SQLExp
  deriving (Int -> BoolExp -> ShowS
[BoolExp] -> ShowS
BoolExp -> String
(Int -> BoolExp -> ShowS)
-> (BoolExp -> String) -> ([BoolExp] -> ShowS) -> Show BoolExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BoolExp -> ShowS
showsPrec :: Int -> BoolExp -> ShowS
$cshow :: BoolExp -> String
show :: BoolExp -> String
$cshowList :: [BoolExp] -> ShowS
showList :: [BoolExp] -> ShowS
Show, BoolExp -> BoolExp -> Bool
(BoolExp -> BoolExp -> Bool)
-> (BoolExp -> BoolExp -> Bool) -> Eq BoolExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BoolExp -> BoolExp -> Bool
== :: BoolExp -> BoolExp -> Bool
$c/= :: BoolExp -> BoolExp -> Bool
/= :: BoolExp -> BoolExp -> Bool
Eq, (forall x. BoolExp -> Rep BoolExp x)
-> (forall x. Rep BoolExp x -> BoolExp) -> Generic BoolExp
forall x. Rep BoolExp x -> BoolExp
forall x. BoolExp -> Rep BoolExp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BoolExp -> Rep BoolExp x
from :: forall x. BoolExp -> Rep BoolExp x
$cto :: forall x. Rep BoolExp x -> BoolExp
to :: forall x. Rep BoolExp x -> BoolExp
Generic, Typeable BoolExp
Typeable BoolExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> BoolExp -> c BoolExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BoolExp)
-> (BoolExp -> Constr)
-> (BoolExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BoolExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BoolExp))
-> ((forall b. Data b => b -> b) -> BoolExp -> BoolExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BoolExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BoolExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> BoolExp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> BoolExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BoolExp -> m BoolExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BoolExp -> m BoolExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BoolExp -> m BoolExp)
-> Data BoolExp
BoolExp -> Constr
BoolExp -> DataType
(forall b. Data b => b -> b) -> BoolExp -> BoolExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BoolExp -> u
forall u. (forall d. Data d => d -> u) -> BoolExp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BoolExp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BoolExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BoolExp -> m BoolExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BoolExp -> m BoolExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BoolExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BoolExp -> c BoolExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BoolExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BoolExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BoolExp -> c BoolExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BoolExp -> c BoolExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BoolExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BoolExp
$ctoConstr :: BoolExp -> Constr
toConstr :: BoolExp -> Constr
$cdataTypeOf :: BoolExp -> DataType
dataTypeOf :: BoolExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BoolExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BoolExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BoolExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BoolExp)
$cgmapT :: (forall b. Data b => b -> b) -> BoolExp -> BoolExp
gmapT :: (forall b. Data b => b -> b) -> BoolExp -> BoolExp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BoolExp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BoolExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BoolExp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BoolExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BoolExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BoolExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BoolExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BoolExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BoolExp -> m BoolExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BoolExp -> m BoolExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BoolExp -> m BoolExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BoolExp -> m BoolExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BoolExp -> m BoolExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BoolExp -> m BoolExp
Data)

instance NFData BoolExp

instance Hashable BoolExp

-- removes extraneous 'AND true's
simplifyBoolExp :: BoolExp -> BoolExp
simplifyBoolExp :: BoolExp -> BoolExp
simplifyBoolExp BoolExp
be = case BoolExp
be of
  BEBin BinOp
AndOp BoolExp
e1 BoolExp
e2 ->
    let e1s :: BoolExp
e1s = BoolExp -> BoolExp
simplifyBoolExp BoolExp
e1
        e2s :: BoolExp
e2s = BoolExp -> BoolExp
simplifyBoolExp BoolExp
e2
     in if
          | BoolExp
e1s BoolExp -> BoolExp -> Bool
forall a. Eq a => a -> a -> Bool
== Bool -> BoolExp
BELit Bool
True -> BoolExp
e2s
          | BoolExp
e2s BoolExp -> BoolExp -> Bool
forall a. Eq a => a -> a -> Bool
== Bool -> BoolExp
BELit Bool
True -> BoolExp
e1s
          | Bool
otherwise -> BinOp -> BoolExp -> BoolExp -> BoolExp
BEBin BinOp
AndOp BoolExp
e1s BoolExp
e2s
  BEBin BinOp
OrOp BoolExp
e1 BoolExp
e2 ->
    let e1s :: BoolExp
e1s = BoolExp -> BoolExp
simplifyBoolExp BoolExp
e1
        e2s :: BoolExp
e2s = BoolExp -> BoolExp
simplifyBoolExp BoolExp
e2
     in if
          | BoolExp
e1s BoolExp -> BoolExp -> Bool
forall a. Eq a => a -> a -> Bool
== Bool -> BoolExp
BELit Bool
False -> BoolExp
e2s
          | BoolExp
e2s BoolExp -> BoolExp -> Bool
forall a. Eq a => a -> a -> Bool
== Bool -> BoolExp
BELit Bool
False -> BoolExp
e1s
          | Bool
otherwise -> BinOp -> BoolExp -> BoolExp -> BoolExp
BEBin BinOp
OrOp BoolExp
e1s BoolExp
e2s
  BoolExp
e -> BoolExp
e

mkExists :: FromItem -> BoolExp -> BoolExp
mkExists :: FromItem -> BoolExp -> BoolExp
mkExists FromItem
fromItem BoolExp
whereFrag =
  Select -> BoolExp
BEExists
    Select
mkSelect
      { selExtr :: [Extractor]
selExtr = [Extractor]
dummySelectList,
        selFrom :: Maybe FromExp
selFrom = FromExp -> Maybe FromExp
forall a. a -> Maybe a
Just (FromExp -> Maybe FromExp) -> FromExp -> Maybe FromExp
forall a b. (a -> b) -> a -> b
$ [FromItem] -> FromExp
FromExp ([FromItem] -> FromExp) -> [FromItem] -> FromExp
forall a b. (a -> b) -> a -> b
$ FromItem -> [FromItem]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure FromItem
fromItem,
        selWhere :: Maybe WhereFrag
selWhere = WhereFrag -> Maybe WhereFrag
forall a. a -> Maybe a
Just (WhereFrag -> Maybe WhereFrag) -> WhereFrag -> Maybe WhereFrag
forall a b. (a -> b) -> a -> b
$ BoolExp -> WhereFrag
WhereFrag BoolExp
whereFrag
      }

instance ToSQL BoolExp where
  toSQL :: BoolExp -> Builder
toSQL (BELit Bool
True) = Text -> Builder
TB.text Text
"'true'"
  toSQL (BELit Bool
False) = Text -> Builder
TB.text Text
"'false'"
  toSQL (BEBin BinOp
bo BoolExp
bel BoolExp
ber) =
    Builder -> Builder
parenB (BoolExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL BoolExp
bel) Builder -> Builder -> Builder
<~> BinOp -> Builder
forall a. ToSQL a => a -> Builder
toSQL BinOp
bo Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (BoolExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL BoolExp
ber)
  toSQL (BENot BoolExp
be) =
    Builder
"NOT" Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (BoolExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL BoolExp
be)
  toSQL (BECompare CompareOp
co SQLExp
vl SQLExp
vr) =
    Builder -> Builder
parenB (SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
vl) Builder -> Builder -> Builder
<~> CompareOp -> Builder
forall a. ToSQL a => a -> Builder
toSQL CompareOp
co Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
vr)
  toSQL (BECompareAny CompareOp
co SQLExp
vl SQLExp
vr) =
    Builder -> Builder
parenB (SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
vl) Builder -> Builder -> Builder
<~> CompareOp -> Builder
forall a. ToSQL a => a -> Builder
toSQL CompareOp
co Builder -> Builder -> Builder
<~> Builder
"ANY" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parenB (SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
vr)
  toSQL (BENull SQLExp
v) =
    Builder -> Builder
parenB (SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
v) Builder -> Builder -> Builder
<~> Builder
"IS NULL"
  toSQL (BENotNull SQLExp
v) =
    Builder -> Builder
parenB (SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
v) Builder -> Builder -> Builder
<~> Builder
"IS NOT NULL"
  toSQL (BEExists Select
sel) =
    Builder
"EXISTS " Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (Select -> Builder
forall a. ToSQL a => a -> Builder
toSQL Select
sel)
  -- special case to handle lhs IN (exp1, exp2)
  toSQL (BEIN SQLExp
vl [SQLExp]
exps) =
    Builder -> Builder
parenB (SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
vl) Builder -> Builder -> Builder
<~> CompareOp -> Builder
forall a. ToSQL a => a -> Builder
toSQL CompareOp
SIN Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (Text
", " Text -> [SQLExp] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [SQLExp]
exps)
  -- Any SQL expression which evaluates to bool value
  toSQL (BEExp SQLExp
e) = Builder -> Builder
parenB (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$ SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
e

data BinOp = AndOp | OrOp
  deriving (Int -> BinOp -> ShowS
[BinOp] -> ShowS
BinOp -> String
(Int -> BinOp -> ShowS)
-> (BinOp -> String) -> ([BinOp] -> ShowS) -> Show BinOp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BinOp -> ShowS
showsPrec :: Int -> BinOp -> ShowS
$cshow :: BinOp -> String
show :: BinOp -> String
$cshowList :: [BinOp] -> ShowS
showList :: [BinOp] -> ShowS
Show, BinOp -> BinOp -> Bool
(BinOp -> BinOp -> Bool) -> (BinOp -> BinOp -> Bool) -> Eq BinOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BinOp -> BinOp -> Bool
== :: BinOp -> BinOp -> Bool
$c/= :: BinOp -> BinOp -> Bool
/= :: BinOp -> BinOp -> Bool
Eq, (forall x. BinOp -> Rep BinOp x)
-> (forall x. Rep BinOp x -> BinOp) -> Generic BinOp
forall x. Rep BinOp x -> BinOp
forall x. BinOp -> Rep BinOp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BinOp -> Rep BinOp x
from :: forall x. BinOp -> Rep BinOp x
$cto :: forall x. Rep BinOp x -> BinOp
to :: forall x. Rep BinOp x -> BinOp
Generic, Typeable BinOp
Typeable BinOp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> BinOp -> c BinOp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BinOp)
-> (BinOp -> Constr)
-> (BinOp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BinOp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BinOp))
-> ((forall b. Data b => b -> b) -> BinOp -> BinOp)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BinOp -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BinOp -> r)
-> (forall u. (forall d. Data d => d -> u) -> BinOp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> BinOp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BinOp -> m BinOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BinOp -> m BinOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BinOp -> m BinOp)
-> Data BinOp
BinOp -> Constr
BinOp -> DataType
(forall b. Data b => b -> b) -> BinOp -> BinOp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BinOp -> u
forall u. (forall d. Data d => d -> u) -> BinOp -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BinOp -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BinOp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BinOp -> m BinOp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BinOp -> m BinOp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BinOp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BinOp -> c BinOp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BinOp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BinOp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BinOp -> c BinOp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BinOp -> c BinOp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BinOp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BinOp
$ctoConstr :: BinOp -> Constr
toConstr :: BinOp -> Constr
$cdataTypeOf :: BinOp -> DataType
dataTypeOf :: BinOp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BinOp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BinOp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BinOp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BinOp)
$cgmapT :: (forall b. Data b => b -> b) -> BinOp -> BinOp
gmapT :: (forall b. Data b => b -> b) -> BinOp -> BinOp
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BinOp -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BinOp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BinOp -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BinOp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BinOp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BinOp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BinOp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BinOp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BinOp -> m BinOp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BinOp -> m BinOp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BinOp -> m BinOp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BinOp -> m BinOp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BinOp -> m BinOp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BinOp -> m BinOp
Data)

instance NFData BinOp

instance Hashable BinOp

instance ToSQL BinOp where
  toSQL :: BinOp -> Builder
toSQL BinOp
AndOp = Builder
"AND"
  toSQL BinOp
OrOp = Builder
"OR"

data CompareOp
  = SEQ
  | SGT
  | SLT
  | SIN
  | SNE
  | SGTE
  | SLTE
  | SNIN
  | SLIKE
  | SNLIKE
  | SILIKE
  | SNILIKE
  | SSIMILAR
  | SNSIMILAR
  | SREGEX
  | SIREGEX
  | SNREGEX
  | SNIREGEX
  | SContains
  | SContainedIn
  | SHasKey
  | SHasKeysAny
  | SHasKeysAll
  | SMatchesFulltext
  deriving (CompareOp -> CompareOp -> Bool
(CompareOp -> CompareOp -> Bool)
-> (CompareOp -> CompareOp -> Bool) -> Eq CompareOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CompareOp -> CompareOp -> Bool
== :: CompareOp -> CompareOp -> Bool
$c/= :: CompareOp -> CompareOp -> Bool
/= :: CompareOp -> CompareOp -> Bool
Eq, (forall x. CompareOp -> Rep CompareOp x)
-> (forall x. Rep CompareOp x -> CompareOp) -> Generic CompareOp
forall x. Rep CompareOp x -> CompareOp
forall x. CompareOp -> Rep CompareOp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CompareOp -> Rep CompareOp x
from :: forall x. CompareOp -> Rep CompareOp x
$cto :: forall x. Rep CompareOp x -> CompareOp
to :: forall x. Rep CompareOp x -> CompareOp
Generic, Typeable CompareOp
Typeable CompareOp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CompareOp -> c CompareOp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CompareOp)
-> (CompareOp -> Constr)
-> (CompareOp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CompareOp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CompareOp))
-> ((forall b. Data b => b -> b) -> CompareOp -> CompareOp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CompareOp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CompareOp -> r)
-> (forall u. (forall d. Data d => d -> u) -> CompareOp -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> CompareOp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CompareOp -> m CompareOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CompareOp -> m CompareOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CompareOp -> m CompareOp)
-> Data CompareOp
CompareOp -> Constr
CompareOp -> DataType
(forall b. Data b => b -> b) -> CompareOp -> CompareOp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> CompareOp -> u
forall u. (forall d. Data d => d -> u) -> CompareOp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CompareOp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CompareOp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CompareOp -> m CompareOp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CompareOp -> m CompareOp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CompareOp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CompareOp -> c CompareOp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CompareOp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CompareOp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CompareOp -> c CompareOp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CompareOp -> c CompareOp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CompareOp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CompareOp
$ctoConstr :: CompareOp -> Constr
toConstr :: CompareOp -> Constr
$cdataTypeOf :: CompareOp -> DataType
dataTypeOf :: CompareOp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CompareOp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CompareOp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CompareOp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CompareOp)
$cgmapT :: (forall b. Data b => b -> b) -> CompareOp -> CompareOp
gmapT :: (forall b. Data b => b -> b) -> CompareOp -> CompareOp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CompareOp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CompareOp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CompareOp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CompareOp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CompareOp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> CompareOp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CompareOp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CompareOp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CompareOp -> m CompareOp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CompareOp -> m CompareOp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CompareOp -> m CompareOp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CompareOp -> m CompareOp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CompareOp -> m CompareOp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CompareOp -> m CompareOp
Data)

instance NFData CompareOp

instance Hashable CompareOp

instance Show CompareOp where
  show :: CompareOp -> String
show = \case
    CompareOp
SEQ -> String
"="
    CompareOp
SGT -> String
">"
    CompareOp
SLT -> String
"<"
    CompareOp
SIN -> String
"IN"
    CompareOp
SNE -> String
"<>"
    CompareOp
SGTE -> String
">="
    CompareOp
SLTE -> String
"<="
    CompareOp
SNIN -> String
"NOT IN"
    CompareOp
SLIKE -> String
"LIKE"
    CompareOp
SNLIKE -> String
"NOT LIKE"
    CompareOp
SILIKE -> String
"ILIKE"
    CompareOp
SNILIKE -> String
"NOT ILIKE"
    CompareOp
SSIMILAR -> String
"SIMILAR TO"
    CompareOp
SNSIMILAR -> String
"NOT SIMILAR TO"
    CompareOp
SREGEX -> String
"~"
    CompareOp
SIREGEX -> String
"~*"
    CompareOp
SNREGEX -> String
"!~"
    CompareOp
SNIREGEX -> String
"!~*"
    CompareOp
SContains -> String
"@>"
    CompareOp
SContainedIn -> String
"<@"
    CompareOp
SHasKey -> String
"?"
    CompareOp
SHasKeysAny -> String
"?|"
    CompareOp
SHasKeysAll -> String
"?&"
    CompareOp
SMatchesFulltext -> String
"@"

instance ToSQL CompareOp where
  toSQL :: CompareOp -> Builder
toSQL = String -> Builder
forall a. IsString a => String -> a
fromString (String -> Builder)
-> (CompareOp -> String) -> CompareOp -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CompareOp -> String
forall a. Show a => a -> String
show

data SQLDelete = SQLDelete
  { SQLDelete -> QualifiedTable
delTable :: QualifiedTable,
    SQLDelete -> Maybe UsingExp
delUsing :: Maybe UsingExp,
    SQLDelete -> Maybe WhereFrag
delWhere :: Maybe WhereFrag,
    SQLDelete -> Maybe RetExp
delRet :: Maybe RetExp
  }
  deriving (Int -> SQLDelete -> ShowS
[SQLDelete] -> ShowS
SQLDelete -> String
(Int -> SQLDelete -> ShowS)
-> (SQLDelete -> String)
-> ([SQLDelete] -> ShowS)
-> Show SQLDelete
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SQLDelete -> ShowS
showsPrec :: Int -> SQLDelete -> ShowS
$cshow :: SQLDelete -> String
show :: SQLDelete -> String
$cshowList :: [SQLDelete] -> ShowS
showList :: [SQLDelete] -> ShowS
Show, SQLDelete -> SQLDelete -> Bool
(SQLDelete -> SQLDelete -> Bool)
-> (SQLDelete -> SQLDelete -> Bool) -> Eq SQLDelete
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SQLDelete -> SQLDelete -> Bool
== :: SQLDelete -> SQLDelete -> Bool
$c/= :: SQLDelete -> SQLDelete -> Bool
/= :: SQLDelete -> SQLDelete -> Bool
Eq)

data SQLUpdate = SQLUpdate
  { SQLUpdate -> QualifiedTable
upTable :: QualifiedTable,
    SQLUpdate -> SetExp
upSet :: SetExp,
    SQLUpdate -> Maybe FromExp
upFrom :: Maybe FromExp,
    SQLUpdate -> Maybe WhereFrag
upWhere :: Maybe WhereFrag,
    SQLUpdate -> Maybe RetExp
upRet :: Maybe RetExp
  }
  deriving (Int -> SQLUpdate -> ShowS
[SQLUpdate] -> ShowS
SQLUpdate -> String
(Int -> SQLUpdate -> ShowS)
-> (SQLUpdate -> String)
-> ([SQLUpdate] -> ShowS)
-> Show SQLUpdate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SQLUpdate -> ShowS
showsPrec :: Int -> SQLUpdate -> ShowS
$cshow :: SQLUpdate -> String
show :: SQLUpdate -> String
$cshowList :: [SQLUpdate] -> ShowS
showList :: [SQLUpdate] -> ShowS
Show, SQLUpdate -> SQLUpdate -> Bool
(SQLUpdate -> SQLUpdate -> Bool)
-> (SQLUpdate -> SQLUpdate -> Bool) -> Eq SQLUpdate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SQLUpdate -> SQLUpdate -> Bool
== :: SQLUpdate -> SQLUpdate -> Bool
$c/= :: SQLUpdate -> SQLUpdate -> Bool
/= :: SQLUpdate -> SQLUpdate -> Bool
Eq)

newtype SetExp = SetExp [SetExpItem]
  deriving (Int -> SetExp -> ShowS
[SetExp] -> ShowS
SetExp -> String
(Int -> SetExp -> ShowS)
-> (SetExp -> String) -> ([SetExp] -> ShowS) -> Show SetExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetExp -> ShowS
showsPrec :: Int -> SetExp -> ShowS
$cshow :: SetExp -> String
show :: SetExp -> String
$cshowList :: [SetExp] -> ShowS
showList :: [SetExp] -> ShowS
Show, SetExp -> SetExp -> Bool
(SetExp -> SetExp -> Bool)
-> (SetExp -> SetExp -> Bool) -> Eq SetExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetExp -> SetExp -> Bool
== :: SetExp -> SetExp -> Bool
$c/= :: SetExp -> SetExp -> Bool
/= :: SetExp -> SetExp -> Bool
Eq)

newtype SetExpItem = SetExpItem (PGCol, SQLExp)
  deriving (Int -> SetExpItem -> ShowS
[SetExpItem] -> ShowS
SetExpItem -> String
(Int -> SetExpItem -> ShowS)
-> (SetExpItem -> String)
-> ([SetExpItem] -> ShowS)
-> Show SetExpItem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetExpItem -> ShowS
showsPrec :: Int -> SetExpItem -> ShowS
$cshow :: SetExpItem -> String
show :: SetExpItem -> String
$cshowList :: [SetExpItem] -> ShowS
showList :: [SetExpItem] -> ShowS
Show, SetExpItem -> SetExpItem -> Bool
(SetExpItem -> SetExpItem -> Bool)
-> (SetExpItem -> SetExpItem -> Bool) -> Eq SetExpItem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetExpItem -> SetExpItem -> Bool
== :: SetExpItem -> SetExpItem -> Bool
$c/= :: SetExpItem -> SetExpItem -> Bool
/= :: SetExpItem -> SetExpItem -> Bool
Eq)

buildUpsertSetExp ::
  [PGCol] ->
  HashMap.HashMap PGCol SQLExp ->
  SetExp
buildUpsertSetExp :: [PGCol] -> HashMap PGCol SQLExp -> SetExp
buildUpsertSetExp [PGCol]
cols HashMap PGCol SQLExp
preSet =
  [SetExpItem] -> SetExp
SetExp ([SetExpItem] -> SetExp) -> [SetExpItem] -> SetExp
forall a b. (a -> b) -> a -> b
$ ((PGCol, SQLExp) -> SetExpItem)
-> [(PGCol, SQLExp)] -> [SetExpItem]
forall a b. (a -> b) -> [a] -> [b]
map (PGCol, SQLExp) -> SetExpItem
SetExpItem ([(PGCol, SQLExp)] -> [SetExpItem])
-> [(PGCol, SQLExp)] -> [SetExpItem]
forall a b. (a -> b) -> a -> b
$ HashMap PGCol SQLExp -> [(PGCol, SQLExp)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList HashMap PGCol SQLExp
setExps
  where
    setExps :: HashMap PGCol SQLExp
setExps = HashMap PGCol SQLExp
-> HashMap PGCol SQLExp -> HashMap PGCol SQLExp
forall k v.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k v -> HashMap k v
HashMap.union HashMap PGCol SQLExp
preSet
      (HashMap PGCol SQLExp -> HashMap PGCol SQLExp)
-> HashMap PGCol SQLExp -> HashMap PGCol SQLExp
forall a b. (a -> b) -> a -> b
$ [(PGCol, SQLExp)] -> HashMap PGCol SQLExp
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
      ([(PGCol, SQLExp)] -> HashMap PGCol SQLExp)
-> [(PGCol, SQLExp)] -> HashMap PGCol SQLExp
forall a b. (a -> b) -> a -> b
$ ((PGCol -> (PGCol, SQLExp)) -> [PGCol] -> [(PGCol, SQLExp)])
-> [PGCol] -> (PGCol -> (PGCol, SQLExp)) -> [(PGCol, SQLExp)]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (PGCol -> (PGCol, SQLExp)) -> [PGCol] -> [(PGCol, SQLExp)]
forall a b. (a -> b) -> [a] -> [b]
map [PGCol]
cols
      ((PGCol -> (PGCol, SQLExp)) -> [(PGCol, SQLExp)])
-> (PGCol -> (PGCol, SQLExp)) -> [(PGCol, SQLExp)]
forall a b. (a -> b) -> a -> b
$ \PGCol
col ->
        (PGCol
col, Identifier -> SQLExp
SEExcluded (Identifier -> SQLExp) -> Identifier -> SQLExp
forall a b. (a -> b) -> a -> b
$ PGCol -> Identifier
forall a. IsIdentifier a => a -> Identifier
toIdentifier PGCol
col)

newtype UsingExp = UsingExp [TableName]
  deriving (Int -> UsingExp -> ShowS
[UsingExp] -> ShowS
UsingExp -> String
(Int -> UsingExp -> ShowS)
-> (UsingExp -> String) -> ([UsingExp] -> ShowS) -> Show UsingExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UsingExp -> ShowS
showsPrec :: Int -> UsingExp -> ShowS
$cshow :: UsingExp -> String
show :: UsingExp -> String
$cshowList :: [UsingExp] -> ShowS
showList :: [UsingExp] -> ShowS
Show, UsingExp -> UsingExp -> Bool
(UsingExp -> UsingExp -> Bool)
-> (UsingExp -> UsingExp -> Bool) -> Eq UsingExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UsingExp -> UsingExp -> Bool
== :: UsingExp -> UsingExp -> Bool
$c/= :: UsingExp -> UsingExp -> Bool
/= :: UsingExp -> UsingExp -> Bool
Eq)

instance ToSQL UsingExp where
  toSQL :: UsingExp -> Builder
toSQL (UsingExp [TableName]
tables) =
    Builder
"USING" Builder -> Builder -> Builder
<~> Text
"," Text -> [TableName] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [TableName]
tables

newtype RetExp = RetExp [Extractor]
  deriving (Int -> RetExp -> ShowS
[RetExp] -> ShowS
RetExp -> String
(Int -> RetExp -> ShowS)
-> (RetExp -> String) -> ([RetExp] -> ShowS) -> Show RetExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RetExp -> ShowS
showsPrec :: Int -> RetExp -> ShowS
$cshow :: RetExp -> String
show :: RetExp -> String
$cshowList :: [RetExp] -> ShowS
showList :: [RetExp] -> ShowS
Show, RetExp -> RetExp -> Bool
(RetExp -> RetExp -> Bool)
-> (RetExp -> RetExp -> Bool) -> Eq RetExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RetExp -> RetExp -> Bool
== :: RetExp -> RetExp -> Bool
$c/= :: RetExp -> RetExp -> Bool
/= :: RetExp -> RetExp -> Bool
Eq)

selectStar :: Extractor
selectStar :: Extractor
selectStar = SQLExp -> Maybe ColumnAlias -> Extractor
Extractor (Maybe Qual -> SQLExp
SEStar Maybe Qual
forall a. Maybe a
Nothing) Maybe ColumnAlias
forall a. Maybe a
Nothing

selectStar' :: Qual -> Extractor
selectStar' :: Qual -> Extractor
selectStar' Qual
q = SQLExp -> Maybe ColumnAlias -> Extractor
Extractor (Maybe Qual -> SQLExp
SEStar (Qual -> Maybe Qual
forall a. a -> Maybe a
Just Qual
q)) Maybe ColumnAlias
forall a. Maybe a
Nothing

returningStar :: RetExp
returningStar :: RetExp
returningStar = [Extractor] -> RetExp
RetExp [Extractor
selectStar]

instance ToSQL RetExp where
  toSQL :: RetExp -> Builder
toSQL (RetExp []) =
    Builder
forall a. Monoid a => a
mempty
  toSQL (RetExp [Extractor]
exps) =
    Builder
"RETURNING" Builder -> Builder -> Builder
<~> (Text
", " Text -> [Extractor] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [Extractor]
exps)

instance ToSQL SQLDelete where
  toSQL :: SQLDelete -> Builder
toSQL SQLDelete
sd =
    Builder
"DELETE FROM"
      Builder -> Builder -> Builder
<~> QualifiedTable -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLDelete -> QualifiedTable
delTable SQLDelete
sd)
      Builder -> Builder -> Builder
<~> Maybe UsingExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLDelete -> Maybe UsingExp
delUsing SQLDelete
sd)
      Builder -> Builder -> Builder
<~> Maybe WhereFrag -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLDelete -> Maybe WhereFrag
delWhere SQLDelete
sd)
      Builder -> Builder -> Builder
<~> Maybe RetExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLDelete -> Maybe RetExp
delRet SQLDelete
sd)

instance ToSQL SQLUpdate where
  toSQL :: SQLUpdate -> Builder
toSQL SQLUpdate
a =
    Builder
"UPDATE"
      Builder -> Builder -> Builder
<~> QualifiedTable -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLUpdate -> QualifiedTable
upTable SQLUpdate
a)
      Builder -> Builder -> Builder
<~> SetExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLUpdate -> SetExp
upSet SQLUpdate
a)
      Builder -> Builder -> Builder
<~> Maybe FromExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLUpdate -> Maybe FromExp
upFrom SQLUpdate
a)
      Builder -> Builder -> Builder
<~> Maybe WhereFrag -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLUpdate -> Maybe WhereFrag
upWhere SQLUpdate
a)
      Builder -> Builder -> Builder
<~> Maybe RetExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLUpdate -> Maybe RetExp
upRet SQLUpdate
a)

instance ToSQL SetExp where
  toSQL :: SetExp -> Builder
toSQL (SetExp [SetExpItem]
cvs) =
    Builder
"SET" Builder -> Builder -> Builder
<~> (Text
"," Text -> [SetExpItem] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [SetExpItem]
cvs)

instance ToSQL SetExpItem where
  toSQL :: SetExpItem -> Builder
toSQL (SetExpItem (PGCol
col, SQLExp
val)) =
    PGCol -> Builder
forall a. ToSQL a => a -> Builder
toSQL PGCol
col Builder -> Builder -> Builder
<~> Builder
"=" Builder -> Builder -> Builder
<~> SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
val

data SQLConflictTarget
  = SQLColumn [PGCol]
  | SQLConstraint ConstraintName
  deriving (Int -> SQLConflictTarget -> ShowS
[SQLConflictTarget] -> ShowS
SQLConflictTarget -> String
(Int -> SQLConflictTarget -> ShowS)
-> (SQLConflictTarget -> String)
-> ([SQLConflictTarget] -> ShowS)
-> Show SQLConflictTarget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SQLConflictTarget -> ShowS
showsPrec :: Int -> SQLConflictTarget -> ShowS
$cshow :: SQLConflictTarget -> String
show :: SQLConflictTarget -> String
$cshowList :: [SQLConflictTarget] -> ShowS
showList :: [SQLConflictTarget] -> ShowS
Show, SQLConflictTarget -> SQLConflictTarget -> Bool
(SQLConflictTarget -> SQLConflictTarget -> Bool)
-> (SQLConflictTarget -> SQLConflictTarget -> Bool)
-> Eq SQLConflictTarget
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SQLConflictTarget -> SQLConflictTarget -> Bool
== :: SQLConflictTarget -> SQLConflictTarget -> Bool
$c/= :: SQLConflictTarget -> SQLConflictTarget -> Bool
/= :: SQLConflictTarget -> SQLConflictTarget -> Bool
Eq)

instance ToSQL SQLConflictTarget where
  toSQL :: SQLConflictTarget -> Builder
toSQL (SQLColumn [PGCol]
cols) =
    Builder
"("
      Builder -> Builder -> Builder
<~> (Text
"," Text -> [PGCol] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [PGCol]
cols)
      Builder -> Builder -> Builder
<~> Builder
")"
  toSQL (SQLConstraint ConstraintName
cons) = Builder
"ON CONSTRAINT" Builder -> Builder -> Builder
<~> ConstraintName -> Builder
forall a. ToSQL a => a -> Builder
toSQL ConstraintName
cons

data SQLConflict
  = DoNothing (Maybe SQLConflictTarget)
  | Update SQLConflictTarget SetExp (Maybe WhereFrag)
  deriving (Int -> SQLConflict -> ShowS
[SQLConflict] -> ShowS
SQLConflict -> String
(Int -> SQLConflict -> ShowS)
-> (SQLConflict -> String)
-> ([SQLConflict] -> ShowS)
-> Show SQLConflict
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SQLConflict -> ShowS
showsPrec :: Int -> SQLConflict -> ShowS
$cshow :: SQLConflict -> String
show :: SQLConflict -> String
$cshowList :: [SQLConflict] -> ShowS
showList :: [SQLConflict] -> ShowS
Show, SQLConflict -> SQLConflict -> Bool
(SQLConflict -> SQLConflict -> Bool)
-> (SQLConflict -> SQLConflict -> Bool) -> Eq SQLConflict
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SQLConflict -> SQLConflict -> Bool
== :: SQLConflict -> SQLConflict -> Bool
$c/= :: SQLConflict -> SQLConflict -> Bool
/= :: SQLConflict -> SQLConflict -> Bool
Eq)

instance ToSQL SQLConflict where
  toSQL :: SQLConflict -> Builder
toSQL (DoNothing Maybe SQLConflictTarget
Nothing) = Builder
"ON CONFLICT DO NOTHING"
  toSQL (DoNothing (Just SQLConflictTarget
ct)) =
    Builder
"ON CONFLICT"
      Builder -> Builder -> Builder
<~> SQLConflictTarget -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLConflictTarget
ct
      Builder -> Builder -> Builder
<~> Builder
"DO NOTHING"
  toSQL (Update SQLConflictTarget
ct SetExp
set Maybe WhereFrag
whr) =
    Builder
"ON CONFLICT"
      Builder -> Builder -> Builder
<~> SQLConflictTarget -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLConflictTarget
ct
      Builder -> Builder -> Builder
<~> Builder
"DO UPDATE"
      Builder -> Builder -> Builder
<~> SetExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SetExp
set
      Builder -> Builder -> Builder
<~> Maybe WhereFrag -> Builder
forall a. ToSQL a => a -> Builder
toSQL Maybe WhereFrag
whr

newtype ValuesExp = ValuesExp {ValuesExp -> [TupleExp]
getValuesExp :: [TupleExp]}
  deriving (Int -> ValuesExp -> ShowS
[ValuesExp] -> ShowS
ValuesExp -> String
(Int -> ValuesExp -> ShowS)
-> (ValuesExp -> String)
-> ([ValuesExp] -> ShowS)
-> Show ValuesExp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ValuesExp -> ShowS
showsPrec :: Int -> ValuesExp -> ShowS
$cshow :: ValuesExp -> String
show :: ValuesExp -> String
$cshowList :: [ValuesExp] -> ShowS
showList :: [ValuesExp] -> ShowS
Show, ValuesExp -> ValuesExp -> Bool
(ValuesExp -> ValuesExp -> Bool)
-> (ValuesExp -> ValuesExp -> Bool) -> Eq ValuesExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ValuesExp -> ValuesExp -> Bool
== :: ValuesExp -> ValuesExp -> Bool
$c/= :: ValuesExp -> ValuesExp -> Bool
/= :: ValuesExp -> ValuesExp -> Bool
Eq, Typeable ValuesExp
Typeable ValuesExp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ValuesExp -> c ValuesExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ValuesExp)
-> (ValuesExp -> Constr)
-> (ValuesExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ValuesExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ValuesExp))
-> ((forall b. Data b => b -> b) -> ValuesExp -> ValuesExp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ValuesExp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ValuesExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> ValuesExp -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ValuesExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp)
-> Data ValuesExp
ValuesExp -> Constr
ValuesExp -> DataType
(forall b. Data b => b -> b) -> ValuesExp -> ValuesExp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ValuesExp -> u
forall u. (forall d. Data d => d -> u) -> ValuesExp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ValuesExp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ValuesExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ValuesExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ValuesExp -> c ValuesExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ValuesExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ValuesExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ValuesExp -> c ValuesExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ValuesExp -> c ValuesExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ValuesExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ValuesExp
$ctoConstr :: ValuesExp -> Constr
toConstr :: ValuesExp -> Constr
$cdataTypeOf :: ValuesExp -> DataType
dataTypeOf :: ValuesExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ValuesExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ValuesExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ValuesExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ValuesExp)
$cgmapT :: (forall b. Data b => b -> b) -> ValuesExp -> ValuesExp
gmapT :: (forall b. Data b => b -> b) -> ValuesExp -> ValuesExp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ValuesExp -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ValuesExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ValuesExp -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ValuesExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ValuesExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> ValuesExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ValuesExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ValuesExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ValuesExp -> m ValuesExp
Data, ValuesExp -> ()
(ValuesExp -> ()) -> NFData ValuesExp
forall a. (a -> ()) -> NFData a
$crnf :: ValuesExp -> ()
rnf :: ValuesExp -> ()
NFData, Eq ValuesExp
Eq ValuesExp
-> (Int -> ValuesExp -> Int)
-> (ValuesExp -> Int)
-> Hashable ValuesExp
Int -> ValuesExp -> Int
ValuesExp -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> ValuesExp -> Int
hashWithSalt :: Int -> ValuesExp -> Int
$chash :: ValuesExp -> Int
hash :: ValuesExp -> Int
Hashable)

instance ToSQL ValuesExp where
  toSQL :: ValuesExp -> Builder
toSQL (ValuesExp [TupleExp]
tuples) =
    Builder
"VALUES" Builder -> Builder -> Builder
<~> (Text
", " Text -> [TupleExp] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> [TupleExp]
tuples)

data SQLInsert = SQLInsert
  { SQLInsert -> QualifiedTable
siTable :: QualifiedTable,
    SQLInsert -> [PGCol]
siCols :: [PGCol],
    SQLInsert -> ValuesExp
siValues :: ValuesExp,
    SQLInsert -> Maybe SQLConflict
siConflict :: (Maybe SQLConflict),
    SQLInsert -> Maybe RetExp
siRet :: (Maybe RetExp)
  }
  deriving (Int -> SQLInsert -> ShowS
[SQLInsert] -> ShowS
SQLInsert -> String
(Int -> SQLInsert -> ShowS)
-> (SQLInsert -> String)
-> ([SQLInsert] -> ShowS)
-> Show SQLInsert
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SQLInsert -> ShowS
showsPrec :: Int -> SQLInsert -> ShowS
$cshow :: SQLInsert -> String
show :: SQLInsert -> String
$cshowList :: [SQLInsert] -> ShowS
showList :: [SQLInsert] -> ShowS
Show, SQLInsert -> SQLInsert -> Bool
(SQLInsert -> SQLInsert -> Bool)
-> (SQLInsert -> SQLInsert -> Bool) -> Eq SQLInsert
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SQLInsert -> SQLInsert -> Bool
== :: SQLInsert -> SQLInsert -> Bool
$c/= :: SQLInsert -> SQLInsert -> Bool
/= :: SQLInsert -> SQLInsert -> Bool
Eq)

instance ToSQL SQLInsert where
  toSQL :: SQLInsert -> Builder
toSQL SQLInsert
si =
    Builder
"INSERT INTO"
      Builder -> Builder -> Builder
<~> QualifiedTable -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLInsert -> QualifiedTable
siTable SQLInsert
si)
      Builder -> Builder -> Builder
<~> ( if [PGCol] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (SQLInsert -> [PGCol]
siCols SQLInsert
si)
              then
                Builder
"VALUES"
                  Builder -> Builder -> Builder
<~> Text
", "
                  Text -> [Builder] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> (TupleExp -> Builder) -> [TupleExp] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (Builder -> TupleExp -> Builder
forall a b. a -> b -> a
const (Builder
"(DEFAULT)" :: TB.Builder)) (ValuesExp -> [TupleExp]
getValuesExp (SQLInsert -> ValuesExp
siValues SQLInsert
si))
              else Builder
"(" Builder -> Builder -> Builder
<~> (Text
", " Text -> [PGCol] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> SQLInsert -> [PGCol]
siCols SQLInsert
si) Builder -> Builder -> Builder
<~> Builder
")" Builder -> Builder -> Builder
<~> ValuesExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLInsert -> ValuesExp
siValues SQLInsert
si)
          )
      Builder -> Builder -> Builder
<~> Builder -> (SQLConflict -> Builder) -> Maybe SQLConflict -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
"" SQLConflict -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLInsert -> Maybe SQLConflict
siConflict SQLInsert
si)
      Builder -> Builder -> Builder
<~> Maybe RetExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL (SQLInsert -> Maybe RetExp
siRet SQLInsert
si)

-- | Top-level Common Table Expression statement.
--
--   A top level CTE can be a query or a mutation statement.
--
--   Postgres supports mutations only in top-level CTEs.
--   See <https://www.postgresql.org/docs/current/queries-with.html#QUERIES-WITH-MODIFYING>
data TopLevelCTE
  = CTESelect Select
  | CTEInsert SQLInsert
  | CTEUpdate SQLUpdate
  | CTEDelete SQLDelete
  | CTEUnsafeRawSQL (InterpolatedQuery SQLExp)
  deriving (Int -> TopLevelCTE -> ShowS
[TopLevelCTE] -> ShowS
TopLevelCTE -> String
(Int -> TopLevelCTE -> ShowS)
-> (TopLevelCTE -> String)
-> ([TopLevelCTE] -> ShowS)
-> Show TopLevelCTE
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TopLevelCTE -> ShowS
showsPrec :: Int -> TopLevelCTE -> ShowS
$cshow :: TopLevelCTE -> String
show :: TopLevelCTE -> String
$cshowList :: [TopLevelCTE] -> ShowS
showList :: [TopLevelCTE] -> ShowS
Show, TopLevelCTE -> TopLevelCTE -> Bool
(TopLevelCTE -> TopLevelCTE -> Bool)
-> (TopLevelCTE -> TopLevelCTE -> Bool) -> Eq TopLevelCTE
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TopLevelCTE -> TopLevelCTE -> Bool
== :: TopLevelCTE -> TopLevelCTE -> Bool
$c/= :: TopLevelCTE -> TopLevelCTE -> Bool
/= :: TopLevelCTE -> TopLevelCTE -> Bool
Eq)

instance ToSQL TopLevelCTE where
  toSQL :: TopLevelCTE -> Builder
toSQL = \case
    CTESelect Select
q -> Select -> Builder
forall a. ToSQL a => a -> Builder
toSQL Select
q
    CTEInsert SQLInsert
q -> SQLInsert -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLInsert
q
    CTEUpdate SQLUpdate
q -> SQLUpdate -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLUpdate
q
    CTEDelete SQLDelete
q -> SQLDelete -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLDelete
q
    CTEUnsafeRawSQL (InterpolatedQuery [InterpolatedItem SQLExp]
parts) ->
      (InterpolatedItem SQLExp -> Builder)
-> [InterpolatedItem SQLExp] -> Builder
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap
        ( \case
            IIText Text
t -> Text -> Builder
TB.text Text
t
            IIVariable SQLExp
v -> SQLExp -> Builder
forall a. ToSQL a => a -> Builder
toSQL SQLExp
v
        )
        [InterpolatedItem SQLExp]
parts

-- | Represents a common table expresion that can be used in nested selects.
data InnerCTE
  = ICTESelect Select
  | ICTEUnsafeRawSQL (InterpolatedQuery SQLExp)
  deriving (Int -> InnerCTE -> ShowS
[InnerCTE] -> ShowS
InnerCTE -> String
(Int -> InnerCTE -> ShowS)
-> (InnerCTE -> String) -> ([InnerCTE] -> ShowS) -> Show InnerCTE
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InnerCTE -> ShowS
showsPrec :: Int -> InnerCTE -> ShowS
$cshow :: InnerCTE -> String
show :: InnerCTE -> String
$cshowList :: [InnerCTE] -> ShowS
showList :: [InnerCTE] -> ShowS
Show, InnerCTE -> InnerCTE -> Bool
(InnerCTE -> InnerCTE -> Bool)
-> (InnerCTE -> InnerCTE -> Bool) -> Eq InnerCTE
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InnerCTE -> InnerCTE -> Bool
== :: InnerCTE -> InnerCTE -> Bool
$c/= :: InnerCTE -> InnerCTE -> Bool
/= :: InnerCTE -> InnerCTE -> Bool
Eq, (forall x. InnerCTE -> Rep InnerCTE x)
-> (forall x. Rep InnerCTE x -> InnerCTE) -> Generic InnerCTE
forall x. Rep InnerCTE x -> InnerCTE
forall x. InnerCTE -> Rep InnerCTE x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. InnerCTE -> Rep InnerCTE x
from :: forall x. InnerCTE -> Rep InnerCTE x
$cto :: forall x. Rep InnerCTE x -> InnerCTE
to :: forall x. Rep InnerCTE x -> InnerCTE
Generic, Typeable InnerCTE
Typeable InnerCTE
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> InnerCTE -> c InnerCTE)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c InnerCTE)
-> (InnerCTE -> Constr)
-> (InnerCTE -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c InnerCTE))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c InnerCTE))
-> ((forall b. Data b => b -> b) -> InnerCTE -> InnerCTE)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> InnerCTE -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> InnerCTE -> r)
-> (forall u. (forall d. Data d => d -> u) -> InnerCTE -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> InnerCTE -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE)
-> Data InnerCTE
InnerCTE -> Constr
InnerCTE -> DataType
(forall b. Data b => b -> b) -> InnerCTE -> InnerCTE
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> InnerCTE -> u
forall u. (forall d. Data d => d -> u) -> InnerCTE -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> InnerCTE -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> InnerCTE -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c InnerCTE
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> InnerCTE -> c InnerCTE
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c InnerCTE)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c InnerCTE)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> InnerCTE -> c InnerCTE
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> InnerCTE -> c InnerCTE
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c InnerCTE
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c InnerCTE
$ctoConstr :: InnerCTE -> Constr
toConstr :: InnerCTE -> Constr
$cdataTypeOf :: InnerCTE -> DataType
dataTypeOf :: InnerCTE -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c InnerCTE)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c InnerCTE)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c InnerCTE)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c InnerCTE)
$cgmapT :: (forall b. Data b => b -> b) -> InnerCTE -> InnerCTE
gmapT :: (forall b. Data b => b -> b) -> InnerCTE -> InnerCTE
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> InnerCTE -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> InnerCTE -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> InnerCTE -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> InnerCTE -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> InnerCTE -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> InnerCTE -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> InnerCTE -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> InnerCTE -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> InnerCTE -> m InnerCTE
Data)

instance NFData InnerCTE

instance Hashable InnerCTE

toTopLevelCTE :: InnerCTE -> TopLevelCTE
toTopLevelCTE :: InnerCTE -> TopLevelCTE
toTopLevelCTE = \case
  ICTESelect Select
select -> Select -> TopLevelCTE
CTESelect Select
select
  ICTEUnsafeRawSQL InterpolatedQuery SQLExp
query -> InterpolatedQuery SQLExp -> TopLevelCTE
CTEUnsafeRawSQL InterpolatedQuery SQLExp
query

-- | A @SELECT@ statement with Common Table Expressions.
--   <https://www.postgresql.org/docs/current/queries-with.html>
--
--   These CTEs are determined by the @statement@ parameter.
--   Currently they are either 'TopLevelCTE', which allow for a query or mutation statement,
--   or 'Select', which only allow for querying results.
--
--   The distinction is required because Postgres only supports mutations in CTEs
--   at the top level.
--   See <https://www.postgresql.org/docs/current/queries-with.html#QUERIES-WITH-MODIFYING>
data SelectWithG statement = SelectWith
  { forall statement.
SelectWithG statement -> [(TableAlias, statement)]
swCTEs :: [(TableAlias, statement)],
    forall statement. SelectWithG statement -> Select
swSelect :: Select
  }
  deriving (Int -> SelectWithG statement -> ShowS
[SelectWithG statement] -> ShowS
SelectWithG statement -> String
(Int -> SelectWithG statement -> ShowS)
-> (SelectWithG statement -> String)
-> ([SelectWithG statement] -> ShowS)
-> Show (SelectWithG statement)
forall statement.
Show statement =>
Int -> SelectWithG statement -> ShowS
forall statement.
Show statement =>
[SelectWithG statement] -> ShowS
forall statement. Show statement => SelectWithG statement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall statement.
Show statement =>
Int -> SelectWithG statement -> ShowS
showsPrec :: Int -> SelectWithG statement -> ShowS
$cshow :: forall statement. Show statement => SelectWithG statement -> String
show :: SelectWithG statement -> String
$cshowList :: forall statement.
Show statement =>
[SelectWithG statement] -> ShowS
showList :: [SelectWithG statement] -> ShowS
Show, SelectWithG statement -> SelectWithG statement -> Bool
(SelectWithG statement -> SelectWithG statement -> Bool)
-> (SelectWithG statement -> SelectWithG statement -> Bool)
-> Eq (SelectWithG statement)
forall statement.
Eq statement =>
SelectWithG statement -> SelectWithG statement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall statement.
Eq statement =>
SelectWithG statement -> SelectWithG statement -> Bool
== :: SelectWithG statement -> SelectWithG statement -> Bool
$c/= :: forall statement.
Eq statement =>
SelectWithG statement -> SelectWithG statement -> Bool
/= :: SelectWithG statement -> SelectWithG statement -> Bool
Eq, (forall x. SelectWithG statement -> Rep (SelectWithG statement) x)
-> (forall x.
    Rep (SelectWithG statement) x -> SelectWithG statement)
-> Generic (SelectWithG statement)
forall x. Rep (SelectWithG statement) x -> SelectWithG statement
forall x. SelectWithG statement -> Rep (SelectWithG statement) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall statement x.
Rep (SelectWithG statement) x -> SelectWithG statement
forall statement x.
SelectWithG statement -> Rep (SelectWithG statement) x
$cfrom :: forall statement x.
SelectWithG statement -> Rep (SelectWithG statement) x
from :: forall x. SelectWithG statement -> Rep (SelectWithG statement) x
$cto :: forall statement x.
Rep (SelectWithG statement) x -> SelectWithG statement
to :: forall x. Rep (SelectWithG statement) x -> SelectWithG statement
Generic, Typeable (SelectWithG statement)
Typeable (SelectWithG statement)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> SelectWithG statement
    -> c (SelectWithG statement))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (SelectWithG statement))
-> (SelectWithG statement -> Constr)
-> (SelectWithG statement -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (SelectWithG statement)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (SelectWithG statement)))
-> ((forall b. Data b => b -> b)
    -> SelectWithG statement -> SelectWithG statement)
-> (forall r r'.
    (r -> r' -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> SelectWithG statement
    -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> SelectWithG statement
    -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> SelectWithG statement -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> SelectWithG statement -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> SelectWithG statement -> m (SelectWithG statement))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> SelectWithG statement -> m (SelectWithG statement))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> SelectWithG statement -> m (SelectWithG statement))
-> Data (SelectWithG statement)
SelectWithG statement -> Constr
SelectWithG statement -> DataType
(forall b. Data b => b -> b)
-> SelectWithG statement -> SelectWithG statement
forall {statement}.
Data statement =>
Typeable (SelectWithG statement)
forall statement. Data statement => SelectWithG statement -> Constr
forall statement.
Data statement =>
SelectWithG statement -> DataType
forall statement.
Data statement =>
(forall b. Data b => b -> b)
-> SelectWithG statement -> SelectWithG statement
forall statement u.
Data statement =>
Int -> (forall d. Data d => d -> u) -> SelectWithG statement -> u
forall statement u.
Data statement =>
(forall d. Data d => d -> u) -> SelectWithG statement -> [u]
forall statement r r'.
Data statement =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SelectWithG statement -> r
forall statement r r'.
Data statement =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SelectWithG statement -> r
forall statement (m :: * -> *).
(Data statement, Monad m) =>
(forall d. Data d => d -> m d)
-> SelectWithG statement -> m (SelectWithG statement)
forall statement (m :: * -> *).
(Data statement, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> SelectWithG statement -> m (SelectWithG statement)
forall statement (c :: * -> *).
Data statement =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (SelectWithG statement)
forall statement (c :: * -> *).
Data statement =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> SelectWithG statement
-> c (SelectWithG statement)
forall statement (t :: * -> *) (c :: * -> *).
(Data statement, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (SelectWithG statement))
forall statement (t :: * -> * -> *) (c :: * -> *).
(Data statement, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (SelectWithG statement))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> SelectWithG statement -> u
forall u.
(forall d. Data d => d -> u) -> SelectWithG statement -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SelectWithG statement -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SelectWithG statement -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> SelectWithG statement -> m (SelectWithG statement)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> SelectWithG statement -> m (SelectWithG statement)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (SelectWithG statement)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> SelectWithG statement
-> c (SelectWithG statement)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (SelectWithG statement))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (SelectWithG statement))
$cgfoldl :: forall statement (c :: * -> *).
Data statement =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> SelectWithG statement
-> c (SelectWithG statement)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> SelectWithG statement
-> c (SelectWithG statement)
$cgunfold :: forall statement (c :: * -> *).
Data statement =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (SelectWithG statement)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (SelectWithG statement)
$ctoConstr :: forall statement. Data statement => SelectWithG statement -> Constr
toConstr :: SelectWithG statement -> Constr
$cdataTypeOf :: forall statement.
Data statement =>
SelectWithG statement -> DataType
dataTypeOf :: SelectWithG statement -> DataType
$cdataCast1 :: forall statement (t :: * -> *) (c :: * -> *).
(Data statement, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (SelectWithG statement))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (SelectWithG statement))
$cdataCast2 :: forall statement (t :: * -> * -> *) (c :: * -> *).
(Data statement, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (SelectWithG statement))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (SelectWithG statement))
$cgmapT :: forall statement.
Data statement =>
(forall b. Data b => b -> b)
-> SelectWithG statement -> SelectWithG statement
gmapT :: (forall b. Data b => b -> b)
-> SelectWithG statement -> SelectWithG statement
$cgmapQl :: forall statement r r'.
Data statement =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SelectWithG statement -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SelectWithG statement -> r
$cgmapQr :: forall statement r r'.
Data statement =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SelectWithG statement -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SelectWithG statement -> r
$cgmapQ :: forall statement u.
Data statement =>
(forall d. Data d => d -> u) -> SelectWithG statement -> [u]
gmapQ :: forall u.
(forall d. Data d => d -> u) -> SelectWithG statement -> [u]
$cgmapQi :: forall statement u.
Data statement =>
Int -> (forall d. Data d => d -> u) -> SelectWithG statement -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> SelectWithG statement -> u
$cgmapM :: forall statement (m :: * -> *).
(Data statement, Monad m) =>
(forall d. Data d => d -> m d)
-> SelectWithG statement -> m (SelectWithG statement)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> SelectWithG statement -> m (SelectWithG statement)
$cgmapMp :: forall statement (m :: * -> *).
(Data statement, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> SelectWithG statement -> m (SelectWithG statement)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> SelectWithG statement -> m (SelectWithG statement)
$cgmapMo :: forall statement (m :: * -> *).
(Data statement, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> SelectWithG statement -> m (SelectWithG statement)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> SelectWithG statement -> m (SelectWithG statement)
Data)

instance (NFData v) => NFData (SelectWithG v)

instance (Hashable v) => Hashable (SelectWithG v)

instance (ToSQL v) => ToSQL (SelectWithG v) where
  toSQL :: SelectWithG v -> Builder
toSQL (SelectWith [] Select
sel) = Select -> Builder
forall a. ToSQL a => a -> Builder
toSQL Select
sel
  toSQL (SelectWith [(TableAlias, v)]
ctes Select
sel) =
    Builder
"WITH " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> (Text
", " Text -> [Builder] -> Builder
forall a. ToSQL a => Text -> [a] -> Builder
<+> ((TableAlias, v) -> Builder) -> [(TableAlias, v)] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (TableAlias, v) -> Builder
forall {a}. ToSQL a => (TableAlias, a) -> Builder
f [(TableAlias, v)]
ctes) Builder -> Builder -> Builder
<~> Select -> Builder
forall a. ToSQL a => a -> Builder
toSQL Select
sel
    where
      f :: (TableAlias, a) -> Builder
f (TableAlias
al, a
q) = TableAlias -> Builder
tableAliasToSqlWithoutAs TableAlias
al Builder -> Builder -> Builder
<~> Builder
"AS" Builder -> Builder -> Builder
<~> Builder -> Builder
parenB (a -> Builder
forall a. ToSQL a => a -> Builder
toSQL a
q)

-- | A top-level select with CTEs.
type SelectWith = SelectWithG TopLevelCTE

-- local helpers

infixr 6 <+>

(<+>) :: (ToSQL a) => Text -> [a] -> TB.Builder
<+> :: forall a. ToSQL a => Text -> [a] -> Builder
(<+>) Text
_ [] = Builder
forall a. Monoid a => a
mempty
(<+>) Text
kat (a
x : [a]
xs) =
  a -> Builder
forall a. ToSQL a => a -> Builder
toSQL a
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat [Text -> Builder
TB.text Text
kat Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> a -> Builder
forall a. ToSQL a => a -> Builder
toSQL a
x' | a
x' <- [a]
xs]
{-# INLINE (<+>) #-}