在发生冲突时, onConflict 返回错误的值
作者: rockrepIGN创建于 2022年9月9日更新于 2025年4月17日
标签bug
describe('insert', () => {
const userPlatforms = [
{ userId: 1, platformId: 11 },
{ userId: 1, platformId: 12 },
]
console.log({existing: userPlatforms})
it('Knex version - should NOT raise, but ignore, on insertion of duplicate records, existing or provided, returning only those actually added', async () => {
expect.assertions(1)
await db.UserPlatformDB.insert(userPlatforms)
const inserts = userPlatforms.concat([
{ userId: 1, platformId: 13 },
{ userId: 1, platformId: 13 },
])
console.log({ inserts })
const response = await db.UserPlatformDB.insertWithKnex(inserts)
console.log({ response })
expect(response.map(rs => rs.platformId)).toEqual([13])
})
it('Objection version - should NOT raise, but ignore, on insertion of duplicate records, existing or provided, returning only those actually added', async () => {
expect.assertions(1)
await db.UserPlatformDB.insert(userPlatforms)
const inserts = userPlatforms.concat([
{ userId: 1, platformId: 13 },
{ userId: 1, platformId: 13 },
])
console.log({ inserts })
const response = await db.UserPlatformDB.insertWithObjection(inserts)
console.log({ response })
expect(response.map(rs => rs.platformId)).toEqual([13])
})
}
内容来源: Vincit/objection.js