Question: Is it possible to use pg.helpers.ColumnSet to skip updating value based on column's new value
rakeshriv opened this issue · 0 comments
rakeshriv commented
Hi,
I have a requirement where I want to skip updating the column's value if after the update its value goes below 0. I tried looking up pg-promise's documentation but haven't found anything which serves my purpose. Basically I would want to do something like below (I know that the 'skip' part is incorrect but just posting here for clarifying my requirement).
const decrementQuotaColumnSet = new pgp.helpers.ColumnSet([
skipCol('user_id'),
{
name: 'remaining_quota',
skip(col: any) {
return 'remaining_quota -' + col.value < 0
},
init(col: any) {
return 'remaining_quota - ' + col.value
},
mod: ':raw'
},
{ name: 'updated_at', def: Date.now() }
], { table: 'user_sms_fup' })
Environment
Version of pg-promise: 11.2.0
Version of Node.js: v16