Safe Haskell | None |
---|---|
Language | Haskell2010 |
The modules in the Hasura.Backends.MSSQL.FromIr
namespace translates the
RQL IR into TSQL, the SQL dialect of MSSQL, as defined in abstract syntax in
Hasura.Backends.MSSQL.Types.
The translation happens in the FromIr
monad, which manages identifier
scoping and error collection.
The actual rendering of this AST into TSQL text happens in Hasura.Backends.MSSQL.ToQuery.
Synopsis
- newtype FromIr a = FromIr {}
- runFromIr :: MonadError QErr m => FromIr a -> m a
- data Error
- data NameTemplate
- = ArrayRelationTemplate Text
- | ArrayAggregateTemplate Text
- | ObjectRelationTemplate Text
- | TableTemplate Text
- | ForOrderAlias Text
- generateAlias :: NameTemplate -> FromIr Text
Documentation
The central Monad used throughout for all conversion functions.
It has the following features:
- It's a
MonadValidate
, so it'll continue going when it encountersError
s to accumulate as many as possible. - It has a facility for generating fresh, unique aliases, which lets the
translation output retain a resemblance with source names without the
translation process needing to be bothered about potential name shadowing.
See
generateAlias
.
runFromIr :: MonadError QErr m => FromIr a -> m a Source #
Run a FromIr
action, throwing errors that have been collected using the
supplied action.
Errors that may happen during translation.
data NameTemplate Source #
Hints about the type of entity that generateAlias
is producing an alias
for.
ArrayRelationTemplate Text | |
ArrayAggregateTemplate Text | |
ObjectRelationTemplate Text | |
TableTemplate Text | |
ForOrderAlias Text |
generateAlias :: NameTemplate -> FromIr Text Source #
Generate a fresh alias for a given entity to remove ambiguity and naming conflicts between scopes at the TSQL level.
Names are generated in the form type_name_occurrence
, where:
type
hints at the type of entity,name
refers to the source name being aliased, andoccurrence
is an integer counter that distinguishes each occurrence oftype_name
.
Example outputs:
do "ar_articles_1" <- generateAlias (ArrayRelationTemplate "articles") "ar_articles_2" <- generateAlias (ArrayRelationTemplate "articles") "t_users_1" <- generateAlias (TableTemplate "users")