|
1 | 1 | # fastify-postgres |
2 | 2 |
|
3 | | -[](http://standardjs.com/) |
4 | | - |
| 3 | + |
| 4 | +[](https://www.npmjs.com/package/fastify-postgres) |
| 5 | +[](https://snyk.io/test/github/fastify/fastify-postgres) |
| 6 | +[](https://coveralls.io/github/fastify/fastify-postgres?branch=master) |
| 7 | +[](https://standardjs.com/) |
6 | 8 |
|
7 | | -Fastify PostgreSQL connection plugin, with this you can share the same PostgreSQL connection pool in every part of your server. |
8 | | -Under the hood the [node-postgres](https://github.com/brianc/node-postgres) is used, the options that you pass to `register` will be passed to the PostgreSQL pool builder. |
| 9 | +Fastify PostgreSQL connection plugin; with this, you can share the same PostgreSQL connection pool in every part of your server. |
| 10 | +Under the hood [node-postgres](https://github.com/brianc/node-postgres) is used, the options that you pass to `register` will be passed to the PostgreSQL pool builder. |
9 | 11 |
|
10 | 12 | ## Install |
11 | 13 | ``` |
12 | 14 | npm i pg fastify-postgres --save |
13 | 15 | ``` |
14 | 16 | ## Usage |
15 | | -Add it to you project with `register` and you are done! |
16 | | -This plugin will add the `pg` namespace in your Fastify instance, with the following properties: |
| 17 | +Add it to your project with `register` and you are done! |
| 18 | +This plugin will add the `pg` namespace to your Fastify instance, with the following properties: |
17 | 19 | ``` |
18 | 20 | connect: the function to get a connection from the pool |
19 | 21 | pool: the pool instance |
@@ -145,7 +147,7 @@ fastify.listen(3000, err => { |
145 | 147 | }) |
146 | 148 | ``` |
147 | 149 |
|
148 | | -As you can see there is no need to close the client, since is done internally. Promises and async await are supported as well. |
| 150 | +As you can see there is no need to close the client, since it is done internally. Promises and async await are supported as well. |
149 | 151 |
|
150 | 152 | ### Name option |
151 | 153 | If you need to have multiple databases set up, then you can name each one of them by passing `name: 'foo'`. It will then be accessible as `fastify.pg.foo`. |
@@ -175,9 +177,9 @@ fastify.listen(3000, err => { |
175 | 177 | ``` |
176 | 178 |
|
177 | 179 | ### Native option |
178 | | -If you want to gain the maximum performances you can install [pg-native](https://github.com/brianc/node-pg-native), and pass `native: true` to the plugin options. |
| 180 | +If you want maximum performance you can install [pg-native](https://github.com/brianc/node-pg-native), and pass `native: true` to the plugin options. |
179 | 181 | *Note: it requires PostgreSQL client libraries & tools installed, see [instructions](https://github.com/brianc/node-pg-native#install).* |
180 | | -Note: trying to use native options without successfully installation of `pg-native` will get a warning and fallback to regular `pg` module. |
| 182 | +Note: trying to use native options without successfully installation of `pg-native` will return a warning and fallback to regular `pg` module. |
181 | 183 |
|
182 | 184 | ```js |
183 | 185 | const fastify = require('fastify')() |
@@ -231,7 +233,7 @@ fastify.listen(3000, err => { |
231 | 233 | ``` |
232 | 234 |
|
233 | 235 | ### Transact route option |
234 | | -It's possible to automatically wrap a route handler in a transaction by using the `transact` option when registering a route with Fastify. Note that the option must be scoped within a `pg` options object to take effect. |
| 236 | +It is possible to automatically wrap a route handler in a transaction by using the `transact` option when registering a route with Fastify. Note that the option must be scoped within a `pg` options object to take effect. |
235 | 237 |
|
236 | 238 | `query` commands can then be accessed at `request.pg` or `request.pg[name]` and `transact` can be set for either the root pg client with value `true` or for a pg client at a particular namespace with value `name`. Note that the namespace needs to be set when registering the plugin in order to be available on the request object. |
237 | 239 |
|
@@ -305,8 +307,8 @@ $ npm test |
305 | 307 | ## Acknowledgements |
306 | 308 |
|
307 | 309 | This project is kindly sponsored by: |
308 | | -- [nearForm](http://nearform.com) |
309 | | -- [LetzDoIt](http://www.letzdoitapp.com/) |
| 310 | +- [nearForm](https://www.nearform.com) |
| 311 | +- [LetzDoIt](https://www.letzdoitapp.com/) |
310 | 312 |
|
311 | 313 | ## License |
312 | 314 |
|
|
0 commit comments