2018-02-13 21:40:02 +00:00
|
|
|
let mysql = require('mysql2');
|
2018-01-16 20:39:40 +00:00
|
|
|
|
2018-01-17 11:46:26 +00:00
|
|
|
let connection = mysql.createConnection({
|
2018-01-21 16:47:24 +00:00
|
|
|
multipleStatements: true,
|
2018-01-17 11:46:26 +00:00
|
|
|
host: 'localhost',
|
|
|
|
user: 'root',
|
|
|
|
password: '',
|
|
|
|
database: 'salix'
|
|
|
|
});
|
2018-01-16 20:39:40 +00:00
|
|
|
|
2018-01-21 16:47:24 +00:00
|
|
|
let errorHandler = callback => {
|
|
|
|
return error => {
|
|
|
|
if (error)
|
|
|
|
throw error;
|
|
|
|
callback();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-03-08 11:23:51 +00:00
|
|
|
let insertFixtures = async function(sqlStatements) {
|
|
|
|
try {
|
|
|
|
if (sqlStatements.deletes.length)
|
|
|
|
await connection.query(sqlStatements.deletes);
|
|
|
|
if (sqlStatements.inserts.length)
|
|
|
|
await connection.query(sqlStatements.inserts);
|
|
|
|
if (sqlStatements.updates.length)
|
|
|
|
await connection.query(sqlStatements.updates);
|
|
|
|
} catch (error) {
|
|
|
|
errorHandler(error);
|
|
|
|
}
|
2018-01-21 16:47:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
connection.connect();
|
|
|
|
|
2018-03-08 11:23:51 +00:00
|
|
|
module.exports = function restoreFixtures(sqlStatements) {
|
2018-01-21 16:47:24 +00:00
|
|
|
connection.query('SET FOREIGN_KEY_CHECKS = 0', () => {
|
2018-03-08 11:23:51 +00:00
|
|
|
insertFixtures(sqlStatements);
|
2018-01-21 16:47:24 +00:00
|
|
|
});
|
2018-01-31 10:15:12 +00:00
|
|
|
};
|