Code Monkey home page Code Monkey logo

fastify-mssql's Introduction

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

fastify-mssql's People

Contributors

bredikhin avatar davideroffo avatar dependabot[bot] avatar eomm avatar gilach avatar github-actions[bot] avatar grantmorrison avatar ilteoood avatar jhonrocha avatar jimmymintzer avatar leorossi avatar mahenrique94 avatar marten-cz avatar melkornemesis avatar nstratton-lfa avatar optic-release-automation[bot] avatar sameer-coder avatar simoneb avatar williamlines avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastify-mssql's Issues

Release pending!

Pending commits since release v1.2.0

Based on the following commits, a patch release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • 239094a Merge pull request #72 from nearform/fix-switch-optic-release-automation-action-org
  • 86e77b0 switch the org for optic-release-automation-action

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Release pending!

Pending commits since release v2.0.0

Based on the following commits, a patch release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • f671803 chore(deps-dev): bump @types/mssql from 8.1.2 to 9.1.1 (#99)
  • be97822 chore(deps-dev): bump mssql from 9.3.2 to 10.0.0 (#95)
  • 8d627c4 chore(deps): bump actions/checkout from 3 to 4 (#94)
  • 97bb9aa Merge pull request #91 from nearform/dependabot/npm_and_yarn/prettier-3.0.2
  • 68c05fa chore: upgrade eslint prettier plugin
  • 137f1ec chore(deps-dev): bump prettier from 2.8.8 to 3.0.2
  • 8e97add chore(deps-dev): bump eslint-config-prettier from 8.10.0 to 9.0.0 (#89)

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Feature Request: Add `decorate` Property to MSSQL Plugin Configuration

Feature Request: Add decorate Property to MSSQL Plugin Configuration

Description:

I would like to propose an enhancement to the MSSQL plugin for Fastify. This enhancement involves adding a decorate property to the plugin's configuration options. This new property would allow users to customize the name used to decorate the Fastify instance with the MSSQL pool and types.

Motivation:

Currently, the MSSQL plugin decorates the Fastify instance with a hardcoded name ('mssql'). This can lead to potential naming conflicts and limits the flexibility for users who might want to use multiple instances of the plugin with different configurations. By allowing customization of the decoration name, users will have more control and flexibility over their Fastify instance as well as multiple database connection can be using in parallel.

Proposed Solution:

  • Add a decorate property to the defaults object in the plugin configuration.
  • Update the fastify.decorate method to use the value of connectionConfig.decorate.

Benefits:

  • Prevents potential naming conflicts.
  • Allows for greater flexibility and control for users.
  • Enables the use of multiple instances of the plugin with different configurations.

Potential Issues:

No major issues anticipated. The default behavior remains unchanged, ensuring backward compatibility. Users who do not specify the decorate property will still have their Fastify instance decorated with the default name ('mssql').

Additional Context:

This enhancement would be particularly useful in complex applications where multiple database connections or plugins are in use. Customizing the decoration name can help keep the Fastify instance organized and free of naming conflicts.

Release pending!

Pending commits since release v1.1.0

Unreleased commits have been found which are pending release, please publish the changes.

  • 06e88f0 chore(deps): bump nearform/github-action-notify-release (#31)
  • 9ffcd9b Merge pull request #30 from nearform/dependabot/github_actions/fastify/github-action-merge-dependabot-2.1.1
  • e21ccec chore(deps): bump nearform/github-action-notify-release (#29)
  • 1a44648 chore(deps): bump fastify/github-action-merge-dependabot
  • 4b4bc6b chore(deps): bump nearform/github-action-notify-release (#28)
  • ac9d138 Merge pull request #27 from nearform/dependabot/github_actions/fastify/github-action-merge-dependabot-2.1.0
  • 2ab0b20 chore(deps): bump fastify/github-action-merge-dependabot
  • 5b16d6e chore: solidify notify-release version
  • 2131297 chore(deps-dev): bump jest from 26.6.3 to 27.0.1 (#26)
  • 4307c1c ci: fix notify-release workflow dispatch branch
  • 4e3c01d chore: add package-lock.json to .gitignore
  • 36f9212 docs: readme formatting
  • 4253a49 Merge branch 'master' of https://github.com/nearform/fastify-mssql
  • cd59b5b Bumped v1.1.0

Issue generated by github-actions-notify-release.

Release pending!

Pending commits since release v1.2.0

Based on the following commits, a patch release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • ef1749b Merge pull request #74 from nearform/fix-notify-release-permissions
  • 3675f5b ci: update notify-release action permissions
  • 239094a Merge pull request #72 from nearform/fix-switch-optic-release-automation-action-org
  • 86e77b0 switch the org for optic-release-automation-action

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Connect sqlexpress

Hi all,
i have used this plugin for connect to my MSSQL Server on docker and work fine, when i try to connect a SQLExpress istance i have an error

json {"statusCode":500,"code":"ESOCKET","error":"Internal Server Error","message":"Failed to connect to localhost:1433 - 15468:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:c:\\ws\\deps\\openssl\\openssl\\ssl\\statem\\statem_lib.c:1994:\n"}

On server there is another application that connect with ODBC, can i use the same method with plugin?

Thanks

Release pending!

Pending commits since release v2.0.0

Based on the following commits, a patch release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • 97bb9aa Merge pull request #91 from nearform/dependabot/npm_and_yarn/prettier-3.0.2
  • 68c05fa chore: upgrade eslint prettier plugin
  • 137f1ec chore(deps-dev): bump prettier from 2.8.8 to 3.0.2
  • 8e97add chore(deps-dev): bump eslint-config-prettier from 8.10.0 to 9.0.0 (#89)

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Release pending!

Pending commits since release v1.2.0

Based on the following commits, a patch release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • ef1749b Merge pull request #74 from nearform/fix-notify-release-permissions
  • 3675f5b ci: update notify-release action permissions
  • 239094a Merge pull request #72 from nearform/fix-switch-optic-release-automation-action-org
  • 86e77b0 switch the org for optic-release-automation-action

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Release pending!

Pending commits since release v2.0.0

Based on the following commits, a patch release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • 97bb9aa Merge pull request #91 from nearform/dependabot/npm_and_yarn/prettier-3.0.2
  • 68c05fa chore: upgrade eslint prettier plugin
  • 137f1ec chore(deps-dev): bump prettier from 2.8.8 to 3.0.2
  • 8e97add chore(deps-dev): bump eslint-config-prettier from 8.10.0 to 9.0.0 (#89)

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Enable NPM Provenance

Integration with beta NPM Provenance integration when publishing new versions to NPM registry.

Release pending!

Pending commits since release v1.2.0

Based on the following commits, a patch release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • ef1749b Merge pull request #74 from nearform/fix-notify-release-permissions
  • 3675f5b ci: update notify-release action permissions
  • 239094a Merge pull request #72 from nearform/fix-switch-optic-release-automation-action-org
  • 86e77b0 switch the org for optic-release-automation-action

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Use server not host in sample

app.register(mssqlPlugin, {
  host: 'my-host',

should be

app.register(mssqlPlugin, {
  server: 'my-host',

Otherwise you get cannot connect to localhost.

Release pending!

Pending commits since release v1.2.1

Based on the following commits, a patch release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • 6172fa5 Merge pull request #83 from marten-cz/feature/types
  • 73ec5ef Add instructions to install mssql dependency to project
  • 0479f25 Use option interface from parent mssql package

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Release pending!

Pending commits since release v1.1.1

Based on the following commits, a minor release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • 26ffc01 Merge pull request #69 from nearform/chore/update-notify-release-action-config
  • f5de5ff feat: update notify-release config
  • 0c6f187 Merge pull request #67 from nearform/update-notify-release-workflow
  • 019d182 chore: release trigger added to notify-release workflow
  • 3fe760b Merge pull request #66 from ilteoood/patch-1
  • 65fc4c6 restore version
  • 7403fcc Create .nvmrc
  • 46e5eaa Update ci.yaml
  • 47d4004 chore(deps-dev): bump @types/jest from 28.1.8 to 29.0.0 (#65)
  • 4b4591c chore(deps-dev): bump jest from 28.1.3 to 29.0.0 (#64)
  • 71701c3 chore(deps-dev): bump mssql from 8.1.4 to 9.0.1 (#63)
  • b894956 chore(deps): bump fastify-plugin from 3.0.1 to 4.1.0 (#61)
  • c4db02c chore(deps-dev): bump fastify from 3.29.0 to 4.0.0 (#59)
  • 789113e chore(deps-dev): bump @types/jest from 27.5.2 to 28.1.0 (#58)
  • 9cbd5d4 chore(deps-dev): bump @types/mssql from 7.1.5 to 8.0.0 (#57)
  • 3250f8e chore(deps-dev): bump jest from 27.5.1 to 28.0.0 (#56)
  • c89d295 chore(deps): bump actions/checkout from 2.4.0 to 3 (#55)
  • ce2a61e Merge pull request #54 from nearform/dependabot/npm_and_yarn/mssql-8.0.1
  • 75d169e chore: remove automerge target minor for consistency
  • ed70aaf chore(deps-dev): bump mssql from 7.3.0 to 8.0.1
  • 585a8a4 chore: upgrade github-action-merge-dependabot to v3 (#53)
  • 4e40ed0 feat: sqlTypes decorator (#51)
  • 3c1f1c5 chore: use major version of notify release action
  • d11bf62 chore(deps): bump nearform/github-action-notify-release (#52)
  • cf14df3 chore(deps): bump fastify/github-action-merge-dependabot (#48)
  • 0ed6130 chore(deps): bump fastify/github-action-merge-dependabot (#47)
  • c6c253e chore(deps): bump fastify/github-action-merge-dependabot (#46)
  • 8e0f525 Merge pull request #45 from nearform/dependabot/github_actions/actions/checkout-2.4.0
  • 083e63a chore(deps): bump actions/checkout from 2.3.5 to 2.4.0
  • 16a7780 chore(deps): bump actions/checkout from 2.3.4 to 2.3.5 (#44)

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

I believe something happened to the TYPES system

fastify-mssql V1.1.1
mssql V 7.3.0

I have the following route in Fastify

 fastify.get('/details/:userID', schema.status_array, async (request, reply) => {
        try {
            
            let pool = await fastify.mssql.pool.connect();
            
            let query = 'Select * from app.EngaugeUsers where userid=@userID';
            const res = await pool.request()
            .input('userID', pool.Int , request.params.userID)
            .query(query);
            return {status: "ok", data: res.recordset};
        } catch (err) {
            console.log(err);
            return {status:'error', data: [err.message] };
        }
  });

The request fails with a message of
TypeError: Cannot read property 'type' of undefined
at Request.input (C:\Users\mprie\Documents\Fastify\EmployeePortal\Test1\node_modules\mssql\lib\base\request.js:134:18)

If I take the pool.Int parameter in .input() it works fine, see below.

fastify.get('/details/:userID', schema.status_array, async (request, reply) => {
        try {
            
            let pool = await fastify.mssql.pool.connect();
            
            let query = 'Select * from app.users where userid=@userID';
            const res = await pool.request()
            .input('userID',request.params.userID)
            .query(query);
            return {status: "ok", data: res.recordset};
        } catch (err) {
            console.log(err);
            return {status:'error', data: [err.message] };
        }
    });

Release pending!

Pending commits since release v2.0.0

Based on the following commits, a patch release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • be97822 chore(deps-dev): bump mssql from 9.3.2 to 10.0.0 (#95)
  • 8d627c4 chore(deps): bump actions/checkout from 3 to 4 (#94)
  • 97bb9aa Merge pull request #91 from nearform/dependabot/npm_and_yarn/prettier-3.0.2
  • 68c05fa chore: upgrade eslint prettier plugin
  • 137f1ec chore(deps-dev): bump prettier from 2.8.8 to 3.0.2
  • 8e97add chore(deps-dev): bump eslint-config-prettier from 8.10.0 to 9.0.0 (#89)

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Release pending!

Pending commits since release v2.0.0

Unreleased commits have been found which are pending release, please publish the changes.

  • be97822 chore(deps-dev): bump mssql from 9.3.2 to 10.0.0 (#95)
  • 8d627c4 chore(deps): bump actions/checkout from 3 to 4 (#94)
  • 97bb9aa Merge pull request #91 from nearform/dependabot/npm_and_yarn/prettier-3.0.2
  • 68c05fa chore: upgrade eslint prettier plugin
  • 137f1ec chore(deps-dev): bump prettier from 2.8.8 to 3.0.2
  • 8e97add chore(deps-dev): bump eslint-config-prettier from 8.10.0 to 9.0.0 (#89)

Issue generated by github-actions-notify-release.

Release pending!

Pending commits since release v2.0.0

Based on the following commits, a patch release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • 8e97add chore(deps-dev): bump eslint-config-prettier from 8.10.0 to 9.0.0 (#89)

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.