Registry / database / sails-hook-orm

sails-hook-orm

JSON →
library4.0.3jsnpmunverified

Core ORM hook for Sails.js that integrates Waterline ORM into the Sails framework. Version 4.0.3 loads adapters and models, hydrates them via Waterline, and exposes them as sails.models and optional globals. Released as part of Sails v1, with a stable release cadence following Sails releases. Key differentiators: automatic model loading from api/models, auto-migration prompts, and built-in sails-disk adapter. ESM-only since v2.

npm install sails-hook-orm
INSTALL
IMPORT
SIG · SAILS-HOOK-ORM
S
sails-hook-orm
databasejavascriptv4.0.3
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-hook-orm
import 'sails-hook-orm'
const orm = require('sails-hook-orm')
No exports; must be installed and Sails loads it automatically.
sails
import sails from 'sails'
const sails = require('sails')
ESM-only since v2; use import statement.
sails.models
import sails from 'sails'; sails.models.user.create(...)
sails.models.User
Models are keyed by identity (lowercase), e.g., 'user', not 'User'.

Installs the ORM hook, lifts a Sails app with default disk adapter, creates a User model, and queries all users.

// Install Sails and the ORM hook: // npm install sails sails-hook-orm // In your Sails app (app.js): import sails from 'sails'; import 'sails-hook-orm'; sails.lift({ models: { datastore: 'default' }, datastores: { default: { adapter: 'sails-disk', // Optional: inMemory: true to avoid persistence } }, globals: { models: true } }, (err) => { if (err) { console.error(err); return; } // Access models via sails.models or global (if enabled) sails.models.user.find({}).then(console.log).catch(console.error); }); // Define a model in api/models/User.js: export default { attributes: { name: { type: 'string' }, email: { type: 'string' } } };
Debug
Known issues
breakingsails-hook-orm v2+ is ESM-only. CommonJS require() will fail.
fix
Switch to ES module imports: import 'sails-hook-orm' and use import for sails.
affects: >=2.0.0
gotchaModels are exposed with lowercase identities, e.g., sails.models.user, not sails.models.User.
fix
Use the identity defined in the model (usually lowercase filename).
affects: >=1.0.0
deprecatedThe auto-migration prompt is deprecated and will be removed in future versions.
fix
Set sails.config.models.migrate explicitly to 'safe', 'alter', or 'drop' in your app configuration.
affects: >=3.0.0
gotchaIf the 'moduleloader' or 'userconfig' hooks are disabled, sails-hook-orm will not load.
fix
Ensure those core hooks are enabled or load dependencies manually.
affects: >=1.0.0
breakingWaterline v0.13 dropped support for callbacks; only promises or async/await.
fix
Use .then() or await with model methods.
affects: >=4.0.0
gotchaSetting sails.config.globals.models to false will not attach models to global scope, but they remain on sails.models.
fix
Access models via sails.models if globals are disabled.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'sails-hook-orm'
The package is not installed or not in node_modules.
fix
Run npm install sails-hook-orm.
Error: Cannot use import statement outside a module
ESM syntax used in a CommonJS project.
fix
Add "type": "module" to package.json or rename file to .mjs.
TypeError: sails.models.user.create is not a function
Model not loaded or datastore not configured.
fix
Ensure model file exists and datastore adapter is installed.
Error: Hook 'orm' failed to load
Missing dependencies (moduleloader, userconfig) or incorrect config.
fix
Check that all required core hooks are enabled and configuration is valid.
Upgrade
Version history
4.0.3latest on npm
Audit
Dependencies
sailsrequiredThis is a Sails hook and requires the Sails framework to run.
waterlinerequiredCore ORM library used for database interactions.
sails-diskoptionalDefault disk adapter bundled as implicit default.
Agent activity
12 hits · last 30 days
node
10
Meta
1
Resources