2022-04-06 01:08:43 +03:00
|
|
|
module Hasura.Backends.Postgres.RQLGenerator.GenSelectArgsG
|
|
|
|
( genSelectArgsG,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.Int (Int64)
|
|
|
|
import Hasura.Backends.Postgres.RQLGenerator.GenAssociatedTypes
|
|
|
|
( genBooleanOperators,
|
|
|
|
genColumn,
|
2022-05-25 13:24:41 +03:00
|
|
|
genFunctionArgumentExp,
|
2022-04-06 01:08:43 +03:00
|
|
|
genFunctionName,
|
|
|
|
genScalarType,
|
|
|
|
genTableName,
|
|
|
|
genXComputedField,
|
|
|
|
)
|
|
|
|
import Hasura.Backends.Postgres.SQL.DML (NullsOrder (..), OrderType (..))
|
|
|
|
import Hasura.Generator.Common (defaultRange)
|
|
|
|
import Hasura.Prelude hiding (maybe, nonEmpty)
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.IR.BoolExp
|
2022-04-06 01:08:43 +03:00
|
|
|
import Hasura.RQL.IR.Generator
|
|
|
|
( genAnnBoolExp,
|
|
|
|
genAnnBoolExpFld,
|
|
|
|
genAnnotatedOrderByElement,
|
|
|
|
genAnnotatedOrderByItemG,
|
|
|
|
)
|
|
|
|
import Hasura.RQL.IR.Select (AnnotatedOrderByItemG, SelectArgsG (..))
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Backend
|
|
|
|
import Hasura.SQL.Backend
|
2022-04-06 01:08:43 +03:00
|
|
|
import Hedgehog (MonadGen)
|
|
|
|
import Hedgehog.Gen qualified as Gen
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Exported
|
|
|
|
|
|
|
|
genSelectArgsG :: forall m a. MonadGen m => m a -> m (SelectArgsG ('Postgres 'Vanilla) a)
|
|
|
|
genSelectArgsG genA = do
|
|
|
|
_saWhere <- where'
|
|
|
|
_saOrderBy <- orderBy
|
|
|
|
_saLimit <- limit
|
|
|
|
_saOffset <- offset
|
|
|
|
_saDistinct <- distinct
|
|
|
|
pure SelectArgs {..}
|
|
|
|
where
|
|
|
|
where' :: m (Maybe (AnnBoolExp ('Postgres 'Vanilla) a))
|
|
|
|
where' =
|
|
|
|
Gen.maybe $
|
|
|
|
genAnnBoolExp
|
|
|
|
( genAnnBoolExpFld
|
|
|
|
genColumn
|
|
|
|
genTableName
|
|
|
|
genScalarType
|
|
|
|
genFunctionName
|
|
|
|
genXComputedField
|
|
|
|
(genBooleanOperators genA)
|
2022-05-25 13:24:41 +03:00
|
|
|
(genFunctionArgumentExp genA)
|
2022-04-06 01:08:43 +03:00
|
|
|
genA
|
|
|
|
)
|
|
|
|
genTableName
|
|
|
|
|
|
|
|
orderBy :: m (Maybe (NonEmpty (AnnotatedOrderByItemG ('Postgres 'Vanilla) a)))
|
|
|
|
orderBy =
|
|
|
|
Gen.maybe . Gen.nonEmpty defaultRange $
|
|
|
|
genAnnotatedOrderByItemG @_ @('Postgres 'Vanilla)
|
|
|
|
genBasicOrderType
|
|
|
|
genNullsOrderType
|
|
|
|
( genAnnotatedOrderByElement @_ @('Postgres 'Vanilla)
|
|
|
|
genColumn
|
|
|
|
genTableName
|
|
|
|
genScalarType
|
|
|
|
genFunctionName
|
|
|
|
genXComputedField
|
|
|
|
(genBooleanOperators genA)
|
2022-05-25 13:24:41 +03:00
|
|
|
(genFunctionArgumentExp genA)
|
2022-04-06 01:08:43 +03:00
|
|
|
genA
|
|
|
|
)
|
|
|
|
|
|
|
|
limit :: m (Maybe Int)
|
|
|
|
limit = Gen.maybe $ Gen.integral defaultRange
|
|
|
|
|
|
|
|
offset :: m (Maybe Int64)
|
|
|
|
offset = Gen.maybe $ Gen.integral defaultRange
|
|
|
|
|
|
|
|
distinct :: m (Maybe (NonEmpty (Column ('Postgres 'Vanilla))))
|
|
|
|
distinct = Gen.maybe . Gen.nonEmpty defaultRange $ genColumn
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Unexported Helpers
|
|
|
|
|
|
|
|
genBasicOrderType :: MonadGen m => m (BasicOrderType ('Postgres 'Vanilla))
|
|
|
|
genBasicOrderType = Gen.element [OTAsc, OTDesc]
|
|
|
|
|
|
|
|
genNullsOrderType :: MonadGen m => m (NullsOrderType ('Postgres 'Vanilla))
|
|
|
|
genNullsOrderType = Gen.element [NFirst, NLast]
|