Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module defines translation functions for queries which select data.
Principally this includes translating the query
root field, but parts are
also reused for serving the responses for mutations.
Synopsis
- fromQueryRootField :: QueryDB 'MSSQL Void Expression -> FromIr Select
- fromSelect :: JsonAggSelect -> AnnSelectG 'MSSQL (AnnFieldG 'MSSQL Void) Expression -> FromIr Select
- fromSourceRelationship :: NonEmpty Object -> HashMap FieldName (ColumnName, ScalarType) -> FieldName -> (FieldName, SourceRelationshipSelection 'MSSQL Void (Const Expression)) -> FromIr Select
- fromRemoteRelationFieldsG :: Map TableName EntityAlias -> HashMap ColumnName ColumnName -> (FieldName, SourceRelationshipSelection 'MSSQL Void (Const Expression)) -> ReaderT EntityAlias FromIr FieldSource
- fromSelectRows :: AnnSelectG 'MSSQL (AnnFieldG 'MSSQL Void) Expression -> FromIr Select
- mkNodesSelect :: Args -> Where -> Expression -> Top -> From -> [(Int, (FieldName, [FieldSource]))] -> [(Int, Projection)]
- mkAggregateSelect :: Args -> Where -> Expression -> From -> [(Int, (FieldName, [Projection]))] -> [(Int, Projection)]
- fromSelectAggregate :: Maybe (EntityAlias, HashMap ColumnName ColumnName) -> AnnSelectG 'MSSQL (TableAggregateFieldG 'MSSQL Void) Expression -> FromIr Select
- data Args = Args {
- argsWhere :: Where
- argsOrderBy :: Maybe (NonEmpty OrderBy)
- argsJoins :: [Join]
- argsTop :: Top
- argsOffset :: Maybe Expression
- argsDistinct :: Proxy (Maybe (NonEmpty FieldName))
- argsExistingJoins :: Map TableName EntityAlias
- fromSelectArgsG :: SelectArgsG 'MSSQL Expression -> ReaderT EntityAlias FromIr Args
- fromQualifiedTable :: TableName -> FromIr From
- data FieldSource
- fromTableExpFieldG :: (Int, (FieldName, TableAggregateFieldG 'MSSQL Void Expression)) -> Maybe (ReaderT EntityAlias FromIr (Int, Projection))
- fromTableAggFieldG :: (Int, (FieldName, TableAggregateFieldG 'MSSQL Void Expression)) -> Maybe (Int, (FieldName, [Projection]))
- fromTableNodesFieldG :: Map TableName EntityAlias -> (Int, (FieldName, TableAggregateFieldG 'MSSQL Void Expression)) -> Maybe (ReaderT EntityAlias FromIr (Int, (FieldName, [FieldSource])))
- fromAggregateField :: Text -> AggregateField 'MSSQL -> Projection
- fromAnnFieldsG :: Map TableName EntityAlias -> (FieldName, AnnFieldG 'MSSQL Void Expression) -> ReaderT EntityAlias FromIr FieldSource
- fromAnnColumnField :: AnnColumnField 'MSSQL Expression -> ReaderT EntityAlias FromIr Expression
- fromColumn :: ColumnName -> ReaderT EntityAlias FromIr FieldName
- fieldSourceProjections :: FieldSource -> Projection
- joinAliasToField :: JoinAlias -> FieldName
- fieldSourceJoin :: FieldSource -> Maybe Join
- fromObjectRelationSelectG :: Map TableName EntityAlias -> ObjectRelationSelectG 'MSSQL Void Expression -> ReaderT EntityAlias FromIr Join
- lookupTableFrom :: Map TableName EntityAlias -> TableName -> FromIr (Either EntityAlias From)
- fromArraySelectG :: ArraySelectG 'MSSQL Void Expression -> ReaderT EntityAlias FromIr Join
- fromArrayAggregateSelectG :: AnnRelationSelectG 'MSSQL (AnnAggregateSelectG 'MSSQL Void Expression) -> ReaderT EntityAlias FromIr Join
- fromArrayRelationSelectG :: ArrayRelationSelectG 'MSSQL Void Expression -> ReaderT EntityAlias FromIr Join
- fromRelName :: RelName -> FromIr Text
- fromMapping :: From -> HashMap ColumnName ColumnName -> ReaderT EntityAlias FromIr [Expression]
- selectFromMapping :: Select -> HashMap ColumnName ColumnName -> ReaderT EntityAlias FromIr [Expression]
- safeJsonQueryExpression :: JsonCardinality -> Expression -> Expression
- data UnfurledJoin = UnfurledJoin {}
- fromAnnotatedOrderByItemG :: AnnotatedOrderByItemG 'MSSQL Expression -> WriterT (Seq UnfurledJoin) (ReaderT EntityAlias FromIr) OrderBy
- unfurlAnnotatedOrderByElement :: AnnotatedOrderByElement 'MSSQL Expression -> WriterT (Seq UnfurledJoin) (ReaderT EntityAlias FromIr) (FieldName, Maybe ScalarType)
- tableNameText :: TableName -> Text
- fromColumnInfo :: ColumnInfo 'MSSQL -> ReaderT EntityAlias FromIr FieldName
Documentation
fromQueryRootField :: QueryDB 'MSSQL Void Expression -> FromIr Select Source #
This is the top-level entry point for translation of Query root fields.
fromSelect :: JsonAggSelect -> AnnSelectG 'MSSQL (AnnFieldG 'MSSQL Void) Expression -> FromIr Select Source #
fromSourceRelationship Source #
:: NonEmpty Object | List of json objects, each of which becomes a row of the table |
-> HashMap FieldName (ColumnName, ScalarType) | The above objects have this schema |
-> FieldName | |
-> (FieldName, SourceRelationshipSelection 'MSSQL Void (Const Expression)) | |
-> FromIr Select |
Used in planSourceRelationship
, which is in
turn used by to implement mkDBRemoteRelationship
for BackendExecute
.
For more information, see the module/documentation of Source
.
fromRemoteRelationFieldsG :: Map TableName EntityAlias -> HashMap ColumnName ColumnName -> (FieldName, SourceRelationshipSelection 'MSSQL Void (Const Expression)) -> ReaderT EntityAlias FromIr FieldSource Source #
Build the FieldSource
for the relation field, depending on whether it's
an object, array, or aggregate relationship.
fromSelectRows :: AnnSelectG 'MSSQL (AnnFieldG 'MSSQL Void) Expression -> FromIr Select Source #
Toproot-level Select
. All descendentsub-translations are collected to produce a root TSQL.Select.
mkNodesSelect :: Args -> Where -> Expression -> Top -> From -> [(Int, (FieldName, [FieldSource]))] -> [(Int, Projection)] Source #
mkAggregateSelect :: Args -> Where -> Expression -> From -> [(Int, (FieldName, [Projection]))] -> [(Int, Projection)] Source #
fromSelectAggregate :: Maybe (EntityAlias, HashMap ColumnName ColumnName) -> AnnSelectG 'MSSQL (TableAggregateFieldG 'MSSQL Void) Expression -> FromIr Select Source #
Args | |
|
data FieldSource Source #
fromTableExpFieldG :: (Int, (FieldName, TableAggregateFieldG 'MSSQL Void Expression)) -> Maybe (ReaderT EntityAlias FromIr (Int, Projection)) Source #
Get FieldSource from a TAFExp type table aggregate field
fromTableAggFieldG :: (Int, (FieldName, TableAggregateFieldG 'MSSQL Void Expression)) -> Maybe (Int, (FieldName, [Projection])) Source #
fromTableNodesFieldG :: Map TableName EntityAlias -> (Int, (FieldName, TableAggregateFieldG 'MSSQL Void Expression)) -> Maybe (ReaderT EntityAlias FromIr (Int, (FieldName, [FieldSource]))) Source #
fromAggregateField :: Text -> AggregateField 'MSSQL -> Projection Source #
fromAnnFieldsG :: Map TableName EntityAlias -> (FieldName, AnnFieldG 'MSSQL Void Expression) -> ReaderT EntityAlias FromIr FieldSource Source #
The main sources of fields, either constants, fields or via joins.
fromAnnColumnField :: AnnColumnField 'MSSQL Expression -> ReaderT EntityAlias FromIr Expression Source #
Here is where we project a field as a column expression. If
number stringification is on, then we wrap it in a
ToStringExpression
so that it's casted when being projected.
fromColumn :: ColumnName -> ReaderT EntityAlias FromIr FieldName Source #
This is where a field name "foo" is resolved to a fully qualified field name [table].[foo]. The table name comes from EntityAlias in the ReaderT.
fieldSourceJoin :: FieldSource -> Maybe Join Source #
fromObjectRelationSelectG :: Map TableName EntityAlias -> ObjectRelationSelectG 'MSSQL Void Expression -> ReaderT EntityAlias FromIr Join Source #
lookupTableFrom :: Map TableName EntityAlias -> TableName -> FromIr (Either EntityAlias From) Source #
fromArrayAggregateSelectG :: AnnRelationSelectG 'MSSQL (AnnAggregateSelectG 'MSSQL Void Expression) -> ReaderT EntityAlias FromIr Join Source #
fromArrayRelationSelectG :: ArrayRelationSelectG 'MSSQL Void Expression -> ReaderT EntityAlias FromIr Join Source #
fromRelName :: RelName -> FromIr Text Source #
fromMapping :: From -> HashMap ColumnName ColumnName -> ReaderT EntityAlias FromIr [Expression] Source #
The context given by the reader is of the previous/parent
"remote" table. The WHERE that we're generating goes in the child,
"local" query. The From
passed in as argument is the local table.
We should hope to see e.g. "post.category = category.id" for a local table of post and a remote table of category.
The left/right columns in HashMap ColumnName ColumnName
corresponds
to the left/right of select ... join ...
. Therefore left=remote,
right=local in this context.
selectFromMapping :: Select -> HashMap ColumnName ColumnName -> ReaderT EntityAlias FromIr [Expression] Source #
safeJsonQueryExpression :: JsonCardinality -> Expression -> Expression Source #
A version of JSON_QUERY(..)
that returns a proper json literal, rather
than SQL null, which does not compose properly with FOR JSON
clauses.
data UnfurledJoin Source #
UnfurledJoin | |
|
fromAnnotatedOrderByItemG :: AnnotatedOrderByItemG 'MSSQL Expression -> WriterT (Seq UnfurledJoin) (ReaderT EntityAlias FromIr) OrderBy Source #
unfurlAnnotatedOrderByElement :: AnnotatedOrderByElement 'MSSQL Expression -> WriterT (Seq UnfurledJoin) (ReaderT EntityAlias FromIr) (FieldName, Maybe ScalarType) Source #
Unfurl the nested set of object relations (tell'd in the writer) that are terminated by field name (IR.AOCColumn and IR.AOCArrayAggregation).
tableNameText :: TableName -> Text Source #