|
4 | 4 |
|
5 | 5 | [](http://standardjs.com/) [](https://travis-ci.org/fastify/fastify-postgres)
|
6 | 6 |
|
7 |
| -Fastify PostgreSQL connection plugin, with this you can share the same PostgreSQL connection pool in every part of your server. |
| 7 | +Fastify PostgreSQL connection plugin, with this you can share the same PostgreSQL connection pool in every part of your server. |
8 | 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 | 9 |
|
10 | 10 | ## Install
|
11 | 11 | ```
|
12 | 12 | npm i fastify-postgres --save
|
13 | 13 | ```
|
14 | 14 | ## Usage
|
15 |
| -Add it to you project with `register` and you are done! |
| 15 | +Add it to you project with `register` and you are done! |
16 | 16 | This plugin will add the `pg` namespace in your Fastify instance, with the following properties:
|
17 | 17 | ```
|
18 | 18 | connect: the function to get a connection from the pool
|
@@ -131,7 +131,7 @@ fastify.pg.transact(client => {
|
131 | 131 |
|
132 | 132 | /* or with a commit callback
|
133 | 133 |
|
134 |
| -fastify.pg.transact((client, commit) => { |
| 134 | +fastify.pg.transact((client, commit) => { |
135 | 135 | client.query('INSERT INTO users(username) VALUES($1) RETURNING id', [req.params.username], (err, id) => {
|
136 | 136 | commit(err, id)
|
137 | 137 | });
|
@@ -211,9 +211,16 @@ First, start postgres with:
|
211 | 211 | $ npm run postgres
|
212 | 212 | ```
|
213 | 213 |
|
214 |
| -Then in another terminal: |
| 214 | +Then you can, in another terminal, find the running docker, init the DB, then run the tests: |
215 | 215 |
|
216 | 216 | ```
|
| 217 | +$ docker ps |
| 218 | +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 219 | +28341f85c4cd postgres:9.6-alpine "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 0.0.0.0:5432->5432/tcp jovial_shockley |
| 220 | +
|
| 221 | +$ docker exec -ti jovial_shockley /usr/local/bin/psql -d postgres -U postgres -c 'CREATE TABLE users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);' |
| 222 | +CREATE TABLE |
| 223 | +
|
217 | 224 | $ npm test
|
218 | 225 | ```
|
219 | 226 |
|
|
0 commit comments