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);
}
};
Errors
Common errors & fixes
Error: connect ETIMEDOUT
TCP port 1433 not reachable or SQL Server not accepting remote connections.
fixCheck 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.
fixEnsure 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.
fixStart SQL Server service, verify port in connection URL, and check if the server is accessible.
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