Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-mssql

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-mssql

Fastify Plugin to manage MSSQL connections

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
101
decreased by-44.2%
Maintainers
0
Weekly downloads
 
Created
Source

fastify-mssql

MSSQL Plugin for Fastify.

Installation

npm install fastify-mssql

You will also need to have mssql dependency installed and @types/mssql when you are using TypeScript.

npm install mssql @types/mssql

Usage

Example

const Fastify = require('fastify')
const mssql = require('fastify-mssql')

const app = Fastify()

app.register(mssql, {
  server: 'my-host',
  port: 1433,
  user: 'my-user',
  password: 'my-password',
  database: 'my-database'
})

app.get('/users', async function (req, reply) {
  try {
    await app.mssql.pool.connect();
    const res = await app.mssql.pool.query('SELECT * FROM users');
    return { users: res.recordset }
  } catch (err) {
    return err;
  }
})

app.listen(3000)

If you need to access the SQL Data Types you can access them by using the mssql.sqlTypes property:

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 }
  }
})

Keywords

FAQs

Package last updated on 23 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc