I want to update multiple rows with pg promise but I don’t understand it fully
Here is my code
I don’t know where I have access to my plan_id
const cs = new pgp.helpers.ColumnSet(
['user_id', 'tenant_id', 'location_id', 'start_time', 'end_time', 'time_range', 'status', 'info'], { table: 'workers_plan' });
const cs_values: UpdateWorkersPlan[] = plan.map((el: UpdateWorkersPlan) => ({
plan_id: el.plan_id,
user_id: el.user_id,
tenant_id,
location_id: el.location_id,
start_time: el.start_time,
end_time: el.end_time,
time_range: tsrange(el.start_time, el.end_time),
status: el.status,
info: el.info,
}));
pgp.as.format('WHERE plan_id = $1', [how to access plan id ?])
await pgp.helpers.update(cs_values, cs)
With my experience, to update multiple rows with pg-promise, you can utilize
pgp.helpers.updatemethod.So you should include
plan_idinColumnSetdefinition and map it incs_values:(haven't tested this code)
Docs: https://vitaly-t.github.io/pg-promise/helpers.html