schemats
                                
                                 schemats copied to clipboard
                                
                                    schemats copied to clipboard
                            
                            
                            
                        article
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 ;)
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 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 Thanks! nice .catch! I updated the article per your suggestion :)
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.
It's been fixed 😅 Thanks for the review!