mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 13:02:11 +03:00
11a454c2d6
This commit applies ormolu to the whole Haskell code base by running `make format`. For in-flight branches, simply merging changes from `main` will result in merge conflicts. To avoid this, update your branch using the following instructions. Replace `<format-commit>` by the hash of *this* commit. $ git checkout my-feature-branch $ git merge <format-commit>^ # and resolve conflicts normally $ make format $ git commit -a -m "reformat with ormolu" $ git merge -s ours post-ormolu https://github.com/hasura/graphql-engine-mono/pull/2404 GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
55 lines
2.1 KiB
Haskell
55 lines
2.1 KiB
Haskell
module Hasura.Backends.Postgres.Translate.Update
|
|
( mkUpdateCTE,
|
|
)
|
|
where
|
|
|
|
import Hasura.Backends.Postgres.SQL.DML qualified as S
|
|
import Hasura.Backends.Postgres.SQL.Types
|
|
import Hasura.Backends.Postgres.Translate.BoolExp
|
|
import Hasura.Backends.Postgres.Translate.Insert
|
|
import Hasura.Backends.Postgres.Translate.Returning
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.IR.Update
|
|
import Hasura.RQL.Types
|
|
import Hasura.SQL.Types
|
|
|
|
mkUpdateCTE ::
|
|
Backend ('Postgres pgKind) =>
|
|
AnnUpd ('Postgres pgKind) ->
|
|
S.CTE
|
|
mkUpdateCTE (AnnUpd tn opExps (permFltr, wc) chk _ columnsInfo) =
|
|
S.CTEUpdate update
|
|
where
|
|
update =
|
|
S.SQLUpdate tn setExp Nothing tableFltr
|
|
. Just
|
|
. S.RetExp
|
|
$ [ S.selectStar,
|
|
asCheckErrorExtractor $ insertCheckConstraint checkExpr
|
|
]
|
|
setExp = S.SetExp $ map (expandOperator columnsInfo) opExps
|
|
tableFltr = Just $ S.WhereFrag tableFltrExpr
|
|
tableFltrExpr = toSQLBoolExp (S.QualTable tn) $ andAnnBoolExps permFltr wc
|
|
checkExpr = toSQLBoolExp (S.QualTable tn) chk
|
|
|
|
expandOperator :: [ColumnInfo ('Postgres pgKind)] -> (PGCol, UpdOpExpG S.SQLExp) -> S.SetExpItem
|
|
expandOperator infos (column, op) = S.SetExpItem $
|
|
(column,) $ case op of
|
|
UpdSet e -> e
|
|
UpdInc e -> S.mkSQLOpExp S.incOp identifier (asNum e)
|
|
UpdAppend e -> S.mkSQLOpExp S.jsonbConcatOp identifier (asJSON e)
|
|
UpdPrepend e -> S.mkSQLOpExp S.jsonbConcatOp (asJSON e) identifier
|
|
UpdDeleteKey e -> S.mkSQLOpExp S.jsonbDeleteOp identifier (asText e)
|
|
UpdDeleteElem e -> S.mkSQLOpExp S.jsonbDeleteOp identifier (asInt e)
|
|
UpdDeleteAtPath a -> S.mkSQLOpExp S.jsonbDeleteAtPathOp identifier (asArray a)
|
|
where
|
|
identifier = S.SEIdentifier $ toIdentifier column
|
|
asInt e = S.SETyAnn e S.intTypeAnn
|
|
asText e = S.SETyAnn e S.textTypeAnn
|
|
asJSON e = S.SETyAnn e S.jsonbTypeAnn
|
|
asArray a = S.SETyAnn (S.SEArray a) S.textArrTypeAnn
|
|
asNum e = S.SETyAnn e $
|
|
case find (\info -> pgiColumn info == column) infos <&> pgiType of
|
|
Just (ColumnScalar s) -> S.mkTypeAnn $ CollectableTypeScalar s
|
|
_ -> S.numericTypeAnn
|