Skip to content
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

Enhanced quick update utility #677

Open
benhutchins opened this issue Mar 19, 2024 · 0 comments
Open

Enhanced quick update utility #677

benhutchins opened this issue Mar 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@benhutchins
Copy link
Owner

benhutchins commented Mar 19, 2024

Pulling this out from #675. I think this would be a useful enhancement.

A suggestion would be to expand the .update() command to avoid having to do 3 functions instead of 1. For example, this is currently the update() command:

 await Users.primaryKey.update({
      hash: id,
      range: undefined,
      changes: {
        status: 'active'
      }
    });

An option would be to use the commands set, add, subtract, etc so that you could issue update() this way:

 await Users.primaryKey.update({
      hash: id,
      range: undefined,
      set: {
        status: 'active'
      },
      add: {
       logins: 1
      }
    });

In other words, these other new methods are added, and "changes" becomes "set" (but would still need to alias "changes" to "set" so it doesn't become a breaking change.) A person could use set, add, subtract together in a single call as above or just individually, examples:

 await Stats.primaryKey.update({
      hash: id,
      range: undefined,
      add: {
        daily_total: 1
      }
    });

 let payment= 50;
 await Accounts.primaryKey.update({
      hash: id,
      range: undefined,
      subtract: {
        remaining_balance: payment
      }
    });

This gives a simple pattern to convert into the actual sdk call. Since you've already used "increment" and "decrement" in other places, for conformity I guess it makes sense to use those instead of add/subtract, or at least alias them.

 let payment= 50;
 await Accounts.primaryKey.update({
      hash: id,
      range: undefined,
      decrement: {
        remaining_balance: payment
      }
    });

Originally posted by @ktwbc in #675 (comment)

@benhutchins benhutchins added the enhancement New feature or request label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant