39 lines
942 B
JavaScript
39 lines
942 B
JavaScript
let mysql = require('mysql2');
|
|
|
|
let connection = mysql.createConnection({
|
|
multipleStatements: true,
|
|
host: 'localhost',
|
|
user: 'root',
|
|
password: 'root',
|
|
database: 'salix'
|
|
});
|
|
|
|
let errorHandler = callback => {
|
|
return error => {
|
|
if (error)
|
|
throw error;
|
|
callback();
|
|
};
|
|
};
|
|
|
|
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);
|
|
}
|
|
};
|
|
|
|
connection.connect();
|
|
|
|
module.exports = function restoreFixtures(sqlStatements) {
|
|
connection.query('SET FOREIGN_KEY_CHECKS = 0', () => {
|
|
insertFixtures(sqlStatements);
|
|
});
|
|
};
|