Describe what you want
This is a follow-up of a discussion on discord
The idea is that, when inserting an array of object values, it's a bit complex to ask for an update for value which cause a conflict. I came up with something like the following
const values: CrmCompanies[] = ... ;
await db
.insert(crmCompanies)
.values(values)
.onConflictDoUpdate({
target: crmCompanies.id,
set: Object.assign(
{},
...Object.keys(values[0])
.filter((k) => k !== "id")
.map((k) => ({ [k]: sql`excluded.${k}` })),
) as Partial<CrmCompanies>,
});
As you can see, the syntax is not very easy to come up with, and we lose type information. Ideally, I would rather write something such as (not necessarily that exact syntax of course):
const values: CrmCompanies[] = ... ;
await db
.insert(crmCompanies)
.values(values)
.onConflictDoUpdate({
target: crmCompanies.id,
set: values,
});
Describe what you want
This is a follow-up of a discussion on discord
The idea is that, when inserting an array of object values, it's a bit complex to ask for an update for value which cause a conflict. I came up with something like the following
As you can see, the syntax is not very easy to come up with, and we lose type information. Ideally, I would rather write something such as (not necessarily that exact syntax of course):