db-cluster-mysql
Advanced tools
Comparing version 0.0.8 to 0.0.9
44
index.js
@@ -1,4 +0,4 @@ | ||
"use strict"; | ||
'use strict'; | ||
var engine = 'mysql'; | ||
const engine = 'mysql'; | ||
@@ -32,3 +32,3 @@ class Result { | ||
this.connection = raw; | ||
this.engine = engine | ||
this.engine = engine; | ||
} | ||
@@ -52,9 +52,9 @@ init(cb) { | ||
cb(err, new Result(result, header), this.sql, options); | ||
}.bind({sql: sql})) | ||
}.bind({sql: sql})); | ||
} | ||
getInsertData(data) { | ||
var fields = Object.keys(data); | ||
var dataArray = []; | ||
for (var f = 0; f < fields.length; f++) { | ||
const fields = Object.keys(data); | ||
const dataArray = []; | ||
for (let f = 0; f < fields.length; f++) { | ||
if(data[fields[f]] !== undefined) { | ||
@@ -64,4 +64,4 @@ dataArray.push(fields[f]); | ||
} | ||
var fieldPh = []; | ||
var valuePh = []; | ||
const fieldPh = []; | ||
const valuePh = []; | ||
fields.forEach(function(field) { | ||
@@ -83,13 +83,13 @@ if(data[field] !== undefined) { | ||
let [fieldPh, valuePh, dataArray] = this.getInsertData(data); | ||
const [fieldPh, valuePh, dataArray] = this.getInsertData(data); | ||
dataArray.unshift(table); | ||
// Big assumption - Assumes single autoincrement field named id | ||
this.query('INSERT INTO ?? (' + fieldPh.join(', ') + ') values (' + valuePh.join(', ') + ')', dataArray, cb); | ||
}; | ||
} | ||
update(table, data, condition, cond_params, cb) { | ||
var fields = Object.keys(data); | ||
var values = []; | ||
var dataArray = [table]; | ||
var fieldPh = []; | ||
const fields = Object.keys(data); | ||
const values = []; | ||
const dataArray = [table]; | ||
const fieldPh = []; | ||
fields.forEach(function(field, f) { | ||
@@ -104,5 +104,5 @@ if(data[field] !== undefined) { | ||
dataArray.push(param); | ||
}) | ||
}); | ||
this.query('UPDATE ?? SET ' + fieldPh.join(', ') + ' WHERE ' + condition, dataArray, cb); | ||
}; | ||
} | ||
@@ -127,3 +127,3 @@ beginTransaction(cb, options) { | ||
} | ||
}; | ||
} | ||
@@ -151,3 +151,3 @@ class Pool { | ||
} | ||
}) | ||
}); | ||
} | ||
@@ -158,3 +158,3 @@ | ||
this.pool.end(function(err) { | ||
cb(err) | ||
cb(err); | ||
}); | ||
@@ -165,3 +165,3 @@ } else { | ||
} | ||
}; | ||
} | ||
@@ -174,4 +174,4 @@ module.exports = { | ||
getDriver: function() { | ||
return require('mysql2') | ||
return require('mysql2'); | ||
} | ||
}; |
{ | ||
"name": "db-cluster-mysql", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "", | ||
@@ -12,6 +12,6 @@ "main": "index.js", | ||
"devDependencies": { | ||
"db-cluster": "0.0.5", | ||
"mocha": "^2.4.5", | ||
"mysql2": "^1.0.0-rc.1" | ||
"db-cluster": "0.0.7", | ||
"mocha": "^9.1.0", | ||
"mysql2": "^2.3.0" | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
var dbCluster = require('db-cluster'); | ||
var config = { | ||
const dbCluster = require('db-cluster'); | ||
const config = { | ||
adapter: require('../index.js'), | ||
@@ -9,3 +9,3 @@ driver: require('mysql2'), | ||
password: '', | ||
database: "test" | ||
database: 'test' | ||
}, | ||
@@ -24,27 +24,23 @@ pools: { | ||
user: 'root', | ||
health: function(poolObject) { | ||
poolObject.health = {}; | ||
poolObject.health.initialize = setInterval(function() { | ||
var pool = this.pool; | ||
pool.getConnection(function(err, conn) { | ||
conn.query('select (FLOOR(1 + RAND() * 100)) as number', function(err, res) { | ||
conn.release(); | ||
if (res.rows()[0].number % 2 == 0) { | ||
poolObject.paused = true; | ||
} else { | ||
poolObject.paused = false; | ||
} | ||
}); | ||
}) | ||
}.bind({ | ||
pool: poolObject.pool | ||
}), 500); | ||
poolObject.health.shutdown = function(cb) { | ||
clearInterval(this.scope); | ||
cb(); | ||
}.bind({ | ||
scope: poolObject.health.shutdown | ||
}) | ||
} | ||
// health: function (poolObject) { | ||
// poolObject.health = {}; | ||
// poolObject.health.initialize = setInterval(function () { | ||
// const pool = this.pool; | ||
// pool.getConnection(function (err, conn) { | ||
// conn.query('select (FLOOR(1 + RAND() * 100)) as number', function (err, res) { | ||
// conn.release(); | ||
// poolObject.paused = res.rows()[0].number % 2 === 0; | ||
// }); | ||
// }); | ||
// }.bind({ | ||
// pool: poolObject.pool | ||
// }), 500); | ||
// | ||
// poolObject.health.shutdown = function (cb) { | ||
// clearInterval(this.scope); | ||
// cb(); | ||
// }.bind({ | ||
// scope: poolObject.health.shutdown | ||
// }); | ||
// } | ||
}, | ||
@@ -58,30 +54,39 @@ nodes: [{ | ||
} | ||
} | ||
}; | ||
var cluster = dbCluster(config); | ||
const cluster = dbCluster(config); | ||
describe('MySQL', function() { | ||
beforeEach(function(done) { | ||
cluster.master(function(err, conn) { | ||
if(err) { | ||
describe('MySQL', function () { | ||
beforeEach(function (done) { | ||
cluster.master(function (err, conn) { | ||
if (err) { | ||
return done(err); | ||
} | ||
conn.query('CREATE TABLE ?? (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(40), someval VARCHAR(40) NULL)', ['test'], function(err, result) { | ||
conn.query('CREATE TABLE ?? (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(40), someval VARCHAR(40) NULL)', ['test'], function (err, result) { | ||
conn.release(); | ||
done(err); | ||
}) | ||
}) | ||
}); | ||
}); | ||
}); | ||
afterEach(function(done) { | ||
cluster.master(function(err, conn) { | ||
if(err) { | ||
afterEach(function (done) { | ||
cluster.master(function (err, conn) { | ||
if (err) { | ||
return done(err); | ||
} | ||
conn.query('DROP TABLE ??', ['test'], function(err, result) { | ||
conn.query('DROP TABLE ??', ['test'], function (err, result) { | ||
conn.release(); | ||
done(err); | ||
}) | ||
}); | ||
}); | ||
}) | ||
}); | ||
after(done => { | ||
cluster.end(done); | ||
}); | ||
it('Test Before/After', (done) => { | ||
done(); | ||
}); | ||
require('db-cluster/test/integration/test')(cluster, config); | ||
}) | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
262
34955
10
1