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
Installation
npm install fastify-knex-pluginor
yarn add fastify-knex-pluginUsage
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
License
Licensed under MIT.
