fastify-knex-plugin

1.0.3 • Public • Published

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.

Package Sidebar

Install

npm i fastify-knex-plugin

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

3.47 kB

Total Files

4

Last publish

Collaborators

  • beyazatli