While booting my Node.js app, I want to make a couple of synchronous calls to the PostgreSQL database to check some things before continuing the control flow. How can I achieve this using the node-postgres package?
标签:
node-postgres
相关问题
- Error Relation does not exist
- PostgreSQL connection via javascript
- Passing array of custom type to postgres function
- How to convert MySQL-style question mark `?` bound
- How to set schema with node-postgres
相关文章
- when to disconnect and when to end a pg client or
- How do I send in parameters in COPY TO-query in no
- Webpack can not use __dirname?
- Pass array from node-postgres to plpgsql function
- Why do I need to use async/await twice in node-pos
- 如何使用节点的Postgres的服务器?(How do I use node-postgres in
- querying postgres db with node-postgres
- How to set schema in pg-promise
You can do this by using pg-pool in combination with asyncawait:
I think this would be applicable.
The only way to synchronize calls is to nest them in callbacks:
This can be a pain, and would be trivial in some other languages, but it is the nature of the beast.
Given that the call is inherently asynchronous, you'll need to manage it either via callbacks (the defacto Node style), async or via promises (Q, when.js, Bluebird, etc...) Please note that wrt to the accepted answer, callbacks are not the only way to do this.
You can use the pg-native or pg-sync package.
brianc (author of node-postgres) commented here, that
Hope this helps...