mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 13:02:11 +03:00
4ccc830bb8
## Description We go through the module `Hasura.Backends.MSSQL.FromIr` and split it into separate self-contained units, which we document. Note that this PR has a slightly opinionated follow-up PR #3909 . ### Related Issues Fix #3666 ### Solution and Design The module `FromIr` has given rise to: * `FromIr.Expression` * `FromIr.Query` * `FromIr.Delete` * `FromIr.Insert` * `FromIr.Update` * `FromIr.SelectIntoTempTable` And `Execute.MutationResponse` has become `FromIr.MutationResponse` (after some slight adaptation of types). PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3908 GitOrigin-RevId: 364acf1bcdf74f2e19464c31cdded12bd8e9aa59
41 lines
1.5 KiB
Haskell
41 lines
1.5 KiB
Haskell
-- | This module contains supporting definitions for building temporary tables
|
|
-- based off of the schema of other tables. This is used in mutations to capture
|
|
-- the data of rows that are affected.
|
|
module Hasura.Backends.MSSQL.FromIr.SelectIntoTempTable
|
|
( toSelectIntoTempTable,
|
|
)
|
|
where
|
|
|
|
import Hasura.Backends.MSSQL.Instances.Types ()
|
|
import Hasura.Backends.MSSQL.Types.Internal as TSQL
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types.Column qualified as IR
|
|
import Hasura.SQL.Backend
|
|
import Language.GraphQL.Draft.Syntax (unName)
|
|
|
|
-- | Create a temporary table with the same schema as the given table.
|
|
toSelectIntoTempTable :: TempTableName -> TableName -> [IR.ColumnInfo 'MSSQL] -> SITTConstraints -> SelectIntoTempTable
|
|
toSelectIntoTempTable tempTableName fromTable allColumns withConstraints = do
|
|
SelectIntoTempTable
|
|
{ sittTempTableName = tempTableName,
|
|
sittColumns = map columnInfoToUnifiedColumn allColumns,
|
|
sittFromTableName = fromTable,
|
|
sittConstraints = withConstraints
|
|
}
|
|
|
|
-- | Extracts the type and column name of a ColumnInfo
|
|
columnInfoToUnifiedColumn :: IR.ColumnInfo 'MSSQL -> UnifiedColumn
|
|
columnInfoToUnifiedColumn colInfo =
|
|
case IR.ciType colInfo of
|
|
IR.ColumnScalar t ->
|
|
UnifiedColumn
|
|
{ name = unName $ IR.ciName colInfo,
|
|
type' = t
|
|
}
|
|
-- Enum values are represented as text value so they will always be of type text
|
|
IR.ColumnEnumReference {} ->
|
|
UnifiedColumn
|
|
{ name = unName $ IR.ciName colInfo,
|
|
type' = TextType
|
|
}
|