schemats icon indicating copy to clipboard operation
schemats copied to clipboard

article

Open vitaly-t opened this issue 8 years ago • 5 comments

Great article, well done!

I just wanted to point out that one can write even more elegant code, by replacing db.query(..).then(...each) with simply db.each. See methods each and map ;)

vitaly-t avatar Nov 27 '16 12:11 vitaly-t

Thanks @vitaly-t for the pointer! Looks like we haven't used pg-promise at its full potential. I'll update the article when I get a chance.

xiamx avatar Nov 28 '16 19:11 xiamx

@xiamx just saw the update, and wanted to point out - it is generally not a good idea showing loose promises in examples, i.e. the ones that have no .catch provided, which is what you do for those each examples.

I would suggest that you either refactor them using the await syntax or provide a .catch handler :wink:

vitaly-t avatar Dec 07 '16 22:12 vitaly-t

@vitaly-t Thanks! nice .catch! I updated the article per your suggestion :)

xiamx avatar Dec 08 '16 16:12 xiamx

I would also suggest that you test the code that you publish :wink:

The syntax you show for calling .each is incorrect, see the API. It must be .each(query, values, callback), whereas instead you pass your callback as values, such code wouldn't work and throw an error.

Instead of db.each(q, (book) => { you should have db.each(q, [], (book) => {, since you are not passing in any query-formatting values.

vitaly-t avatar Dec 10 '16 15:12 vitaly-t

It's been fixed 😅 Thanks for the review!

xiamx avatar Dec 11 '16 22:12 xiamx