Skip to main content

Upsert operations

Set options.upsert to true to perform an "upsert" (update or insert). If the SDK finds a record matching your where clause, it updates that record. If no match is found, it inserts a new record.

Basic upsert​

Use conflictKeys to specify which fields the database should use to identify an existing record during the insert phase.

TypeScript
await manta.updateRecords({
table: "products",
data: { name: "New Product", sku: "SKU123" },
where: { sku: "SKU123" }, // Attempts to find/update by this field
options: {
upsert: true,
conflictKeys: ["sku"],
},
});

Upsert with OR logic​

By default, conflictKeys are combined using AND logic. Set conflictKeysLogic to 'or' to trigger an update if any of the specified keys match an existing record.

TypeScript
await manta.updateRecords({
table: "products",
data: { name: "Product X", sku: "SKU123", barcode: "BAR456" },
where: { sku: "SKU123" },
options: {
upsert: true,
conflictKeys: ["sku", "barcode"],
conflictKeysLogic: "or",
},
});