Icemourne
Icemourne
DTDrizzle Team
Created by Icemourne on 3/11/2024 in #help
Can someone explain how can I use .onConflictDoUpdate with array of values?
If where is conflict somewhere with some value in array how can I use values from that array as new value? In documentation it shows how to handle that then setting one value but not array of values
// for single value
await db.insert(users)
.values({ id: 1, name: 'Dan' })
.onConflictDoUpdate({ target: users.id, set: { name: 'John' } });
// for single value
await db.insert(users)
.values({ id: 1, name: 'Dan' })
.onConflictDoUpdate({ target: users.id, set: { name: 'John' } });
but how about this
await db.insert(users)
.values([{ id: 1, name: 'Dan' }, { id: 2, name: 'Tom' }, { id: 3, name: 'Martin' }])
.onConflictDoUpdate({ target: users.id, set: ??? }); // if where was conflict on id 2 how can I set new name using values in array
await db.insert(users)
.values([{ id: 1, name: 'Dan' }, { id: 2, name: 'Tom' }, { id: 3, name: 'Martin' }])
.onConflictDoUpdate({ target: users.id, set: ??? }); // if where was conflict on id 2 how can I set new name using values in array
5 replies
DTDrizzle Team
Created by Icemourne on 3/8/2024 in #help
How can I make reusable columns then building schema?
If I save part of column in variable
const username = varchar('username', { length: 30 }).unique().notNull()
const username = varchar('username', { length: 30 }).unique().notNull()
and then add something
const username_reference = username.references(() => userSchema.username, { onUpdate: 'cascade' })
const username_reference = username.references(() => userSchema.username, { onUpdate: 'cascade' })
It will change first one to It changes objects properties instead of making copy and that's reasonable but I need to make copy and can't figure out how
3 replies