Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module defines translation functions that yield the results of mutation requests that return the data of rows that were affected.
Synopsis
- mkMutationOutputSelect :: StringifyNumbers -> Text -> MutationOutputG 'MSSQL Void Expression -> FromIr Select
- selectMutationOutputAndCheckCondition :: Text -> Select -> Expression -> Select
Documentation
mkMutationOutputSelect :: StringifyNumbers -> Text -> MutationOutputG 'MSSQL Void Expression -> FromIr Select Source #
Generate a SQL SELECT statement which outputs the mutation response
For multi row inserts:
SELECT (SELECT COUNT(*) FROM [with_alias]) AS [affected_rows], (select_from_returning) AS [returning] FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER
For single row insert: the selection set is translated to SQL query using @fromSelect
selectMutationOutputAndCheckCondition :: Text -> Select -> Expression -> Select Source #
Generate a SQL SELECT statement which outputs both mutation response and check constraint result.
A check constraint
applies to the data that has been changed, while
permissions
filter the data that is made available.
This function applies to insert
and update
mutations.
The check constraint boolean expression is evaluated on mutated rows in a CASE expression so that the int value "0" is returned when check constraint is true otherwise the int value "1" is returned. We use SUM aggregation on the returned value and if check constraint on any row is not met, the summed value will not equal to "0" (always > 1).
<check_constraint_select> := SELECT SUM([check_sub_query].[check_evaluation]) FROM ( SELECT (CASE WHEN <check_boolean_expression> THEN 0 ELSE 1 END) AS [check_evaluation] FROM [with_alias] ) AS [check_sub_query] <mutation_output_select> := SELECT (SELECT COUNT(*) FROM [with_alias]) AS [affected_rows], (select_from_returning) AS [returning] FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER SELECT (<mutation_output_select>) AS [mutation_response], (<check_constraint_select>) AS [check_constraint_select]