Fixed upsert failing on empty insert array due breaking Knex API change.
This commit is contained in:
@@ -33,8 +33,8 @@ async function upsert(table, items, identifier = ['id'], _knex) {
|
||||
logger.debug(`${table}: Updating ${update.length}`);
|
||||
|
||||
const [inserted, updated] = await Promise.all([
|
||||
knex(table).returning('*').insert(insert),
|
||||
knex.transaction(async (trx) => Promise.all(update.map((item) => {
|
||||
insert.length > 0 ? knex(table).returning('*').insert(insert) : [],
|
||||
update.length > 0 ? knex.transaction(async (trx) => Promise.all(update.map((item) => {
|
||||
const clause = identifiers.reduce((acc, identifierX) => ({ ...acc, [identifierX]: item[identifierX] }), {});
|
||||
|
||||
return trx
|
||||
@@ -42,7 +42,7 @@ async function upsert(table, items, identifier = ['id'], _knex) {
|
||||
.update(item)
|
||||
.into(table)
|
||||
.returning('*');
|
||||
}))),
|
||||
}))) : [],
|
||||
]);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user