This repository has been archived by the owner on Jan 28, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Fdawgs/feat/sql-connections
Add route functionality
- Loading branch information
Showing
16 changed files
with
963 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const fastifyPlugin = require("fastify-plugin"); | ||
const sql = require("mssql"); | ||
|
||
/** | ||
* @author Frazer Smith | ||
* @description Decorator plugin that adds Microsoft SQL Server client. | ||
* @param {Function} server - Fastify instance. | ||
* @param {object|string} options - mssql configuration values either as an object with options or as a connection string. | ||
* Example connection string: `mssql://username:password@localhost/database`. | ||
* @param {string=} options.user - User name to use for authentication. | ||
* @param {string=} options.password - Password to use for authentication. | ||
* @param {string} options.server - Server to connect to. | ||
* You can use 'localhost\instance' to connect to named instance. | ||
* @param {number=} options.port - Port to connect to (default: `1433`). | ||
* Do not set when connecting to named instance. | ||
* @param {string=} options.domain - Once you set domain, driver will | ||
* connect to SQL Server using domain login. | ||
* @param {string=} options.database - Database to connect to | ||
* (default: dependent on server configuration). | ||
* @param {number=} options.connectionTimeout - Connection timeout in ms | ||
* (default: `15000`). | ||
* @param {number=} options.requestTimeout - Request timeout in ms | ||
* (default: `15000`). | ||
* NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second. | ||
* When passed via connection string, the key must be `request timeout` | ||
* @param {boolean=} options.stream - Stream recordsets/rows instead of returning | ||
* them all at once as an argument of callback (default: `false`). | ||
* You can also enable streaming for each request independently (`request.stream = true`). | ||
* Always set to true if you plan to work with large amount of rows. | ||
* @param {boolean=} options.parseJSON - Parse JSON recordsets to JS objects | ||
* (default: `false`). | ||
* @param {object=} options.pool - See pool options here: https://github.com/vincit/tarn.js/#usage | ||
*/ | ||
async function plugin(server, options) { | ||
const mssql = await sql.connect(options); | ||
|
||
server.decorate("mssql", mssql); | ||
server.addHook("onClose", async (instance, done) => mssql.close(done)); | ||
} | ||
|
||
module.exports = fastifyPlugin(plugin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.