Registry / database / sails-mssql

sails-mssql

JSON →
library2.1.10jsnpmunverified

SQL Server adapter for Sails.js and Waterline ORM (v2.1.10, supporting Sails 1.x). Enables MSSQL database integration via Sails models, with raw SQL query support. Active maintenance with irregular releases. Key differentiator: native SQL Server support for the Sails ecosystem, leveraging tedious driver. Consider using a more modern driver like mssql directly for non-Sails projects.

npm install sails-mssql
INSTALL
IMPORT
SIG · SAILS-MSSQL
S
sails-mssql
databasejavascriptv2.1.10
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-mssql
// In .sailsrc or config/datastores.js: module.exports.datastores = { default: { adapter: require('sails-mssql'), url: 'mssql://username:password@host:port/database' } };
const SailsMssql = require('sails-mssql'); new SailsMssql(...)
sails-mssql is a Sails adapter, not a standalone ORM. It must be configured via Sails datastore config.
Waterline adapter usage
// In Sails model file (api/models/User.js): module.exports = { datastore: 'default', attributes: { name: 'string' } };
const User = require('sails-mssql'); User.create({...})
Models are defined in Sails, which internally uses the adapter. Never import sails-mssql directly in model files.
query() method
// In custom Sails action or service: const result = await sails.getDatastore().sendStatement({ text: 'SELECT * FROM users' });
const db = require('sails-mssql'); db.query('SELECT 1')
The adapter does not export a query method. Use sails.getDatastore().sendStatement() or model.native() to send raw SQL.

Shows how to install and configure sails-mssql, define a model, and use it in a Sails controller.

// 1. Install: npm install sails-mssql // 2. In config/datastores.js: module.exports.datastores = { default: { adapter: require('sails-mssql'), url: 'mssql://sa:yourStrong(!)Password@localhost:1433/mydb', ssl: false, pool: { min: 0, max: 5 } } }; // 3. Create a model (api/models/User.js): module.exports = { datastore: 'default', attributes: { id: { type: 'number', autoIncrement: true }, name: { type: 'string', required: true }, email: { type: 'string', isEmail: true } } }; // 4. In a controller (api/controllers/UserController.js): module.exports = { create: async function (req, res) { const user = await User.create({ name: 'Alice', email: 'alice@example.com' }).fetch(); return res.json(user); } };
Debug
Known issues
gotchaAdapter requires Sails 1.x. Using with Sails 0.12.x requires the 1.x branch of sails-mssql (git checkout 0.12.x).
fix
Check the branch table: sails-mssql v2.x for Sails 1.x, v1.x for Sails 0.12.x.
affects: >=2.0.0
gotchaconnection url format must be mssql://username:password@host:port/database
fix
Use the correct URL prefix: mssql:// not sqlserver:// or other.
affects: >=2.0.0
deprecatedUse of `native()` model method is deprecated in Sails v1; prefer `sendStatement()`
fix
Replace model.native() with sails.getDatastore().sendStatement({ text: query })
affects: >=2.0.0
breakingSails v1 removed the `query()` method on adapters. Use `sendStatement()` instead.
fix
Use sails.getDatastore().sendStatement({ text: 'SQL' }) or model.getDatastore().sendStatement(...)
affects: >=2.0.0
gotchaTedious driver uses default port 1433. Ensure SQL Server is configured for TCP/IP connections.
fix
Enable TCP/IP in SQL Server Configuration Manager and restart the SQL Server service.
affects: >=2.0.0
Errors
Common errors & fixes
Error: connect ETIMEDOUT
TCP port 1433 not reachable or SQL Server not accepting remote connections.
fix
Check firewall rules, enable TCP/IP in SQL Server Configuration Manager, and verify the server name.
Error: Login failed for user 'username'
Invalid credentials or SQL Server authentication mode is set to Windows only.
fix
Ensure SQL Server is in Mixed Mode (SQL Server and Windows Authentication). Then use correct username/password.
Error: connect ECONNREFUSED
SQL Server is not running or is listening on a different port.
fix
Start SQL Server service, verify port in connection URL, and check if the server is accessible.
Upgrade
Version history
2.1.10latest on npm
Audit
Dependencies
@sailshq/lodashrequiredInternal utility library used by Waterline adapters
waterline-utilsrequiredProvides utility functions for Waterline adapter operations
machinerequiredUsed for defining machine actions
tediousrequiredSQL Server driver for Node.js
Agent activity
13 hits · last 30 days
node
12
Meta
1
Resources
sails-mssql — npm install sails-mssql · libregistry