2022-03-16 07:12:15 +03:00
|
|
|
{-# LANGUAGE DeriveAnyClass #-}
|
2022-03-31 07:45:03 +03:00
|
|
|
{-# LANGUAGE OverloadedLists #-}
|
|
|
|
{-# LANGUAGE StandaloneDeriving #-}
|
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
2022-03-16 07:12:15 +03:00
|
|
|
|
|
|
|
--
|
2022-05-02 08:03:12 +03:00
|
|
|
module Hasura.Backends.DataConnector.API.V0.Expression
|
2022-03-16 07:12:15 +03:00
|
|
|
( Expression (..),
|
|
|
|
Operator (..),
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2022-03-31 07:45:03 +03:00
|
|
|
import Autodocodec.Extended
|
|
|
|
import Autodocodec.OpenAPI ()
|
2022-04-01 04:20:23 +03:00
|
|
|
import Control.DeepSeq (NFData)
|
2022-03-31 07:45:03 +03:00
|
|
|
import Control.Lens.TH (makePrisms)
|
2022-03-16 07:12:15 +03:00
|
|
|
import Data.Aeson (FromJSON, ToJSON)
|
2022-04-01 04:20:23 +03:00
|
|
|
import Data.Data (Data)
|
|
|
|
import Data.Hashable (Hashable)
|
2022-03-31 07:45:03 +03:00
|
|
|
import Data.OpenApi (ToSchema)
|
2022-04-01 04:20:23 +03:00
|
|
|
import GHC.Generics (Generic)
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0.Column qualified as API.V0
|
|
|
|
import Hasura.Backends.DataConnector.API.V0.Scalar.Value qualified as API.V0.Scalar
|
2022-04-01 04:20:23 +03:00
|
|
|
import Prelude
|
2022-03-16 07:12:15 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- | A serializable representation of query operators.
|
|
|
|
data Operator
|
|
|
|
= LessThan
|
|
|
|
| LessThanOrEqual
|
|
|
|
| GreaterThan
|
|
|
|
| GreaterThanOrEqual
|
2022-04-28 04:51:58 +03:00
|
|
|
| Equal
|
2022-03-31 07:45:03 +03:00
|
|
|
deriving stock (Data, Eq, Generic, Ord, Show, Enum, Bounded)
|
2022-04-01 04:20:23 +03:00
|
|
|
deriving anyclass (Hashable, NFData)
|
2022-03-31 07:45:03 +03:00
|
|
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec Operator
|
|
|
|
|
|
|
|
instance HasCodec Operator where
|
|
|
|
codec =
|
|
|
|
named "Operator" $
|
|
|
|
disjointStringConstCodec
|
|
|
|
[ (LessThan, "less_than"),
|
|
|
|
(LessThanOrEqual, "less_than_or_equal"),
|
|
|
|
(GreaterThan, "greater_than"),
|
2022-04-28 04:51:58 +03:00
|
|
|
(GreaterThanOrEqual, "greater_than_or_equal"),
|
|
|
|
(Equal, "equal")
|
2022-03-31 07:45:03 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- | A serializable representation of query expressions.
|
|
|
|
data Expression
|
|
|
|
= -- | A constant 'Scalar.Value'.
|
|
|
|
Literal (ValueWrapper "value" API.V0.Scalar.Value)
|
|
|
|
| In (ValueWrapper2 "expression" Expression "values" [API.V0.Scalar.Value])
|
|
|
|
| And (ValueWrapper "expressions" [Expression])
|
|
|
|
| Or (ValueWrapper "expressions" [Expression])
|
|
|
|
| Not (ValueWrapper "expression" Expression)
|
|
|
|
| IsNull (ValueWrapper "expression" Expression)
|
|
|
|
| Column (ValueWrapper "column" API.V0.ColumnName)
|
|
|
|
| ApplyOperator (ValueWrapper3 "operator" Operator "left" Expression "right" Expression)
|
2022-03-16 07:12:15 +03:00
|
|
|
deriving stock (Data, Eq, Generic, Ord, Show)
|
2022-04-01 04:20:23 +03:00
|
|
|
deriving anyclass (Hashable, NFData)
|
2022-03-31 07:45:03 +03:00
|
|
|
|
|
|
|
$(makePrisms ''Expression)
|
|
|
|
|
|
|
|
instance HasCodec Expression where
|
|
|
|
codec =
|
|
|
|
named "Expression" $
|
|
|
|
sumTypeCodec
|
|
|
|
[ TypeAlternative "LiteralExpression" "literal" _Literal,
|
|
|
|
TypeAlternative "InExpression" "in" _In,
|
|
|
|
TypeAlternative "AndExpression" "and" _And,
|
|
|
|
TypeAlternative "OrExpression" "or" _Or,
|
|
|
|
TypeAlternative "NotExpression" "not" _Not,
|
|
|
|
TypeAlternative "IsNullExpression" "is_null" _IsNull,
|
|
|
|
TypeAlternative "ColumnExpression" "column" _Column,
|
|
|
|
TypeAlternative "ApplyOperatorExpression" "op" _ApplyOperator
|
|
|
|
]
|
|
|
|
|
|
|
|
deriving via Autodocodec Expression instance FromJSON Expression
|
|
|
|
|
|
|
|
deriving via Autodocodec Expression instance ToJSON Expression
|
|
|
|
|
|
|
|
deriving via Autodocodec Expression instance ToSchema Expression
|