Skip to content

Update fastify to v3 #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
update_configs:
- package_manager: "javascript"
directory: "/"
update_schedule: "daily"
8 changes: 5 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: GitHub CI
name: CI workflow

on: [push, pull_request]

Expand All @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [6, 8, 10, 12, 13]
node: [10, 12, 14]

name: Node.js ${{ matrix.node }}

Expand All @@ -17,6 +17,7 @@ jobs:
env:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
ports:
# will assign a random free host port
- 5432:5432
Expand All @@ -32,7 +33,8 @@ jobs:
run: |
npm i node-gyp
sudo apt-get install -yqq libpq-dev postgresql-client
psql -h localhost -p ${{ job.services.postgres.ports[5432] }} -d postgres -c 'CREATE TABLE users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);' -U postgres
chmod 600 .pgpass
PGPASSFILE=.pgpass psql -h localhost -p ${{ job.services.postgres.ports[5432] }} -d postgres -c 'CREATE TABLE users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);' -U postgres

- name: Install
run: npm install
Expand Down
1 change: 1 addition & 0 deletions .pgpass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost:*:*:postgres:postgres
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the ci config we must set a POSTGRESS_PASSWORD value, and when we run the psql command it would prompt for a password, but if we provide a .pgpass file it will use that to get the password

27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# fastify-postgres

[![Greenkeeper badge](https://badges.greenkeeper.io/fastify/fastify-postgres.svg)](https://greenkeeper.io/)

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Build Status](https://travis-ci.org/fastify/fastify-postgres.svg?branch=master)](https://travis-ci.org/fastify/fastify-postgres)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) ![CI workflow](https://github.com/fastify/fastify-postgres/workflows/CI%20workflow/badge.svg)

Fastify PostgreSQL connection plugin, with this you can share the same PostgreSQL connection pool in every part of your server.
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.
Expand Down
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "standard && tap -J test/*.test.js",
"test:report": "standard && tap -J --coverage-report=html test/*.test.js",
"test:verbose": "standard && tap -J test/*.test.js -Rspec",
"load-data": "docker run --rm -d --link fastify-postgres:postgres postgres:11-alpine psql -h postgres -d postgres -c 'CREATE TABLE users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);' -U postgres",
"postgres": "docker run --rm -d -p 5432:5432 --name fastify-postgres postgres:11-alpine"
"postgres": "docker run -p 5432:5432 --name fastify-postgres -e POSTGRES_PASSWORD=postgres -d postgres",
"load-data": "docker exec -it fastify-postgres psql -c 'CREATE TABLE users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);' -U postgres -d postgres"
},
"repository": {
"type": "git",
Expand All @@ -29,21 +29,16 @@
},
"homepage": "https://github.com/fastify/fastify-postgres#readme",
"dependencies": {
"fastify-plugin": "^1.5.0"
"fastify-plugin": "^2.0.0"
},
"devDependencies": {
"fastify": "^2.7.1",
"fastify": "^3.0.0-rc.1",
"pg": "*",
"pg-native": "^3.0.0",
"standard": "^13.0.1",
"tap": "^12.7.0"
},
"peerDependencies": {
"pg": ">=6.0.0"
},
"greenkeeper": {
"ignore": [
"tap"
]
}
}
28 changes: 14 additions & 14 deletions test/initialization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('Should be able to use native module', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
connectionString: 'postgres://postgres:postgres@localhost/postgres',
native: true
})

Expand All @@ -38,7 +38,7 @@ test('Should be able to use an alternative pg module', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
connectionString: 'postgres://postgres:postgres@localhost/postgres',
pg: altPg
})

Expand All @@ -64,20 +64,20 @@ test('Should not throw if registered within different scopes (with and without n

fastify.register(function scopeOne (instance, opts, next) {
instance.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres'
connectionString: 'postgres://postgres:postgres@localhost/postgres'
})

next()
})

fastify.register(function scopeTwo (instance, opts, next) {
instance.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
connectionString: 'postgres://postgres:postgres@localhost/postgres',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can use .env to load those up? I think locally it could be different. It would also be different if Docker is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same locally as well. I updated to docker commands

name: 'one'
})

instance.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
connectionString: 'postgres://postgres:postgres@localhost/postgres',
name: 'two'
})

Expand All @@ -97,11 +97,11 @@ test('Should throw when trying to register multiple instances without giving a n
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres'
connectionString: 'postgres://postgres:postgres@localhost/postgres'
})

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres'
connectionString: 'postgres://postgres:postgres@localhost/postgres'
})

fastify.ready((err) => {
Expand All @@ -119,13 +119,13 @@ test('Should throw when trying to register duplicate connection names', (t) => {

fastify
.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
name
})
.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
connectionString: 'postgres://postgres:postgres@localhost/postgres',
name
})
fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres:postgres@localhost/postgres',
name
})

fastify.ready((err) => {
t.ok(err)
Expand All @@ -140,7 +140,7 @@ test('fastify.pg namespace should exist', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres'
connectionString: 'postgres://postgres:postgres@localhost/postgres'
})

fastify.ready((err) => {
Expand All @@ -160,7 +160,7 @@ test('fastify.pg.test namespace should exist', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
connectionString: 'postgres://postgres:postgres@localhost/postgres',
name: 'test'
})

Expand Down
20 changes: 10 additions & 10 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('When fastify.pg root namespace is used:', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres'
connectionString: 'postgres://postgres:postgres@localhost/postgres'
})

fastify.ready((err) => {
Expand All @@ -40,7 +40,7 @@ test('When fastify.pg root namespace is used:', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres'
connectionString: 'postgres://postgres:postgres@localhost/postgres'
})

fastify.ready((err) => {
Expand All @@ -60,7 +60,7 @@ test('When fastify.pg root namespace is used:', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres'
connectionString: 'postgres://postgres:postgres@localhost/postgres'
})

fastify.ready((err) => {
Expand Down Expand Up @@ -88,7 +88,7 @@ test('When fastify.pg root namespace is used:', (t) => {
const DB_NAME = 'database_that_do_not_exist'

fastify.register(fastifyPostgres, {
connectionString: `postgres://postgres@localhost/${DB_NAME}`
connectionString: `postgres://postgres:postgres@localhost/${DB_NAME}`
})

fastify.ready((err) => {
Expand All @@ -112,7 +112,7 @@ test('When fastify.pg root namespace is used:', (t) => {
const DB_NAME = 'database_that_do_not_exist'

fastify.register(fastifyPostgres, {
connectionString: `postgres://postgres@localhost/${DB_NAME}`
connectionString: `postgres://postgres:postgres@localhost/${DB_NAME}`
})

fastify.ready((err) => {
Expand Down Expand Up @@ -141,7 +141,7 @@ test('When fastify.pg.test namespace is used:', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
connectionString: 'postgres://postgres:postgres@localhost/postgres',
name: 'test'
})

Expand All @@ -167,7 +167,7 @@ test('When fastify.pg.test namespace is used:', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
connectionString: 'postgres://postgres:postgres@localhost/postgres',
name: 'test'
})

Expand All @@ -187,7 +187,7 @@ test('When fastify.pg.test namespace is used:', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
connectionString: 'postgres://postgres:postgres@localhost/postgres',
name: 'test'
})

Expand All @@ -212,7 +212,7 @@ test('When fastify.pg.test namespace is used:', (t) => {
t.teardown(() => fastify.close())

fastify.register(fastifyPostgres, {
connectionString: 'postgres://postgres@localhost/postgres',
connectionString: 'postgres://postgres:postgres@localhost/postgres',
name: 'test',
native: true
})
Expand Down Expand Up @@ -240,7 +240,7 @@ test('When fastify.pg.test namespace is used:', (t) => {
const DB_NAME = 'database_that_do_not_exist'

fastify.register(fastifyPostgres, {
connectionString: `postgres://postgres@localhost/${DB_NAME}`,
connectionString: `postgres://postgres:postgres@localhost/${DB_NAME}`,
name: 'test'
})

Expand Down
Loading