graphql-engine/server/src-lib/Hasura/Backends/MSSQL/FromIr/Update.hs
paritosh-08 d66abcefab server: transform enum with upper for graphql-default
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5032
GitOrigin-RevId: 206a673f4bd59700436f6160feeb7df415f637ad
2022-07-19 06:56:45 +00:00

44 lines
1.6 KiB
Haskell

-- | 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 ()
import Hasura.Backends.MSSQL.Types.Internal as TSQL
import Hasura.Backends.MSSQL.Types.Update as TSQL (BackendUpdate (..), Update (..))
import Hasura.Prelude
import Hasura.RQL.IR qualified as IR
import Hasura.RQL.Types.Column qualified as IR
import Hasura.SQL.Backend
fromUpdate :: IR.AnnotatedUpdate 'MSSQL -> FromIr Update
fromUpdate (IR.AnnotatedUpdateG table (permFilter, whereClause) _ backendUpdate _ allColumns _tCase) = do
tableAlias <- generateAlias (TableTemplate (tableName table))
runReaderT
( do
permissionsFilter <- fromGBoolExp permFilter
whereExpression <- fromGBoolExp whereClause
let columnNames = map IR.ciColumn allColumns
pure
Update
{ updateTable =
Aliased
{ aliasedAlias = tableAlias,
aliasedThing = table
},
updateSet = updateOperations backendUpdate,
updateOutput = Output Inserted (map OutputColumn columnNames),
updateTempTable = TempTable tempTableNameUpdated columnNames,
updateWhere = Where [permissionsFilter, whereExpression]
}
)
(EntityAlias tableAlias)