module Hasura.Backends.MSSQL.FromIr.Delete (fromDelete) where
import Hasura.Backends.MSSQL.FromIr (FromIr, NameTemplate (..), generateAlias)
import Hasura.Backends.MSSQL.FromIr.Constants (tempTableNameDeleted)
import Hasura.Backends.MSSQL.FromIr.Expression (fromGBoolExp)
import Hasura.Backends.MSSQL.Instances.Types ()
import Hasura.Backends.MSSQL.Types.Internal as TSQL
import Hasura.Prelude
import Hasura.RQL.IR qualified as IR
import Hasura.RQL.Types.BackendType
import Hasura.RQL.Types.Column qualified as IR
fromDelete :: IR.AnnDel 'MSSQL -> FromIr Delete
fromDelete :: AnnDel 'MSSQL -> FromIr Delete
fromDelete (IR.AnnDel TableName 'MSSQL
table (AnnBoolExp 'MSSQL (SQLExpression 'MSSQL)
permFilter, AnnBoolExp 'MSSQL (SQLExpression 'MSSQL)
whereClause) MutationOutputG 'MSSQL Void (SQLExpression 'MSSQL)
_ [ColumnInfo 'MSSQL]
allColumns Maybe NamingCase
_ Maybe (ValidateInput ResolvedWebhook)
_validateInput Bool
_isDeleteByPrimaryKey) = do
Text
tableAlias <- NameTemplate -> FromIr Text
generateAlias (Text -> NameTemplate
TableTemplate (TableName -> Text
tableName TableName 'MSSQL
TableName
table))
ReaderT EntityAlias FromIr Delete -> EntityAlias -> FromIr Delete
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT
( do
Expression
permissionsFilter <- GBoolExp 'MSSQL (AnnBoolExpFld 'MSSQL Expression)
-> ReaderT EntityAlias FromIr Expression
fromGBoolExp AnnBoolExp 'MSSQL (SQLExpression 'MSSQL)
GBoolExp 'MSSQL (AnnBoolExpFld 'MSSQL Expression)
permFilter
Expression
whereExpression <- GBoolExp 'MSSQL (AnnBoolExpFld 'MSSQL Expression)
-> ReaderT EntityAlias FromIr Expression
fromGBoolExp AnnBoolExp 'MSSQL (SQLExpression 'MSSQL)
GBoolExp 'MSSQL (AnnBoolExpFld 'MSSQL Expression)
whereClause
let columnNames :: [ColumnName]
columnNames = (ColumnInfo 'MSSQL -> ColumnName)
-> [ColumnInfo 'MSSQL] -> [ColumnName]
forall a b. (a -> b) -> [a] -> [b]
map ColumnInfo 'MSSQL -> Column 'MSSQL
ColumnInfo 'MSSQL -> ColumnName
forall (b :: BackendType). ColumnInfo b -> Column b
IR.ciColumn [ColumnInfo 'MSSQL]
allColumns
Delete -> ReaderT EntityAlias FromIr Delete
forall a. a -> ReaderT EntityAlias FromIr a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
Delete
{ $sel:deleteTable:Delete :: Aliased TableName
deleteTable =
Aliased
{ $sel:aliasedAlias:Aliased :: Text
aliasedAlias = Text
tableAlias,
$sel:aliasedThing:Aliased :: TableName
aliasedThing = TableName 'MSSQL
TableName
table
},
$sel:deleteOutput:Delete :: DeleteOutput
deleteOutput = Deleted -> [OutputColumn] -> DeleteOutput
forall t. t -> [OutputColumn] -> Output t
Output Deleted
Deleted ((ColumnName -> OutputColumn) -> [ColumnName] -> [OutputColumn]
forall a b. (a -> b) -> [a] -> [b]
map ColumnName -> OutputColumn
OutputColumn [ColumnName]
columnNames),
$sel:deleteTempTable:Delete :: TempTable
deleteTempTable = TempTableName -> [ColumnName] -> TempTable
TempTable TempTableName
tempTableNameDeleted [ColumnName]
columnNames,
$sel:deleteWhere:Delete :: Where
deleteWhere = [Expression] -> Where
Where [Expression
permissionsFilter, Expression
whereExpression]
}
)
(Text -> EntityAlias
EntityAlias Text
tableAlias)