(
executeCommand: DatabaseExecuteCommand,
tableName: string,
rowIdColumnName: string,
changingColumnNames: string[],
rows: {[id: string]: any[]},
)
| 371 | }; |
| 372 | |
| 373 | const 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 | }; |
nothing calls this directly
no test coverage detected
searching dependent graphs…