fawwaz
fawwaz
DTDrizzle Team
Created by peterstnsz on 6/1/2024 in #help
Supabase + Drizzle + Nuxt 3 + Node - SSL 'SELF_SIGNED_CERT_IN_CHAIN' and drizzle-kit studio issues
I'm in the same boat looking for answers. is it possible that there is no way to do this with drizzle?
5 replies
DTDrizzle Team
Created by sevenwestonroads on 4/23/2023 in #help
UPSERT many ?
I might be wrong as I'm not an sql expert but @Jan Vorwerk shouldn't you catch all the keys instead of just the keys of the first element in the array, something like this?
const saveAll = async (usersData: Array<NewUser | UpdateUser>) => {
await db
.insert(users)
.values(usersData)
.onConflictDoUpdate({
target: users.id,
set: Object.assign(
{},
[...new Set(usersData.map((user) => Object.keys(user)).flat())].filter((k) => k !== "id").map((k) => ({ [k]: sql`excluded.${k}` }))
) as Partial<UpdateUser>,
});
};
const saveAll = async (usersData: Array<NewUser | UpdateUser>) => {
await db
.insert(users)
.values(usersData)
.onConflictDoUpdate({
target: users.id,
set: Object.assign(
{},
[...new Set(usersData.map((user) => Object.keys(user)).flat())].filter((k) => k !== "id").map((k) => ({ [k]: sql`excluded.${k}` }))
) as Partial<UpdateUser>,
});
};
14 replies