Registry / database / sails-mysql-transactions

sails-mysql-transactions

JSON →
library0.9.1jsnpmunverified

Sails ORM adapter for MySQL that adds transaction and replication support on top of the core sails-mysql adapter. Version 0.9.1 (last release) extends Waterline's model methods with .beginTransaction(), .commitTransaction(), and .rollbackTransaction(), allowing atomic multi-query operations. It supports master/slave replication for read/write splitting. The adapter is now in maintenance mode; users are advised to migrate to sails-mysql or use Knex.js for modern transaction handling in Sails.js applications.

npm install sails-mysql-transactions
INSTALL
IMPORT
SIG · SAILS-MYSQL-TRANSA
S
sails-mysql-transactions
databasejavascriptv0.9.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.

default
const MySQLTransactions = require('sails-mysql-transactions');
import MySQLTransactions from 'sails-mysql-transactions';
Package uses CommonJS; no ES default export.
adapter
module.exports = { adapters: { 'sails-mysql-transactions': require('sails-mysql-transactions') } };
module.exports = { adapters: { 'sails-mysql-transactions': 'sails-mysql-transactions' } }
Adapter must be an object, not a string.
N/A (config)
// config/models.js module.exports.models = { connection: 'someMysqlTransactionsConnection', migrate: 'safe' };
Transactions are initiated via model methods, not direct import. Use Waterline's model.transaction() after setup.

Shows how to set up the adapter in Sails.js connections and use beginTransaction/commit/rollback on a Waterline model.

// Install: npm install sails-mysql-transactions sails-mysql // config/connections.js module.exports.connections = { someMysqlTransactions: { adapter: 'sails-mysql-transactions', host: 'localhost', user: 'root', password: process.env.DB_PASSWORD ?? '', database: 'test', // replication: { read: [{ host: 'slave', user: 'root', password: '...', database: 'test' }] } } }; // In a controller User.beginTransaction(function(err, transaction) { if (err) { /* handle error */ } User.create({ name: 'Alice' }).usingConnection(transaction.connection).exec(function(err, user) { if (err) { return transaction.rollback(function() { /* error handling */ }); } transaction.commit(function(err) { if (err) { /* rollback */ } }); }); });
Debug
Known issues
gotchaMust have sails-mysql installed as a peer dependency; missing it will cause silent adapter errors.
fix
npm install sails-mysql
affects: >=0.9.0
breakingTransactions do not work with sails-mysql after v1.0; requires sails-mysql@0.x.
fix
Pin sails-mysql to 0.x
affects: >=0.9.0
deprecatedPackage is no longer actively maintained. Consider migrating to sails-mysql with Knex.js for transactions.
fix
Use sails-mysql and Knex.js transaction support
affects: >=0.9.0
gotchaReplication configuration requires explicit read/write splitting; write to slave will be silently ignored.
fix
Ensure writes go to master host only
affects: >=0.9.0
deprecatedConnection pooling behavior differs from sails-mysql; may cause unexpected timeouts.
fix
Monitor pool event 'acquire' and configure pool settings appropriately
affects: >=0.9.0
Errors
Common errors & fixes
Error: `require()` of ES Module <path>/node_modules/sails-mysql-transactions/index.js from <path>/node_modules/sails-mysql-transactions/... not supported
Package is CommonJS but required from an ESM context or vice versa; or Node.js version mismatch.
fix
Use require() in a CommonJS file or set type: 'commonjs' in package.json.
Error: `usingConnection` is not a function
Attempted to use .usingConnection() on a model method without a transaction object with a connection property.
fix
Call model.beginTransaction() first and pass the returned transaction's connection to usingConnection().
Error: `transaction.rollback` is not a function
Using an older version where rollback was not yet implemented; or the transaction object is malformed.
fix
Upgrade to >=0.9.0 and ensure beginTransaction returns a valid transaction object.
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running or connection config wrong (host, port, credentials).
fix
Start MySQL service and verify connection config in config/connections.js.
Upgrade
Version history
0.9.1latest on npm
Audit
Dependencies
sails-mysqlrequiredExtends sails-mysql adapter; must be installed alongside
Agent activity
6 hits · last 30 days
node
4
Meta
1
Resources
sails-mysql-transactions — npm install sails-mysql-transactions · libregistry