Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Is it possible to use pg.helpers.ColumnSet to skip updating value based on column's new value #881

Closed
rakeshriv opened this issue May 22, 2023 · 0 comments

Comments

@rakeshriv
Copy link

rakeshriv commented May 22, 2023

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
Repository owner locked and limited conversation to collaborators May 22, 2023
@vitaly-t vitaly-t converted this issue into discussion #882 May 22, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant