graphql-engine/server/src-lib/Hasura/Backends/Postgres/Translate/Delete.hs
Naveen Naidu a367525e68 server/postgres: delete input validation [experimental]
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9666
Co-authored-by: Rakesh Emmadi <12475069+rakeshkky@users.noreply.github.com>
GitOrigin-RevId: 5fa7702401065869c953b23c6734b9b367247634
2023-06-28 13:46:00 +00:00

32 lines
850 B
Haskell

-- | Postgres Translate Delete
--
-- Tranlates an IR delete term to a Postgres SQL DELETE statement.
--
-- See 'Hasura.Backends.Postgres.Execute.Mutation.execDeleteQuery'.
module Hasura.Backends.Postgres.Translate.Delete
( mkDelete,
)
where
import Hasura.Backends.Postgres.SQL.DML qualified as S
import Hasura.Backends.Postgres.Translate.BoolExp
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp
import Hasura.RQL.IR.Delete
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.BackendType
mkDelete ::
(Backend ('Postgres pgKind)) =>
AnnDel ('Postgres pgKind) ->
S.SQLDelete
mkDelete (AnnDel tn (fltr, wc) _ _ _ _ _) =
S.SQLDelete tn Nothing tableFltr $ Just S.returningStar
where
tableFltr =
Just
. S.WhereFrag
. S.simplifyBoolExp
. toSQLBoolExp (S.QualTable tn)
$ andAnnBoolExps fltr wc