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

Hasura.Backends.MSSQL.ToQuery

Description

MSSQL ToQuery

Convert the simple T-SQL AST to an SQL query, ready to be passed to the odbc package's query/exec functions.

We define a custom prettyprinter with the type Printer.

If you'd like to trace and see what a Printer looks like as SQL, you can use something like: > ltraceM "sql" (ODBC.renderQuery (toQueryPretty myPrinter))

Synopsis

Types

Instances

Printer generators

fromInsertValuesIntoTempTable :: InsertValuesIntoTempTable -> Printer Source #

Generate a statement to insert values into temporary table.

fromMerge :: Merge -> Printer Source #

Generate a MERGE SQL statement

fromDelete :: Delete -> Printer Source #

Generate a delete statement

Delete
  (Aliased (TableName "table" "schema") "alias")
  [ColumnName "id", ColumnName "name"]
  (Where [OpExpression EQ' (ValueExpression (IntValue 1)) (ValueExpression (IntValue 1))])

Becomes:

DELETE [alias] OUTPUT DELETED.[id], DELETED.[name] INTO #deleted([id], [name]) FROM [schema].[table] AS [alias] WHERE ((1) = (1))

fromUpdate :: Update -> Printer Source #

Generate an update statement

Update
   (Aliased (TableName "table" "schema") "alias")
   (fromList [(ColumnName "name", ValueExpression (TextValue "updated_name"))])
   (Output Inserted)
   (TempTable (TempTableName "updated") [ColumnName "id", ColumnName "name"])
   (Where [OpExpression EQ' (ColumnName "id") (ValueExpression (IntValue 1))])

Becomes:

UPDATE [alias] SET [alias].[name] = 'updated_name' OUTPUT INSERTED.[id], INSERTED.[name] INTO
#updated([id], [name]) FROM [schema].[table] AS [alias] WHERE (id = 1)

fromSelectIntoTempTable :: SelectIntoTempTable -> Printer Source #

Converts SelectIntoTempTable.

SelectIntoTempTable (TempTableName "deleted")  [UnifiedColumn "id" IntegerType, UnifiedColumn "name" TextType] (TableName "table" "schema")

Becomes:

SELECT [id], [name] INTO #deleted([id], [name]) FROM [schema].[table] WHERE (1<>1) UNION ALL SELECT [id], [name] FROM [schema].[table];

We add the `UNION ALL` part to avoid copying identity constraints, and we cast columns with types such as timestamp which are non-insertable to a different type.

dropTempTableQuery :: TempTableName -> Printer Source #

@TempTableName "temp_table" is converted to "DROP TABLE #temp_table"

Basic printing API

toQueryFlat :: Printer -> Query Source #

Pretty-prints a Printer as one line, converting NewlinePrinter to space.

toQueryPretty :: Printer -> Query Source #

Pretty-prints a Printer as multiple lines as defined by the printer.

Orphan instances