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.
adapter
✓ import adapter from 'waterline-mysql';
✗ const adapter = require('waterline-mysql');
Package is primarily used with Waterline's adapter configuration. Default import is typical for ESM; CommonJS require also works but will return the module.exports object.
Waterline
✓ import Waterline from 'waterline'; const MySQLAdapter = require('waterline-mysql'); Waterline.registerAdapter(MySQLAdapter);
✗ const MySQLAdapter = require('waterline-mysql'); // Missing registration with Waterline
Adapter must be registered with Waterline before use. CommonJS pattern shown; Waterline is an ESM-only module in later versions.
config
✓ const config = { adapters: { 'mysql': require('waterline-mysql') }, connections: { 'myLocalMySQL': { adapter: 'mysql', host: 'localhost' } } };
✗ const config = { adapters: { mysql: 'waterline-mysql' } }; // adapter must be the module, not a string
In Waterline config, the adapter property must be set to the required module, not just its name.
Shows how to configure and use the MySQL adapter with Waterline, including collection definition and initialization.
import Waterline from 'waterline';
import MySQLAdapter from 'waterline-mysql';
const waterline = new Waterline();
const userCollection = Waterline.Collection.extend({
identity: 'user',
connection: 'myLocalMySQL',
attributes: {
name: { type: 'string', required: true },
email: { type: 'string', required: true }
}
});
waterline.loadCollection(userCollection);
const config = {
adapters: {
'mysql': MySQLAdapter
},
connections: {
'myLocalMySQL': {
adapter: 'mysql',
host: process.env.MYSQL_HOST ?? 'localhost',
port: process.env.MYSQL_PORT ?? 3306,
user: process.env.MYSQL_USER ?? 'root',
password: process.env.MYSQL_PASSWORD ?? '',
database: process.env.MYSQL_DATABASE ?? 'test'
}
}
};
waterline.initialize(config, (err, ontology) => {
if (err) {
console.error(err);
return;
}
const User = ontology.collections.user;
User.create({ name: 'Alice', email: 'alice@example.com' })
.then((user) => console.log('Created:', user))
.catch((err) => console.error(err));
});
Errors
Common errors & fixes
Error: registerAdapter is not a function
Waterline version mismatch; later versions use a different pattern for adapter registration.
fixUse config.adapters object instead of registerAdapter: { adapters: { mysql: require('waterline-mysql') } } Error: Cannot find module 'mysql'
Missing peer dependency 'mysql' (or 'mysql2').
fixRun: npm install mysql (or mysql2) as a dependency.
Error: Connection failed: connect ECONNREFUSED
MySQL server not running or incorrect host/port in connection config.
fixVerify MySQL is running and connection details are correct.
Audit
Dependencies
waterlinerequiredCore ORM dependency; adapter must be used with Waterline.