Safe Haskell | None |
---|---|
Language | Haskell2010 |
Translate from the DML to the MySQL dialect.
Synopsis
- data FieldSource
- data Error
- newtype FromIr a = FromIr {}
- runFromIr :: FromIr a -> Validate (NonEmpty Error) a
- data NameTemplate
- = ArrayRelationTemplate Text
- | ArrayAggregateTemplate Text
- | ObjectRelationTemplate Text
- | TableTemplate Text
- | ForOrderAlias Text
- | IndexTemplate
- generateEntityAlias :: NameTemplate -> FromIr Text
- fromQualifiedTable :: TableName -> FromIr From
- fromAlias :: From -> EntityAlias
- trueExpression :: Expression
- existsFieldName :: Text
- fromGExists :: GExists 'MySQL Expression -> ReaderT EntityAlias FromIr Select
- fromGBoolExp :: GBoolExp 'MySQL Expression -> ReaderT EntityAlias FromIr Expression
- fromAnnBoolExp :: GBoolExp 'MySQL (AnnBoolExpFld 'MySQL Expression) -> ReaderT EntityAlias FromIr Expression
- fromColumnInfoForBoolExp :: ColumnInfo 'MySQL -> ReaderT EntityAlias FromIr Expression
- fromAnnBoolExpFld :: AnnBoolExpFld 'MySQL Expression -> ReaderT EntityAlias FromIr Expression
- fromMapping :: From -> HashMap Column Column -> ReaderT EntityAlias FromIr [Expression]
- fromColumn :: Column -> ReaderT EntityAlias FromIr FieldName
- columnNameToFieldName :: Column -> EntityAlias -> FieldName
- fromOpExpG :: Expression -> OpExpG 'MySQL Expression -> FromIr Expression
- data Args = Args {
- argsWhere :: Where
- argsOrderBy :: Maybe (NonEmpty OrderBy)
- argsJoins :: [Join]
- argsTop :: Top
- argsOffset :: Maybe Int
- argsDistinct :: Proxy (Maybe (NonEmpty FieldName))
- argsExistingJoins :: Map TableName EntityAlias
- data UnfurledJoin = UnfurledJoin {}
- fromColumnInfo :: ColumnInfo 'MySQL -> ReaderT EntityAlias FromIr FieldName
- tableNameText :: TableName -> Text
- aggFieldName :: Text
- unfurlAnnOrderByElement :: AnnotatedOrderByElement 'MySQL Expression -> WriterT (Seq UnfurledJoin) (ReaderT EntityAlias FromIr) (FieldName, Maybe ScalarType)
- fromAnnOrderByItemG :: AnnotatedOrderByItemG 'MySQL Expression -> WriterT (Seq UnfurledJoin) (ReaderT EntityAlias FromIr) OrderBy
- fromSelectArgsG :: SelectArgsG 'MySQL Expression -> ReaderT EntityAlias FromIr Args
- fromAnnColumnField :: AnnColumnField 'MySQL Expression -> ReaderT EntityAlias FromIr Expression
- fromRelName :: RelName -> FromIr Text
- fromTableAggregateFieldG :: (FieldName, TableAggregateFieldG 'MySQL Void Expression) -> ReaderT EntityAlias FromIr FieldSource
- fieldSourceProjections :: FieldSource -> [Projection]
- fieldSourceJoin :: FieldSource -> Maybe Join
- fromSelectAggregate :: Maybe (EntityAlias, HashMap Column Column) -> AnnSelectG 'MySQL (TableAggregateFieldG 'MySQL Void) Expression -> FromIr Select
- fromArrayAggregateSelectG :: AnnRelationSelectG 'MySQL (AnnAggregateSelectG 'MySQL Void Expression) -> ReaderT EntityAlias FromIr Join
- fromArraySelectG :: ArraySelectG 'MySQL Void Expression -> ReaderT EntityAlias FromIr Join
- fromObjectRelationSelectG :: ObjectRelationSelectG 'MySQL Void Expression -> ReaderT EntityAlias FromIr Join
- isEmptyExpression :: Expression -> Bool
- fromSelectRows :: AnnSelectG 'MySQL (AnnFieldG 'MySQL Void) Expression -> FromIr Select
- fromArrayRelationSelectG :: ArrayRelationSelectG 'MySQL Void Expression -> ReaderT EntityAlias FromIr Join
- fromAnnFieldsG :: (FieldName, AnnFieldG 'MySQL Void Expression) -> ReaderT EntityAlias FromIr FieldSource
- mkSQLSelect :: JsonAggSelect -> AnnSelectG 'MySQL (AnnFieldG 'MySQL Void) Expression -> FromIr Select
- fromRootField :: QueryDB 'MySQL Void Expression -> FromIr Select
- fromMappingFieldNames :: EntityAlias -> HashMap Column Column -> ReaderT EntityAlias FromIr [(FieldName, FieldName)]
- fieldTextNames :: AnnFieldsG 'MySQL Void Expression -> [Text]
Documentation
data FieldSource Source #
Most of these errors should be checked for legitimacy.
UnsupportedOpExpG (OpExpG 'MySQL Expression) | |
IdentifierNotSupported | |
FunctionNotSupported | |
NodesUnsupportedForNow | |
ConnectionsNotSupported |
The base monad used throughout this module for all conversion functions.
It's a Validate, so it'll continue going when it encounters errors to accumulate as many as possible.
It also contains a mapping from entity prefixes to counters. So if my prefix is "table" then there'll be a counter that lets me generate table1, table2, etc. Same for any other prefix needed (e.g. names for joins).
A ReaderT is used around this in most of the module too, for
setting the current entity that a given field name refers to. See
fromColumn
.
data NameTemplate Source #
ArrayRelationTemplate Text | |
ArrayAggregateTemplate Text | |
ObjectRelationTemplate Text | |
TableTemplate Text | |
ForOrderAlias Text | |
IndexTemplate |
generateEntityAlias :: NameTemplate -> FromIr Text Source #
fromQualifiedTable :: TableName -> FromIr From Source #
This is really the start where you query the base table, everything else is joins attached to it.
fromAlias :: From -> EntityAlias Source #
existsFieldName :: Text Source #
fromAnnBoolExp :: GBoolExp 'MySQL (AnnBoolExpFld 'MySQL Expression) -> ReaderT EntityAlias FromIr Expression Source #
fromColumnInfoForBoolExp :: ColumnInfo 'MySQL -> ReaderT EntityAlias FromIr Expression Source #
For boolean operators, various comparison operators used need
special handling to ensure that SQL Server won't outright reject
the comparison. See also shouldCastToVarcharMax
.
fromAnnBoolExpFld :: AnnBoolExpFld 'MySQL Expression -> ReaderT EntityAlias FromIr Expression Source #
fromMapping :: From -> HashMap Column Column -> 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 Column Column
corresponds
to the left/right of select ... join ...
. Therefore left=remote,
right=local in this context.
columnNameToFieldName :: Column -> EntityAlias -> FieldName Source #
fromOpExpG :: Expression -> OpExpG 'MySQL Expression -> FromIr Expression Source #
Args | |
|
data UnfurledJoin Source #
UnfurledJoin | |
|
tableNameText :: TableName -> Text Source #
aggFieldName :: Text Source #
unfurlAnnOrderByElement :: AnnotatedOrderByElement 'MySQL 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).
fromAnnOrderByItemG :: AnnotatedOrderByItemG 'MySQL Expression -> WriterT (Seq UnfurledJoin) (ReaderT EntityAlias FromIr) OrderBy Source #
Produce a valid ORDER BY construct, telling about any joins needed on the side.
fromAnnColumnField :: AnnColumnField 'MySQL 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.
fromRelName :: RelName -> FromIr Text Source #
fromTableAggregateFieldG :: (FieldName, TableAggregateFieldG 'MySQL Void Expression) -> ReaderT EntityAlias FromIr FieldSource Source #
fieldSourceJoin :: FieldSource -> Maybe Join Source #
fromSelectAggregate :: Maybe (EntityAlias, HashMap Column Column) -> AnnSelectG 'MySQL (TableAggregateFieldG 'MySQL Void) Expression -> FromIr Select Source #
fromArrayAggregateSelectG :: AnnRelationSelectG 'MySQL (AnnAggregateSelectG 'MySQL Void Expression) -> ReaderT EntityAlias FromIr Join Source #
fromObjectRelationSelectG :: ObjectRelationSelectG 'MySQL Void Expression -> ReaderT EntityAlias FromIr Join Source #
isEmptyExpression :: Expression -> Bool Source #
fromSelectRows :: AnnSelectG 'MySQL (AnnFieldG 'MySQL Void) Expression -> FromIr Select Source #
fromArrayRelationSelectG :: ArrayRelationSelectG 'MySQL Void Expression -> ReaderT EntityAlias FromIr Join Source #
fromAnnFieldsG :: (FieldName, AnnFieldG 'MySQL Void Expression) -> ReaderT EntityAlias FromIr FieldSource Source #
The main sources of fields, either constants, fields or via joins.
mkSQLSelect :: JsonAggSelect -> AnnSelectG 'MySQL (AnnFieldG 'MySQL Void) Expression -> FromIr Select Source #
fromRootField :: QueryDB 'MySQL Void Expression -> FromIr Select Source #
Convert from the IR database query into a select.
fromMappingFieldNames :: EntityAlias -> HashMap Column Column -> ReaderT EntityAlias FromIr [(FieldName, FieldName)] Source #
fieldTextNames :: AnnFieldsG 'MySQL Void Expression -> [Text] Source #