MCPcopy Index your code
hub / github.com/tinyplex/tinybase / defaultUpsert

Function defaultUpsert

src/persisters/common/database/commands.ts:373–412  ·  view source on GitHub ↗
(
  executeCommand: DatabaseExecuteCommand,
  tableName: string,
  rowIdColumnName: string,
  changingColumnNames: string[],
  rows: {[id: string]: any[]},
)

Source from the content-addressed store, hash-verified

371};
372
373const defaultUpsert: Upsert = async (
374 executeCommand: DatabaseExecuteCommand,
375 tableName: string,
376 rowIdColumnName: string,
377 changingColumnNames: string[],
378 rows: {[id: string]: any[]},
379) => {
380 const offset = [1];
381 await executeCommand(
382 INSERT +
383 ' INTO' +
384 escapeId(tableName) +
385 '(' +
386 escapeColumnNames(rowIdColumnName, ...changingColumnNames) +
387 ')VALUES' +
388 arrayJoin(
389 objToArray(
390 rows,
391 (row: any[]) =>
392 '($' + offset[0]++ + ',' + getPlaceholders(row, offset) + ')',
393 ),
394 COMMA,
395 ) +
396 'ON CONFLICT(' +
397 escapeId(rowIdColumnName) +
398 `)DO ${UPDATE} SET` +
399 arrayJoin(
400 arrayMap(
401 changingColumnNames,
402 (columnName) =>
403 escapeId(columnName) + '=excluded.' + escapeId(columnName),
404 ),
405 COMMA,
406 ),
407 objToArray(rows, (row: any[], id: string) => [
408 id,
409 ...arrayMap(row, (value) => value ?? null),
410 ]).flat(),
411 );
412};

Callers

nothing calls this directly

Calls 6

escapeIdFunction · 0.90
escapeColumnNamesFunction · 0.90
arrayJoinFunction · 0.90
objToArrayFunction · 0.90
getPlaceholdersFunction · 0.90
arrayMapFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…