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

db hint #14

Open
vitaly-t opened this issue Nov 15, 2017 · 2 comments
Open

db hint #14

vitaly-t opened this issue Nov 15, 2017 · 2 comments

Comments

@vitaly-t
Copy link

https://github.com/Cadasta/ZipStream/blob/3b95b03cb92fe0362b7900c4c7b86f8929030404/src/backends/db/postgres/index.js#L40

if you just use oneOrNone instead of one, you won't need to do this kind of error handling, just check for null ;)

@alukach
Copy link
Owner

alukach commented Nov 23, 2017

@vitaly-t Wow, what great OSS support! Thanks for the tip, so to make sure that understand you correctly, oneOrNone wouldn't throw an error so I would need to check for null in a followup .then, right? Something like:

  formatError(err) {  // eslint-disable-line class-methods-use-this
    throw new APIError(err.message, 500);
  }

  checkForEmpty(val) {
    if (val === null) throw new APIError(err.message, 404);
    return val
  }

  update(val) {
    return this.db.oneOrNone(this.cmds.update, val)
      .then(checkForEmpty) 
      .catch(this.formatError);
  }

ps. Loving pg-promise, great library! 👏

@vitaly-t
Copy link
Author

yes, that's correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants