Skip to content

Commit

Permalink
fixed node defs import batch insert (#3015)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 18, 2023
1 parent f917698 commit 43d814e
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions server/modules/nodeDef/repository/nodeDefRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ export const insertNodeDef = async (surveyId, nodeDef, client = DB) =>
(row) => dbTransformCallback({ row, draft: true, advanced: true }) // Always loading draft when creating or updating a nodeDef
)

export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false }, client = DB) =>
client.tx(async (tx) => {
const schema = getSurveyDBSchema(surveyId)
await tx.batch([
nodeDefs.map((nodeDef) =>
tx.none(
`
export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false }, client = DB) => {
const schema = getSurveyDBSchema(surveyId)
return client.batch([
nodeDefs.map((nodeDef) =>
client.none(
`
INSERT INTO ${schema}.node_def (
parent_uuid,
uuid,
Expand All @@ -93,22 +92,22 @@ export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false }
$4::jsonb, $5::jsonb,
$6::jsonb, $7::jsonb,
$8,$9,$10)`,
[
NodeDef.getParentUuid(nodeDef),
nodeDef.uuid,
NodeDef.getType(nodeDef),
backup ? NodeDef.getProps(nodeDef) : {},
backup ? NodeDef.getPropsDraft(nodeDef) : NodeDef.getProps(nodeDef),
backup ? NodeDef.getPropsAdvanced(nodeDef) : {},
backup ? NodeDef.getPropsAdvancedDraft(nodeDef) : NodeDef.getPropsAdvanced(nodeDef),
NodeDef.getMeta(nodeDef),
NodeDef.isAnalysis(nodeDef),
NodeDef.isVirtual(nodeDef),
]
)
),
])
})
[
NodeDef.getParentUuid(nodeDef),
nodeDef.uuid,
NodeDef.getType(nodeDef),
backup ? NodeDef.getProps(nodeDef) : {},
backup ? NodeDef.getPropsDraft(nodeDef) : NodeDef.getProps(nodeDef),
backup ? NodeDef.getPropsAdvanced(nodeDef) : {},
backup ? NodeDef.getPropsAdvancedDraft(nodeDef) : NodeDef.getPropsAdvanced(nodeDef),
NodeDef.getMeta(nodeDef),
NodeDef.isAnalysis(nodeDef),
NodeDef.isVirtual(nodeDef),
]
)
),
])
}

// ============== READ

Expand Down

0 comments on commit 43d814e

Please sign in to comment.