JSPM

fastify-knex-plugin

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q41025F
  • License MIT

Fastify KnexJS Plugin

Package Exports

  • fastify-knex-plugin
  • fastify-knex-plugin/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fastify-knex-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Fastify KnexJS Plugin

NPM

Installation

npm install fastify-knex-plugin

or

yarn add fastify-knex-plugin

Usage

const options = {
  client: 'mysql',
  connection: {
    host : '127.0.0.1',
    port : 3306,
    user : 'your_database_user',
    password : 'your_database_password',
    database : 'myapp_test'
  }
}

fastify.register(require('fastify-knex-plugin'), options, (err) =>
  console.error(err)
);

fastify.get('/', (request, reply) => {
  console.log(fastify.knex) // Knex DB instance
})

fastify.get('/getProgrammers', async(request, reply) => {
  // example get
  const programmers = await fastify.knex('users').select('name').where('isProgrammer', true)
  reply.send(programmers)
})

Options

KnexJS DB configuration object:

https://knexjs.org/guide/#configuration-options

Author

Tarik BEYAZATLI

License

Licensed under MIT.