marv-mysql-driver
v5.0.0
Published
A mysql marv driver implementation
Downloads
563
Readme
marv-mysql-driver
A mysql driver for marv
Prerequisites
One of:
marv-mysql-driver will automatically use whichever library you have installed but does not package either of these libraries. Please read the troubleshooting notes if using mysql with MySQL 8.0 (or above).
Installation
npm i marv marv-mysql-driver
Usage
migrations/
|- 001.create-table.sql
|- 002.create-another-table.sql
Promises
const marv = require('marv/api/promise'); // <-- Promise API
const driver = require('marv-mysql-driver');
const directory = path.resolve('migrations');
const connection = {
// Properties are passed straight mysql.createConnection
host: 'mysql.example.com',
multipleStatements: true // See https://www.npmjs.com/package/mysql#multiple-statement-queries
};
const migrations = await marv.scan(directory);
await marv.migrate(migrations, driver({ connection });
// Profit :)
Callbacks
const marv = require("marv/api/callback"); // <-- Callback API
const driver = require("marv-mysql-driver");
const directory = path.resolve("migrations");
const connection = {
// Properties are passed straight [mysql|mysql2].createConnection
host: "mysql.example.com",
multipleStatements: true, // See https://www.npmjs.com/package/mysql#multiple-statement-queries
};
marv.scan(directory, (err, migrations) => {
if (err) throw err;
// Connection properties are passed straight [mysql|mysql2].createConnection
marv.migrate(migrations, driver({ connection }), (err) => {
if (err) throw err;
// Profit :)
});
});
Troubleshooting
Client does not support authentication protocol requested by server; consider upgrading MySQL client
MySQL v8 changed the default authentication plugin to caching_sha2_password
, which, at time of writing is not supported by mysql. Therefore MySQL v8 users either need to change the default authentication plugin back to mysql_native_password
or install mysql2.
MySQL v5 users can use either mysql or mysql2.
Testing
npm install
npm run mysql5
npm run mysql8
npm run mysql8-native-password
sleep 30
npm test