server: trivial refactor in postgres insert

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3746
GitOrigin-RevId: 3d3004862bb64bef55d2716f4c2a86f95343cab5
This commit is contained in:
Evie Ciobanu 2022-02-21 20:21:36 +02:00 committed by hasura-bot
parent ad7ecc8ed5
commit b74ed10cb5

View File

@ -145,7 +145,7 @@ insertObject singleObjIns additionalColumns userInfo planVars stringifyNum = Tra
objRelDeterminedCols = concatMap snd objInsRes
finalInsCols = columns <> objRelDeterminedCols <> additionalColumns
cte <- mkInsertQ table onConflict finalInsCols defaultValues checkCond
let cte = mkInsertQ table onConflict finalInsCols defaultValues checkCond
PGE.MutateResp affRows colVals <-
liftTx $
@ -304,14 +304,14 @@ validateInsert insCols objRels addCols = do
insConflictCols = insCols `intersect` addCols
mkInsertQ ::
(MonadError QErr m, Backend ('Postgres pgKind)) =>
Backend ('Postgres pgKind) =>
QualifiedTable ->
Maybe (IR.OnConflictClause ('Postgres pgKind) PG.SQLExp) ->
[(PGCol, PG.SQLExp)] ->
Map.HashMap PGCol PG.SQLExp ->
(AnnBoolExpSQL ('Postgres pgKind), Maybe (AnnBoolExpSQL ('Postgres pgKind))) ->
m PG.CTE
mkInsertQ table onConflictM insCols defVals (insCheck, updCheck) = do
PG.CTE
mkInsertQ table onConflictM insCols defVals (insCheck, updCheck) =
let sqlConflict = PGT.toSQLConflict table <$> onConflictM
sqlExps = mkSQLRow defVals insCols
valueExp = PG.ValuesExp [PG.TupleExp sqlExps]
@ -327,7 +327,7 @@ mkInsertQ table onConflictM insCols defVals (insCheck, updCheck) = do
(PGT.toSQLBoolExp (PG.QualTable table) insCheck)
(fmap (PGT.toSQLBoolExp (PG.QualTable table)) updCheck)
]
pure $ PG.CTEInsert sqlInsert
in PG.CTEInsert sqlInsert
fetchFromColVals ::
MonadError QErr m =>