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.Column qualified as IR
import Hasura.SQL.Backend
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
_) = 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 -> ColumnName
forall (b :: BackendType). ColumnInfo b -> Column b
IR.ciColumn [ColumnInfo 'MSSQL]
allColumns
Delete -> ReaderT EntityAlias FromIr Delete
forall (f :: * -> *) a. Applicative f => a -> f a
pure
Delete :: Aliased TableName -> DeleteOutput -> TempTable -> Where -> Delete
Delete
{ $sel:deleteTable:Delete :: Aliased TableName
deleteTable =
Aliased :: forall a. a -> Text -> Aliased a
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)