fastify-mssql
Advanced tools
Comparing version 1.1.1 to 1.2.0
{ | ||
"name": "fastify-mssql", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Fastify Plugin to manage MSSQL connections", | ||
@@ -37,14 +37,14 @@ "main": "plugin.js", | ||
"dependencies": { | ||
"fastify-plugin": "^3.0.0" | ||
"fastify-plugin": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.20", | ||
"@types/mssql": "^6.0.7", | ||
"eslint": "^7.27.0", | ||
"@types/jest": "^29.0.0", | ||
"@types/mssql": "^8.0.0", | ||
"eslint": "^8.0.1", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.23.3", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"fastify": "^3.11.0", | ||
"jest": "^27.0.1", | ||
"mssql": "^7.1.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"fastify": "^4.0.0", | ||
"jest": "^29.0.0", | ||
"mssql": "^9.0.1", | ||
"prettier": "^2.3.0" | ||
@@ -51,0 +51,0 @@ }, |
@@ -26,3 +26,6 @@ 'use strict' | ||
}) | ||
fastify.decorate('mssql', { pool }) | ||
fastify.decorate('mssql', { | ||
pool, | ||
sqlTypes: MSSql | ||
}) | ||
} | ||
@@ -29,0 +32,0 @@ |
@@ -41,1 +41,19 @@ # fastify-mssql | ||
``` | ||
If you need to access the [SQL Data Types](https://github.com/tediousjs/node-mssql#data-types) you can access them by using the `mssql.sqlTypes` property: | ||
```js | ||
app.get('/users/:userId', async function (request) { | ||
try { | ||
const pool = await app.mssql.pool.connect() | ||
const query = 'SELECT * FROM users where id=@userID' | ||
const res = await pool | ||
.request() | ||
.input('userID', app.mssql.sqlTypes.Int, request.params.userId) | ||
.query(query) | ||
return { user: res.recordset } | ||
} catch (err) { | ||
return { error: err.message } | ||
} | ||
}) | ||
``` |
@@ -56,12 +56,39 @@ const buildServer = require('./build-server') | ||
}) | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/users' | ||
app.get('/users/:userId', async function (request) { | ||
try { | ||
const pool = await app.mssql.pool.connect() | ||
const query = 'SELECT * FROM [dbo].[Users] where id=@userID;' | ||
const res = await pool | ||
.request() | ||
.input('userID', app.mssql.sqlTypes.Int, request.params.userId) | ||
.query(query) | ||
return { user: res.recordset } | ||
} catch (err) { | ||
return { error: err.message } | ||
} | ||
}) | ||
const body = JSON.parse(response.body) | ||
expect(app.mssql.pool).not.toBe(undefined) | ||
expect(response.statusCode).toBe(200) | ||
expect(body.users.length).toBe(2) | ||
{ | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/users' | ||
}) | ||
const body = JSON.parse(response.body) | ||
expect(app.mssql.pool).not.toBe(undefined) | ||
expect(response.statusCode).toBe(200) | ||
expect(body.users.length).toBe(2) | ||
} | ||
{ | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/users/2' | ||
}) | ||
expect(response.statusCode).toBe(200) | ||
expect(response.json()).toEqual({ | ||
user: [{ id: '2', name: 'fizzbuzz', email: 'fizzbuzz@gmail.com' }] | ||
}) | ||
} | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
16223
19
171
59
0
+ Addedfastify-plugin@4.5.1(transitive)
- Removedfastify-plugin@3.0.1(transitive)
Updatedfastify-plugin@^4.1.0