graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hasura.Backends.MSSQL.FromIr

Description

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

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

data FromIr a Source #

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 encounters Errors 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.

Instances

Instances details
Applicative FromIr Source # 
Instance details

Defined in Hasura.Backends.MSSQL.FromIr

Methods

pure :: a -> FromIr a #

(<*>) :: FromIr (a -> b) -> FromIr a -> FromIr b #

liftA2 :: (a -> b -> c) -> FromIr a -> FromIr b -> FromIr c #

(*>) :: FromIr a -> FromIr b -> FromIr b #

(<*) :: FromIr a -> FromIr b -> FromIr a #

Functor FromIr Source # 
Instance details

Defined in Hasura.Backends.MSSQL.FromIr

Methods

fmap :: (a -> b) -> FromIr a -> FromIr b #

(<$) :: a -> FromIr b -> FromIr a #

Monad FromIr Source # 
Instance details

Defined in Hasura.Backends.MSSQL.FromIr

Methods

(>>=) :: FromIr a -> (a -> FromIr b) -> FromIr b #

(>>) :: FromIr a -> FromIr b -> FromIr b #

return :: a -> FromIr a #

MonadValidate (NonEmpty Error) FromIr Source # 
Instance details

Defined in Hasura.Backends.MSSQL.FromIr

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.

data Error Source #

Errors that may happen during translation.

Instances

Instances details
Show Error Source # 
Instance details

Defined in Hasura.Backends.MSSQL.FromIr

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

Eq Error Source # 
Instance details

Defined in Hasura.Backends.MSSQL.FromIr

Methods

(==) :: Error -> Error -> Bool #

(/=) :: Error -> Error -> Bool #

MonadValidate (NonEmpty Error) FromIr Source # 
Instance details

Defined in Hasura.Backends.MSSQL.FromIr

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, and
  • occurrence is an integer counter that distinguishes each occurrence of type_name.

Example outputs:

do
  "ar_articles_1" <- generateAlias (ArrayRelationTemplate "articles")
  "ar_articles_2" <- generateAlias (ArrayRelationTemplate "articles")
  "t_users_1"     <- generateAlias (TableTemplate "users")