MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / upsert

Function upsert

packages/core/fumadb/src/adapters/drizzle/query.ts:400–422  ·  view source on GitHub ↗
(table, v)

Source from the content-addressed store, hash-verified

398 },
399
400 async upsert(table, v) {
401 const idField = table.getIdColumn().names.drizzle;
402 const drizzleTable = toDrizzle(table);
403 let query = db
404 .select({ id: drizzleTable[idField] })
405 .from(drizzleTable)
406 .limit(1);
407
408 if (v.where) {
409 query = query.where(buildWhere(toDrizzleColumn, v.where)) as any;
410 }
411
412 const targetIds = await query.execute();
413
414 if (targetIds.length > 0) {
415 await db
416 .update(drizzleTable)
417 .set(mapValues(v.update, table))
418 .where(Drizzle.eq(drizzleTable[idField], targetIds[0].id));
419 } else {
420 await this.createMany(table, [v.create]);
421 }
422 },
423 async upsertMany(table, v) {
424 if (v.values.length === 0) return;
425 if (v.target.length === 0) {

Callers

nothing calls this directly

Calls 7

toDrizzleFunction · 0.85
limitMethod · 0.80
buildWhereFunction · 0.70
mapValuesFunction · 0.70
executeMethod · 0.65
setMethod · 0.65
updateMethod · 0.65

Tested by

no test coverage detected