diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a05045..1ed9c7e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,11 @@ name: CI on: push: + branches: + - main + - master + - next + - 'v*' paths-ignore: - 'docs/**' - '*.md' diff --git a/.gitignore b/.gitignore index c1b9a5c..3c21249 100644 --- a/.gitignore +++ b/.gitignore @@ -135,11 +135,15 @@ dist # macOS files .DS_Store +# Clinic +.clinic + # lock files +bun.lockb package-lock.json pnpm-lock.yaml yarn.lock # editor files .vscode -.idea \ No newline at end of file +.idea diff --git a/README.md b/README.md index 1ddc7d6..acd70b1 100644 --- a/README.md +++ b/README.md @@ -297,7 +297,7 @@ $ npm test ### Custom Postgres approach -1. Set up a database of your choice oin a postgres server of your choice +1. Set up a database of your choice in a postgres server of your choice 2. Create the required table using ```sql CREATE TABLE users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL); diff --git a/index.js b/index.js index 8add88a..1c5162f 100644 --- a/index.js +++ b/index.js @@ -161,7 +161,7 @@ function fastifyPostgres (fastify, options, next) { } } - client.query('BEGIN') + await client.query('BEGIN') } const onError = (req, reply, error, done) => { diff --git a/package.json b/package.json index 52af880..3be7ef9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fastify/postgres", - "version": "5.2.0", + "version": "5.2.1", "description": "Fastify PostgreSQL connection plugin", "main": "index.js", "types": "index.d.ts", @@ -45,8 +45,8 @@ "pg-native": "^3.0.0", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.25.0", - "typescript": "^4.4.3" + "tsd": "^0.29.0", + "typescript": "^5.0.2" }, "peerDependencies": { "pg": ">=6.0.0" diff --git a/test/helpers.js b/test/helpers.js index c068533..4bf3558 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -1,7 +1,7 @@ 'use strict' const BAD_DB_NAME = 'db_that_does_not_exist' -const connectionString = process.env.DATABASE_TEST_URL || 'postgres://postgres:postgres@localhost/postgres' +const connectionString = process.env.DATABASE_TEST_URL || 'postgres://postgres:postgres@127.0.0.1/postgres' const connectionStringBadDbName = connectionString.replace(/\/[^/]+$/, '/' + BAD_DB_NAME) module.exports = Object.freeze({ diff --git a/test/req-initialization.test.js b/test/req-initialization.test.js index 5bf23e2..5a11b6f 100644 --- a/test/req-initialization.test.js +++ b/test/req-initialization.test.js @@ -16,7 +16,7 @@ test('When we use the fastify-postgres transaction route option', t => { connectionString }) - await fastify.pg.query('TRUNCATE users') + await fastify.pg.query('DELETE FROM "users" WHERE TRUE') fastify.get('/count-users', async (req, reply) => { const result = await fastify.pg.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'pass-opt-in\'') @@ -49,7 +49,7 @@ test('When we use the fastify-postgres transaction route option', t => { name: 'test' }) - await fastify.pg.test.query('TRUNCATE users') + await fastify.pg.test.query('DELETE FROM "users" WHERE TRUE') fastify.get('/count-users', async (req, reply) => { const result = await fastify.pg.test.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'pass-opt-in\'') @@ -82,7 +82,7 @@ test('When we use the fastify-postgres transaction route option', t => { connectionString }) - await fastify.pg.query('TRUNCATE users') + await fastify.pg.query('DELETE FROM "users" WHERE TRUE') fastify.get('/count-users', async (req, reply) => { const result = await fastify.pg.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'fail-opt-in\'') @@ -117,7 +117,7 @@ test('When we use the fastify-postgres transaction route option', t => { name: 'test' }) - await fastify.pg.test.query('TRUNCATE users') + await fastify.pg.test.query('DELETE FROM "users" WHERE TRUE') fastify.get('/count-users', async (req, reply) => { const result = await fastify.pg.test.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'fail-opt-in\'') diff --git a/test/transaction.test.js b/test/transaction.test.js index 3f9d4cb..de636d6 100644 --- a/test/transaction.test.js +++ b/test/transaction.test.js @@ -13,7 +13,7 @@ const { test('When fastify.pg root namespace is used:', (t) => { t.test('Should be able to use transact util with a callback', (t) => { - t.plan(3) + t.plan(4) const fastify = Fastify() t.teardown(() => fastify.close())