Registry / database / sails-mysql

sails-mysql

JSON →
library3.0.1jsnpmunverified

MySQL adapter for Sails.js and Waterline ORM, version 3.0.1. Provides a MySQL database integration for Sails applications, allowing model-driven data persistence and raw SQL queries via the `query()` method. Actively maintained as part of the Sails ecosystem, with test coverage and community support. Alternatives include other Waterline adapters or direct MySQL libraries.

npm install sails-mysql
INSTALL
IMPORT
SIG · SAILS-MYSQL
S
sails-mysql
databasejavascriptv3.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-mysql
npm install sails-mysql
require('sails-mysql')
Installed as a Node module, not imported directly. Configure as a datastore adapter in Sails.
sails.config.datastores
// In config/datastores.js: module.exports.datastores = { default: { adapter: 'sails-mysql', url: 'mysql://root:pass@localhost/my_db' } };
require('sails-mysql') as a separate connection
The adapter is configured globally via Sails datastores configuration.
Model.query()
await MyModel.query('SELECT * FROM users WHERE id = $1', [1]);
MyModel.query('SELECT ...')
Use async/await or promises. Raw SQL queries are available on model instances.

Shows installation, configuration, model definition, and creation of a record using sails-mysql.

// 1. Install // npm install sails-mysql // 2. Configure datastore in config/datastores.js module.exports.datastores = { default: { adapter: 'sails-mysql', url: process.env.MYSQL_URL || 'mysql://root:password@localhost/sails_test' } }; // 3. Create model (api/models/User.js) module.exports = { attributes: { name: { type: 'string' }, email: { type: 'string', required: true, unique: true } } }; // 4. Use in controller async function createUser(req, res) { const newUser = await User.create({ name: 'Alice', email: 'alice@example.com' }).fetch(); return res.json(newUser); }
Debug
Known issues
gotchaThe adapter relies on mysql2, but requires careful URL encoding for passwords with special characters.
fix
Use encodeURIComponent() for password values in connection URL.
affects: >=0.0.0
gotchaRaw queries via Model.query() must use parameterized queries to prevent SQL injection.
fix
Always use $1, $2 placeholders and pass values as array.
affects: >=0.0.0
deprecatedOld configuration via adapter config in waterline is deprecated; use Sails datastores config.
fix
Move to sails.config.datastores pattern.
affects: >=2.0
gotchaAdapter does not support connection pooling by default; you must configure pool parameters in datastore config.
fix
Add 'pool' setting in datastores config (e.g., pool: { min: 0, max: 10 }).
affects: >=0.0.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running or wrong host/port.
fix
Start MySQL service and verify MYSQL_URL environment variable.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Invalid credentials in connection URL.
fix
Check username and password in MYSQL_URL; ensure user has proper privileges.
Error: ER_BAD_DB_ERROR: Unknown database 'sails_test'
Database does not exist.
fix
Create database via SQL: CREATE DATABASE sails_test;
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
sailsrequiredAdapter for Sails.js framework
waterlinerequiredORM integration
mysql2requiredMySQL client library for Node.js
Agent activity
10 hits · last 30 days
node
8
Meta
2
Resources
sails-mysql — npm install sails-mysql · libregistry