Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .taprc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
jobs: 1
jsx: false
esm: false
ts: false
flow: false
86 changes: 43 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"name": "fastify-mysql",
"version": "2.1.0",
"description": "Fastify Mysql connection plugin",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"mariadb": "docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --rm mariadb:10.1",
"mysql": "npm run mysql:8.0",
"mysql:5.7": "docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --rm mysql:5.7",
"mysql:5.5": "docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --rm mysql:5.5",
"mysql:8.0": "docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --rm mysql:8.0",
"test": "standard && tap test/*.test.js && npm run typescript",
"typescript": "tsd"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fastify/fastify-mysql.git"
},
"keywords": [
"fastify",
"mysql",
"database",
"connection",
"sql"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/fastify/fastify-mysql/issues"
},
"homepage": "https://github.com/fastify/fastify-mysql#readme",
"dependencies": {
"fastify-plugin": "^3.0.0",
"mysql2": "^2.0.0"
},
"devDependencies": {
"@types/node": "^14.14.21",
"fastify": "^3.0.0",
"standard": "^16.0.0",
"tap": "^14.10.7",
"tsd": "^0.14.0"
}
}
{
"name": "fastify-mysql",
"version": "2.1.0",
"description": "Fastify Mysql connection plugin",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"mariadb": "docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --rm mariadb:10.1",
"mysql": "npm run mysql:8.0",
"mysql:5.7": "docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --rm mysql:5.7",
"mysql:5.5": "docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --rm mysql:5.5",
"mysql:8.0": "docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --rm mysql:8.0",
"test": "standard && tap test/*.test.js && npm run typescript",
"typescript": "tsd"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fastify/fastify-mysql.git"
},
"keywords": [
"fastify",
"mysql",
"database",
"connection",
"sql"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/fastify/fastify-mysql/issues"
},
"homepage": "https://github.com/fastify/fastify-mysql#readme",
"dependencies": {
"fastify-plugin": "^3.0.0",
"mysql2": "^2.0.0"
},
"devDependencies": {
"@types/node": "^14.14.21",
"fastify": "^3.0.0",
"standard": "^16.0.0",
"tap": "^15.0.1",
"tsd": "^0.14.0"
}
}
23 changes: 9 additions & 14 deletions test/connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,18 @@ test('fastify.mysql namespace should exist', (t) => {

test('utils should work', (t) => {
let fastify = null
t.beforeEach((done) => {
t.beforeEach(() => {
fastify = Fastify()

fastify.register(fastifyMysql, {
type: 'connection',
connectionString: 'mysql://root@localhost/mysql'
})

done()
})

t.afterEach((done) => {
t.afterEach(() => {
fastify.close()
fastify = null
done()
})

t.test('query util', (t) => {
Expand Down Expand Up @@ -83,7 +80,7 @@ test('utils should work', (t) => {
t.error(err)

const sqlString = fastify.mysql.format('SELECT ? AS `now`', [1])
t.is('SELECT 1 AS `now`', sqlString)
t.equal('SELECT 1 AS `now`', sqlString)
t.end()
})
})
Expand All @@ -94,7 +91,7 @@ test('utils should work', (t) => {

const id = 'userId'
const sql = 'SELECT * FROM users WHERE id = ' + fastify.mysql.escape(id)
t.is(sql, `SELECT * FROM users WHERE id = '${id}'`)
t.equal(sql, `SELECT * FROM users WHERE id = '${id}'`)
t.end()
})
})
Expand All @@ -115,20 +112,18 @@ test('utils should work', (t) => {

test('promise connection', (t) => {
let fastify = null
t.beforeEach((done) => {
t.beforeEach(() => {
fastify = Fastify()

fastify.register(fastifyMysql, {
promise: true,
type: 'connection',
connectionString: 'mysql://root@localhost/mysql'
})
done()
})
t.afterEach((done) => {
t.afterEach(() => {
fastify.close()
fastify = null
done()
})

t.test('query util', (t) => {
Expand Down Expand Up @@ -162,7 +157,7 @@ test('promise connection', (t) => {
t.error(err)

const sqlString = fastify.mysql.format('SELECT ? AS `now`', [1])
t.is('SELECT 1 AS `now`', sqlString)
t.equal('SELECT 1 AS `now`', sqlString)
t.end()
})
})
Expand All @@ -173,7 +168,7 @@ test('promise connection', (t) => {

const id = 'userId'
const sql = 'SELECT * FROM users WHERE id = ' + fastify.mysql.escape(id)
t.is(sql, `SELECT * FROM users WHERE id = '${id}'`)
t.equal(sql, `SELECT * FROM users WHERE id = '${id}'`)
t.end()
})
})
Expand Down Expand Up @@ -225,7 +220,7 @@ test('Promise: should throw when mysql2 fail to perform operation', (t) => {

fastify.mysql.test.connection.query(sql).catch((errors) => {
t.ok(errors)
t.is(errors.message, "Table 'mysql.fastify' doesn't exist")
t.equal(errors.message, "Table 'mysql.fastify' doesn't exist")
})
})
})
14 changes: 7 additions & 7 deletions test/initialization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('Should throw when trying to register multiple instances without giving a n

fastify.ready((errors) => {
t.ok(errors)
t.is(errors.message, 'fastify-mysql has already been registered')
t.equal(errors.message, 'fastify-mysql has already been registered')
})
})

Expand All @@ -77,7 +77,7 @@ test('Should throw with duplicate connection names', (t) => {

fastify.ready((errors) => {
t.ok(errors)
t.is(errors.message, `fastify-mysql '${name}' instance name has already been registered`)
t.equal(errors.message, `fastify-mysql '${name}' instance name has already been registered`)
})
})

Expand All @@ -98,7 +98,7 @@ test('Should throw when mysql2 fail', (t) => {

fastify.ready((errors) => {
t.ok(errors)
t.is(errors.message, `connect ECONNREFUSED ${HOST}:${BAD_PORT}`)
t.equal(errors.message, `connect ECONNREFUSED ${HOST}:${BAD_PORT}`)
})
})

Expand All @@ -120,7 +120,7 @@ test('Promise: Should throw when mysql2 fail', (t) => {

fastify.ready((errors) => {
t.ok(errors)
t.is(errors.message, `connect ECONNREFUSED ${HOST}:${BAD_PORT}`)
t.equal(errors.message, `connect ECONNREFUSED ${HOST}:${BAD_PORT}`)
})
})

Expand All @@ -143,7 +143,7 @@ test('Connection - Promise: Should throw when mysql2 fail', (t) => {

fastify.ready((errors) => {
t.ok(errors)
t.is(errors.message, `connect ECONNREFUSED ${HOST}:${BAD_PORT}`)
t.equal(errors.message, `connect ECONNREFUSED ${HOST}:${BAD_PORT}`)
t.pass()
})
})
Expand All @@ -164,7 +164,7 @@ test('Promise - Should throw when trying to register multiple instances without

fastify.ready((errors) => {
t.ok(errors)
t.is(errors.message, 'fastify-mysql has already been registered')
t.equal(errors.message, 'fastify-mysql has already been registered')
t.pass()
})
})
Expand All @@ -188,7 +188,7 @@ test('Promise - Should throw with duplicate connection names', (t) => {

fastify.ready((errors) => {
t.ok(errors)
t.is(errors.message, `fastify-mysql '${name}' instance name has already been registered`)
t.equal(errors.message, `fastify-mysql '${name}' instance name has already been registered`)
t.pass()
})
})
6 changes: 2 additions & 4 deletions test/pool.promise.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fastifyMysql = require('../index')
test('promise pool', (t) => {
let fastify

t.beforeEach((done) => {
t.beforeEach(() => {
fastify = Fastify()
fastify.register(fastifyMysql, {
promise: true,
Expand All @@ -16,12 +16,10 @@ test('promise pool', (t) => {
database: 'mysql',
connectionLimit: 1
})
done()
})

t.afterEach((done) => {
t.afterEach(() => {
fastify.close()
done()
})

t.test('mysql.pool.query', (t) => {
Expand Down
4 changes: 2 additions & 2 deletions test/pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ test('synchronous functions', (t) => {

test('mysql.format', (t) => {
const sqlString = fastify.mysql.format('SELECT ? AS `now`', [1])
t.is('SELECT 1 AS `now`', sqlString)
t.equal('SELECT 1 AS `now`', sqlString)
t.end()
})

test('mysql.escape', (t) => {
const id = 'userId'
const sql = 'SELECT * FROM users WHERE id = ' + fastify.mysql.escape(id)
t.is(sql, `SELECT * FROM users WHERE id = '${id}'`)
t.equal(sql, `SELECT * FROM users WHERE id = '${id}'`)
t.end()
})

Expand Down