Registry / database / sails-hook-sequelize

sails-hook-sequelize

JSON →
library2.0.1jsnpmunverified

A Sails.js hook that integrates Sequelize ORM as the database layer, replacing the default Waterline ORM. Version 2.0.1 is the latest stable; it requires Node >=12 and supports Sequelize 6+. Unlike Waterline, this hook provides direct access to Sequelize models and associations, enabling complex SQL queries, transactions, and raw database features. It requires disabling the built-in ORM and pubsub hooks, and models must follow a specific structure with an `options` key and optional `associations` function. Released under MIT, maintained by KSDaemon.

npm install sails-hook-sequelize
INSTALL
IMPORT
SIG · SAILS-HOOK-SEQUELI
S
sails-hook-sequelize
databasejavascriptv2.0.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.

sails.config.sequelize
sails.config.sequelize
require('sails-hook-sequelize')
Do not import the hook directly; configure via Sails config files and access Sequelize instance via sails.config.sequelize.
Sequelize (global)
Exposed globally if 'exposeToGlobal' is true in config; otherwise available via sails.config.sequelize.Sequelize
import Sequelize from 'sequelize' in model files
In model files, Sequelize is available as a global variable (or via sails.config.sequelize). Do not import Sequelize separately.
Models (sequelize models)
sails.models.user
require('../models/user')
Models are loaded by the hook and available via sails.models, not by direct require.

Configures Sails to use Sequelize with PostgreSQL, defines a User model, and sets up an association with an Image model.

// .sailsrc { "hooks": { "orm": false, "pubsub": false } } // config/sequelize.js module.exports.sequelize = { exposeToGlobal: true }; // config/connections.js somePostgresqlServer: { user: 'postgres', password: process.env.DB_PASSWORD || '', database: 'sequelize', dialect: 'postgres', options: { dialect: 'postgres', host: 'localhost', port: 5432, logging: console.log } } // models/user.js module.exports = { attributes: { name: { type: Sequelize.STRING, allowNull: false }, age: Sequelize.INTEGER }, associations: function() { user.hasMany(image, { foreignKey: 'owner' }); }, options: { tableName: 'users' }, connection: 'somePostgresqlServer' };
Debug
Known issues
breakingRequires disabling the default ORM and pubsub hooks; failure to do so causes conflicts.
fix
Add '{"hooks": {"orm": false, "pubsub": false}}' to .sailsrc.
affects: >=1.0.0
deprecatedSequelize v5 deprecated STRING, TEXT, etc. without length; use STRING(255) instead.
fix
Update model attributes to specify lengths where applicable.
affects: >=2.0.0
gotchaModel must include an 'options' key (even if empty) to be recognized as a Sequelize model.
fix
Add 'options: {}' to model definition.
affects: >=0.10.0
gotchaDialect must be specified in both connection and connection.options when using options.
fix
Include 'dialect' in both the connection object and its 'options' sub-object.
affects: >=1.0.0
deprecatedNode.js >=12 required; older versions unsupported.
fix
Upgrade Node.js to >=12.
affects: >=2.0.0
Errors
Common errors & fixes
Error: `dialect` is not configured for this connection. Please specify a `dialect` in the connection config.
Dialect missing from connection configuration.
fix
Add `dialect: 'postgres'` (or your dialect) to the connection object and its options if present.
Error: Trying to use a non-Sequelize model. Make sure you define `options` key.
Model missing `options` key.
fix
Add `options: {}` to the model definition.
Error: Model is not associated with any connection. Please assign a connection.
No `connection` key in model or default connection missing.
fix
Add `connection: 'myConnection'` to the model or set `models.connection` in config.
TypeError: Cannot read property 'sequelize' of undefined
sails-hook-sequelize not loaded or configured.
fix
Ensure .sailsrc disables ORM hook, and the hook is installed.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
sailsrequiredSails.js framework required; this is a Sails hook.
sequelizerequiredSequelize ORM is the core dependency; the hook wraps Sequelize.
lodashrequiredUtility library used internally by the hook.
Agent activity
11 hits · last 30 days
node
10
Meta
1
Resources
sails-hook-sequelize — npm install sails-hook-sequelize · libregistry