Safe Haskell | Safe-Inferred |
---|---|
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
- tellBefore :: TempTableDDL -> FromIr ()
- tellAfter :: TempTableDDL -> FromIr ()
- tellCTE :: NativeQueryName -> InterpolatedQuery Expression -> FromIr Text
- data FromIr a
- runFromIrUseCTEs :: MonadError QErr m => FromIr Select -> m (QueryWithDDL Select)
- runFromIrUseCTEsT :: (Traversable t, MonadError QErr m) => t (FromIr Select) -> m (t (QueryWithDDL Select))
- runFromIrErrorOnCTEs :: MonadError QErr m => FromIr a -> m (QueryWithDDL a)
- data Error
- data NameTemplate
- generateAlias :: NameTemplate -> FromIr Text
Documentation
tellBefore :: TempTableDDL -> FromIr () Source #
add a step to be run before the main query
tellAfter :: TempTableDDL -> FromIr () Source #
add a step to be run after the main query
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
. - It has a writer part for reporting native queries that need to be wrapped in a CTE
The Inner part FromIrInner
containing the state and validate are extracted to a different
type so we can peel the writer for queries and report errors in the process if needed.
runFromIrUseCTEs :: MonadError QErr m => FromIr Select -> m (QueryWithDDL Select) Source #
Run a FromIr
action, throwing errors that have been collected using the
supplied action, and attach CTEs created from native queries to the select query.
runFromIrUseCTEsT :: (Traversable t, MonadError QErr m) => t (FromIr Select) -> m (t (QueryWithDDL Select)) Source #
Run a FromIr
action, throwing errors that have been collected using the
supplied action, and attach CTEs created from native queries to the select query.
runFromIrErrorOnCTEs :: MonadError QErr m => FromIr a -> m (QueryWithDDL a) Source #
Run a FromIr
action, throwing errors that have been collected using the
supplied action, and discard CTEs created from native queries to the select query.
If CTEs were reported, we throw an error, since we don't support native queries in this context yet.
Errors that may happen during translation.
data NameTemplate Source #
Hints about the type of entity that generateAlias
is producing an alias
for.
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")