| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hasura.Backends.MSSQL.FromIr.Insert
Description
This module defines the translation functions for insert and upsert mutations.
Synopsis
- fromInsert :: AnnotatedInsert 'MSSQL Void Expression -> Insert
- normalizeInsertRows :: HashMap (Column 'MSSQL) Expression -> [AnnotatedInsertRow 'MSSQL Expression] -> (HashSet (Column 'MSSQL), [HashMap (Column 'MSSQL) Expression])
- toMerge :: TableName -> [AnnotatedInsertRow 'MSSQL Expression] -> [ColumnInfo 'MSSQL] -> IfMatched Expression -> FromIr Merge
- toInsertValuesIntoTempTable :: TempTableName -> AnnotatedInsert 'MSSQL Void Expression -> InsertValuesIntoTempTable
Documentation
normalizeInsertRows :: HashMap (Column 'MSSQL) Expression -> [AnnotatedInsertRow 'MSSQL Expression] -> (HashSet (Column 'MSSQL), [HashMap (Column 'MSSQL) Expression]) Source #
Normalize a row by adding missing columns with DEFAULT value and sort by
column name to make sure all rows are consistent in column values and order.
Example: A table "author" is defined as:
CREATE TABLE author ([id] INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL, age INTEGER)
Consider the following mutation:
mutation {
insert_author(
objects: [{id: 1, name: "Foo", age: 21}, {id: 2, name: "Bar"}]
){
affected_rows
}
}We consider DEFAULT value for age column which is missing in second
insert row.
The corresponding INSERT statement looks like:
INSERT INTO author (id, name, age) OUTPUT INSERTED.id VALUES (1, 'Foo', 21), (2, 'Bar', DEFAULT)
toMerge :: TableName -> [AnnotatedInsertRow 'MSSQL Expression] -> [ColumnInfo 'MSSQL] -> IfMatched Expression -> FromIr Merge Source #
Construct a MERGE statement from AnnotatedInsert information. A MERGE statement is responsible for actually inserting and/or updating the data in the table.
toInsertValuesIntoTempTable :: TempTableName -> AnnotatedInsert 'MSSQL Void Expression -> InsertValuesIntoTempTable Source #
As part of an INSERT/UPSERT process, insert VALUES into a temporary table. The content of the temporary table will later be inserted into the original table using a MERGE statement.
We insert the values into a temporary table first in order to replace the missing
fields with DEFAULT in normalizeInsertRows, and we can't do that in a
MERGE statement directly.