@voom/bank

0.2.1 • Public • Published

@voom/bank

Knex wrapper for Hapi.

This plugin exposes a bank instance within your server.

The following operations can be performed automatically:

  • Check the database connection on server startup and throw an error if the database is unreachable.
  • Run database migrations on server startup.
  • Destroy the database connection on server shutdown.

This plugin will also convert the columns case between code and database.

Installation

npm install @voom/bank

Usage

const Hapi = require('@hapi/hapi')
const Bank = require('@voom/bank')

async function start () {
  const server = Hapi.Server()

  await server.register({
    plugin: Bank,
    options: {
      client: 'mysql', // postgres, sqlite3, ...
      connection: {
        // ...
      },
      migrations: {
        // ...
      },
      seeds: {
        // ...
      },
      auto: {
        connect: true,
        migrate: false,
        destroy: true
      },
      case: {
        software: 'camelcase',
        database: 'snakecase'
      }
    }
  })

  await server.start()

  const user = await server.bank() // or request.bank()
    .table('users')
    .where('id', 1)
    .first()
}

start()

Package Sidebar

Install

npm i @voom/bank

Weekly Downloads

0

Version

0.2.1

License

MIT

Unpacked Size

7.81 kB

Total Files

6

Last publish

Collaborators

  • spridev