update incrementing value (postgres)

So, i have a table:
export const VisitorCount = pgTable('visitor-count', {
id: bigserial('id', { mode: 'number' }).primaryKey(),
experimentId: bigint('experiment_id', { mode: 'number' }),
variantId: bigint('variant_id', { mode: 'number' }),
count: bigint('count', { mode: 'number' }).default(0),
});
export const VisitorCount = pgTable('visitor-count', {
id: bigserial('id', { mode: 'number' }).primaryKey(),
experimentId: bigint('experiment_id', { mode: 'number' }),
variantId: bigint('variant_id', { mode: 'number' }),
count: bigint('count', { mode: 'number' }).default(0),
});
at the time i want to do the update, i know the required rows are there, initialized at 0 and i'll do batch updates with objects that look like:
{
'8-25': 4,
'8-26': 4,
'8-23': 3,
'8-22': 3,
'8-24': 4,
};
{
'8-25': 4,
'8-26': 4,
'8-23': 3,
'8-22': 3,
'8-24': 4,
};
where "8" is experimentId, "25" is variantId and i want to update the relevant line, adding 4to the existing value that was there before... Is there a good way to do this?
1 Reply
Angelelz
Angelelz15mo ago
This is a javascript question, you just need to do transformations to your data before sending to drizzle Along the lines of Object.entries(theObjectToTransform).map(...)
Want results from more Discord servers?
Add your server