2022-03-10 13:33:55 +03:00
|
|
|
-- | This module defines the translation functions for update mutations.
|
|
|
|
module Hasura.Backends.MSSQL.FromIr.Update
|
|
|
|
( fromUpdate,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Hasura.Backends.MSSQL.FromIr
|
|
|
|
( FromIr,
|
|
|
|
NameTemplate (TableTemplate),
|
|
|
|
generateAlias,
|
|
|
|
)
|
|
|
|
import Hasura.Backends.MSSQL.FromIr.Constants (tempTableNameUpdated)
|
|
|
|
import Hasura.Backends.MSSQL.FromIr.Expression (fromGBoolExp)
|
|
|
|
import Hasura.Backends.MSSQL.Instances.Types ()
|
2023-01-10 04:54:40 +03:00
|
|
|
import Hasura.Backends.MSSQL.Types.Internal
|
|
|
|
import Hasura.Backends.MSSQL.Types.Update
|
2022-03-10 13:33:55 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.IR qualified as IR
|
2023-01-10 04:54:40 +03:00
|
|
|
import Hasura.RQL.IR.Update.Batch qualified as IR
|
2022-03-10 13:33:55 +03:00
|
|
|
import Hasura.RQL.Types.Column qualified as IR
|
|
|
|
import Hasura.SQL.Backend
|
|
|
|
|
|
|
|
fromUpdate :: IR.AnnotatedUpdate 'MSSQL -> FromIr Update
|
2023-01-10 04:54:40 +03:00
|
|
|
fromUpdate (IR.AnnotatedUpdateG table updatePermFilter _ (IR.UpdateBatch updateOperations whereClause) _ allColumns _tCase) = do
|
2022-03-10 13:33:55 +03:00
|
|
|
tableAlias <- generateAlias (TableTemplate (tableName table))
|
|
|
|
runReaderT
|
|
|
|
( do
|
2023-01-10 04:54:40 +03:00
|
|
|
permissionsFilter <- fromGBoolExp updatePermFilter
|
2022-03-10 13:33:55 +03:00
|
|
|
whereExpression <- fromGBoolExp whereClause
|
2022-03-18 13:04:52 +03:00
|
|
|
let columnNames = map IR.ciColumn allColumns
|
2022-03-10 13:33:55 +03:00
|
|
|
pure
|
|
|
|
Update
|
|
|
|
{ updateTable =
|
|
|
|
Aliased
|
|
|
|
{ aliasedAlias = tableAlias,
|
|
|
|
aliasedThing = table
|
|
|
|
},
|
2023-01-10 04:54:40 +03:00
|
|
|
updateSet = updateOperations,
|
2022-03-10 13:33:55 +03:00
|
|
|
updateOutput = Output Inserted (map OutputColumn columnNames),
|
|
|
|
updateTempTable = TempTable tempTableNameUpdated columnNames,
|
|
|
|
updateWhere = Where [permissionsFilter, whereExpression]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
(EntityAlias tableAlias)
|