Skip to content

Fastify Knex Plugin for supporting many databases (MySQL, Postgres, Maria, Oracle, MSSQL)

License

Notifications You must be signed in to change notification settings

zuck/fastify-knex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastify-knex

js-standard-style

Fastify Knex connection plugin, this plugin will allow you to use many different relational database wrappers from Knex.

List of supported databases wrapper:

  1. MySQL
  2. PostgreSQL
  3. SQLite
  4. OracleDB
  5. Maria
  6. MS SQL

Under the hood the knex is used, the options that you pass to register will be passed to the Knex object.

Install

npm i fastify-knex --save

Usage

Add it to you project with register and you are done!
This plugin will add the knex namespace in your Fastify instance.

Example

  
  function registerPlugins(fastify, opts, next) {
    fastify.register(require('fastify-knex'), {
      client: 'pg',
      debug: true // Knex debug SQL
      connection: 'psql:https://angel:Som3p@ss@localhost:5432/angel'
    });

    fastify.register(registerRoutes);

    done();
  }

  // Now in your routes
  function registerRoutes(fastify, opts, next) {
    fastify.get('/', async req => {
      // Get Knex object here..
      const users = await fastify.knex.select().from('users');
      return users;
    });
  }

Upcoming TODO

  • Add test cases
  • Add examples

License

Licensed under MIT.

About

Fastify Knex Plugin for supporting many databases (MySQL, Postgres, Maria, Oracle, MSSQL)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%