{"id":41927,"library":"sails-hook-orm","title":"sails-hook-orm","description":"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.","status":"active","version":"4.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/balderdashy/sails-hook-orm","tags":["javascript","waterline","orm","sails","hook","sails-hook"],"install":[{"cmd":"npm install sails-hook-orm","lang":"bash","label":"npm"},{"cmd":"yarn add sails-hook-orm","lang":"bash","label":"yarn"},{"cmd":"pnpm add sails-hook-orm","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a Sails hook and requires the Sails framework to run.","package":"sails","optional":false},{"reason":"Core ORM library used for database interactions.","package":"waterline","optional":false},{"reason":"Default disk adapter bundled as implicit default.","package":"sails-disk","optional":true}],"imports":[{"note":"No exports; must be installed and Sails loads it automatically.","wrong":"const orm = require('sails-hook-orm')","symbol":"sails-hook-orm","correct":"import 'sails-hook-orm'"},{"note":"ESM-only since v2; use import statement.","wrong":"const sails = require('sails')","symbol":"sails","correct":"import sails from 'sails'"},{"note":"Models are keyed by identity (lowercase), e.g., 'user', not 'User'.","wrong":"sails.models.User","symbol":"sails.models","correct":"import sails from 'sails'; sails.models.user.create(...)"}],"quickstart":{"code":"// Install Sails and the ORM hook:\n// npm install sails sails-hook-orm\n\n// In your Sails app (app.js):\nimport sails from 'sails';\nimport 'sails-hook-orm';\n\nsails.lift({\n  models: {\n    datastore: 'default'\n  },\n  datastores: {\n    default: {\n      adapter: 'sails-disk',\n      // Optional: inMemory: true to avoid persistence\n    }\n  },\n  globals: {\n    models: true\n  }\n}, (err) => {\n  if (err) {\n    console.error(err);\n    return;\n  }\n  // Access models via sails.models or global (if enabled)\n  sails.models.user.find({}).then(console.log).catch(console.error);\n});\n\n// Define a model in api/models/User.js:\nexport default {\n  attributes: {\n    name: { type: 'string' },\n    email: { type: 'string' }\n  }\n};","lang":"javascript","description":"Installs the ORM hook, lifts a Sails app with default disk adapter, creates a User model, and queries all users."},"warnings":[{"fix":"Switch to ES module imports: import 'sails-hook-orm' and use import for sails.","message":"sails-hook-orm v2+ is ESM-only. CommonJS require() will fail.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use the identity defined in the model (usually lowercase filename).","message":"Models are exposed with lowercase identities, e.g., sails.models.user, not sails.models.User.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set sails.config.models.migrate explicitly to 'safe', 'alter', or 'drop' in your app configuration.","message":"The auto-migration prompt is deprecated and will be removed in future versions.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Ensure those core hooks are enabled or load dependencies manually.","message":"If the 'moduleloader' or 'userconfig' hooks are disabled, sails-hook-orm will not load.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use .then() or await with model methods.","message":"Waterline v0.13 dropped support for callbacks; only promises or async/await.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Access models via sails.models if globals are disabled.","message":"Setting sails.config.globals.models to false will not attach models to global scope, but they remain on sails.models.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'4.0.3':19 'adapt':21,68 'api/models':56 'auto':58 'auto-migr':57 'automat':52 'built':63 'built-in':62 'cadenc':46 'core':5 'differenti':51 'disk':67 'esm':70 'esm-on':69 'expos':29 'follow':47 'framework':17 'global':35 'hook':3,7,78,81 'hydrat':24 'integr':11 'javascript':74 'key':50 'load':20,54 'migrat':59 'model':23,53 'option':34 'orm':4,6,13,76 'part':38 'prompt':60 'releas':36,45,49 'sail':2,16,40,48,66,77,80 'sails-disk':65 'sails-hook':79 'sails-hook-orm':1 'sails.js':9 'sails.models':32 'sinc':72 'stabl':44 'v1':41 'v2':73 'version':18 'via':26 'waterlin':12,27,75","created_at":"2026-06-04T18:54:47.176867+00:00","updated_at":"2026-06-04T18:54:47.176867+00:00","problems":[{"fix":"Run npm install sails-hook-orm.","cause":"The package is not installed or not in node_modules.","error":"Error: Cannot find module 'sails-hook-orm'"},{"fix":"Add \"type\": \"module\" to package.json or rename file to .mjs.","cause":"ESM syntax used in a CommonJS project.","error":"Error: Cannot use import statement outside a module"},{"fix":"Ensure model file exists and datastore adapter is installed.","cause":"Model not loaded or datastore not configured.","error":"TypeError: sails.models.user.create is not a function"},{"fix":"Check that all required core hooks are enabled and configuration is valid.","cause":"Missing dependencies (moduleloader, userconfig) or incorrect config.","error":"Error: Hook 'orm' failed to load"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://sailsjs.com","github":"https://github.com/balderdashy/sails-hook-orm","docs":null,"changelog":null,"pypi":null,"npm":"sails-hook-orm","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}