0.1.1 • Published 6 years ago

rethink-hapi v0.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

#RETHINK-HAPI

An HapiJS plugin for rethinkdb.

This plugin is only compatible with hapijs v17.x.x and uses the rethinkdb official driver.

Installation

yarn add rethink-hapi

If you prefer npm:

npm -i rethink-hapi

Usage

Register the plugin to the server

Obtain a rethinkdb connection

WARNING: Never forget to close the connection via await conn.close().

const Hapi = require('hapi')

const server = Hapi.Server()

// Register the plugin
server.register(require('rethink-hapi'))

// Obtain a connection
async function testRethinkConnection () {
  const {connect, r} = server.plugins['rethink-hapi']
  const conn = await connect()
  const db = await r.dbList().run(conn)
  console.log(db)
  await conn.close()
}

testRethinkConnection()

// TODO: Create demo

Plugin options

  • host: rethinkdb hostname. Default localhost
  • port: rethinkdb port. Default 28015
  • db: database name. Default test
  • username: database username. Default admin
  • password: database user password. Default ''
  • ssl: a hash of options to support SSL connections. Default null

Function and object exposed by rethink-hapi

  • connect: A function used to get a connection.
  • r: The top-level ReQL namespace.