Registry / database / hapi-sequelizejs

hapi-sequelizejs

JSON →
library4.6.1jsnpmunverified

hapi-sequelizejs is a hapi.js plugin (v4.6.1) that integrates the Sequelize ORM (versions 5.x or 6.x) as a server plugin, supporting multiple database connections. It decorates the request object with a getDb method and automatically loads model associations. Compatible with hapi.js 19.x, 20.x, and @hapi/hapi 21.x. Development appears to be in maintenance mode with infrequent updates; no known active development since 2021. Key differentiator is its tight integration with hapi's plugin system, allowing multiple database instances and automatic model syncing.

npm install hapi-sequelizejs
INSTALL
IMPORT
SIG · HAPI-SEQUELIZEJS
H
hapi-sequelizejs
databasejavascriptv4.6.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin
await server.register({ plugin: require('hapi-sequelizejs'), options: [...] })
const HapiSequelize = require('hapi-sequelizejs'); await server.register(HapiSequelize, options)
Must pass plugin object with options array; cannot register directly with the plugin as second argument.
getDb
request.getDb('dbname')
request.getDb() without name when multiple databases are registered
getDb throws if name not found. If only one database is registered, calling without name returns that single instance. For multiple databases, name is required.
db.getModel
const model = request.getDb('dbname').getModel('User')
request.getDb('dbname').models.User (works but bypasses getModel null safety)
getModel returns null if model not found; direct models access may throw.

Registers hapi-sequelizejs with a Sequelize instance, syncs models, and uses getDb in a route handler.

const Hapi = require('@hapi/hapi'); const Sequelize = require('sequelize'); const init = async () => { const server = Hapi.server({ port: 3000 }); const sequelize = new Sequelize('database', 'username', 'password', { host: 'localhost', dialect: 'sqlite' // or 'postgres', 'mysql' }); await server.register({ plugin: require('hapi-sequelizejs'), options: [{ name: 'mydb', models: ['/models/**/*.js'], sequelize: sequelize, sync: true }] }); server.route({ method: 'GET', path: '/users', handler: (request, h) => { const db = request.getDb('mydb'); return db.models.User.findAll(); } }); await server.start(); console.log('Server running on %s', server.info.uri); }; init().catch(err => console.error(err));
Debug
Known issues
breakinghapi-sequelizejs v4 drops support for hapi v17 and v18; only supports @hapi/hapi 19.x and 20.x.
fix
Upgrade to @hapi/hapi 19.x or 20.x.
affects: >=4.0.0
gotchagetDb throws an error if the database name is not found: 'hapi-sequelizejs cannot find the ${dbName} database instance'.
fix
Ensure the name passed to getDb matches the name property in the options array.
affects: >=3.0.0
gotchaModel definitions must export a function that returns the Sequelize model; the function receives (sequelize, DataTypes). Not doing so causes silent failures.
fix
Use module.exports = function(sequelize, DataTypes) { return sequelize.define(...); };
affects: *
deprecatedThe package is in maintenance mode; no active development since 2021.
fix
Consider alternatives like @hapipal/schwifty or manual integration.
affects: >=4.0.0
Errors
Common errors & fixes
Error: hapi-sequelizejs cannot find the mydb database instance
getDb('mydb') called but the database name 'mydb' was not registered in options.
fix
Check that the 'name' in options array matches the argument to getDb. Also ensure options is an array even for single database.
TypeError: Cannot read properties of undefined (reading 'Sequelize')
sequelize instance not properly passed; options.sequelize is undefined.
fix
Make sure options[0].sequelize is a valid Sequelize instance (new Sequelize(...)).
Model is not defined
Model file exports a plain object instead of a function that returns the model definition.
fix
Wrap model definition in module.exports = function(sequelize, DataTypes) { return sequelize.define(...); };
Upgrade
Version history
4.6.1latest on npm
Audit
Dependencies
sequelizerequiredPeer dependency: hapi-sequelizejs requires Sequelize ORM (5.x or 6.x) to function.
@hapi/hapirequiredPeer dependency: requires hapi.js 19.x, 20.x, or 21.x.
Agent activity
8 hits · last 30 days
node
8
Resources
hapi-sequelizejs — npm install hapi-sequelizejs · libregistry