Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
var sql = 'select * from ' + table + ' where `' + key + '` in ('
+ qs.join(',') + ')';
mysql_db.query(sql, values, function(err, rows) {
var objs = null;
if(rows) {
objs = {};
rows.forEach(function(row){
objs[row[key]] = row;
});
}
callback(err, objs);
});
};
var mysql_db = mysql.createClient(conf.database);
//mysql_db.connect(function(err) {
// if(err) {
// console.error('connect db ' + mysql_db.host + ' error: ' + err);
// process.exit();
// }
//});
exports.mysql_db = mysql_db;
function loadClient(callback) {
client = mysql.createClient({
user: config.user,
password: config.password,
host: config.host,
port: config.port,
}).on("error", function(err) {
console.log("DB ERROR: " + err);
client = null;
});
// switch to target database
client.useDatabase( config.database ,function(err) {
if(err) {
console.log("DB ERROR: Database cannot select db, detail: " + err);
client = null;
}
var mysql = require('mysql');
var queues = require('mysql-queues');
// подключение к базе данных
var client = mysql.createClient({
user: 'username',
password: 'password'
});
client.query('USE databasenm');
// связывание очередей с запросом
// использование отладки
queues(client, true);
// создание очереди
q = client.createQueue();
// вставка
q.query(
'INSERT INTO nodetest2 (title, text, created) ' + 'values(?,?,NOW())',
['Title for 8', 'Text for 8']
);
// обновление
q.query(
var mysql = require('mysql'),
settings = require('./settings').shorten_settings;
//Load this SQL manually if you'd prefer
var sqlStructure = "CREATE TABLE IF NOT EXISTS `shorten_linkmaps` (`id` int(11) NOT NULL AUTO_INCREMENT,`linkDestination` varchar(512) NOT NULL,`linkHash` varchar(8) NOT NULL,`timestamp` datetime NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;CREATE TABLE IF NOT EXISTS `shorten_linkstats` (`id` int(11) NOT NULL AUTO_INCREMENT,`ip` char(15) NOT NULL,`userAgent` varchar(255) NOT NULL,`referrer` varchar(512) NOT NULL,`timestamp` datetime NOT NULL,`linkId_id` int(11) NOT NULL,PRIMARY KEY (`id`),KEY `shorten_linkstats_11e70f3` (`linkId_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
var devOrLive = process.argv[2];
var mysqlc;
if (devOrLive == "dev"){
mysqlc = mysql.createClient({host: settings.dev_mysql.host, user: settings.dev_mysql.user, password: settings.dev_mysql.password, database: settings.dev_mysql.dbname, port: settings.dev_mysql.port});
makeDB();
}else if(devOrLive == "live"){
mysqlc = mysql.createClient({host: settings.live_mysql.host, user: settings.live_mysql.user, password: settings.live_mysql.password, database: settings.live_mysql.dbname, port: settings.live_mysql.port});
makeDB();
}else{
console.log("usage: node setup_db.js dev");
console.log(" OR: node setup_db.js live");
}
function makeDB(){
mysqlc.query(sqlStructure, function(err, results, fields){
if (err === null){
console.error("DB initalized for " + devOrLive);
process.exit(1);
return true;
}else{
console.error(err);
process.exit(1);
return false;
_resetConnection: function() {
if (this.realClient) this.realClient.destroy();
this.realClient = mysql.createClient(options);
this.realClient.on('error', function(e) {
console.log("database connection down: " + e.toString());
});
},
ping: function(client_cb) {
exports.getSession = function(cb) {
var that = {};
var opts = {
host: hostname,
port: port,
database: db,
user: username,
password: password
};
var client;
function handleDisconnect() {
connection = mysql.createConnection(opts);
}
if(typeof(mysql.createConnection)=='undefined'){
client = mysql.createClient(opts);
}else{
client = new mysql.createConnection(opts);
client.connect(function(err) {
if(err){
console.error(err);
setTimeout(handleDisconnect, 2000);
}
});
client.on('error', function(err) {
console.error(err);
if(err.code === 'PROTOCOL_CONNECTION_LOST') {
handleDisconnect();
} else {
throw err;
}
});
cmbot.prototype.getMysqlClient = function() {
var cmbot = this;
var mysql = false;
try {
mysql = require('mysql').createClient({
host: cmbot.options.mysql.host,
user: cmbot.options.mysql.user,
password: cmbot.options.mysql.password
});
mysql.query('USE ' + cmbot.options.mysql.database);
} catch(e) {}
return mysql;
};
exports.connect = function(config, intern, callback) {
var db;
internals = intern;
internals.interfaces.SeederInterface._makeParamArgs = dummy;
if (typeof(mysql.createConnection) === 'undefined') {
db = config.db || new mysql.createClient(config);
} else {
db = config.db || new mysql.createConnection(config);
}
callback(null, new MysqlDriver(db));
};
var mysql = require('mysql')
, DATABASE = 'node_test'
, TABLE = 'members'
, client = mysql.createClient({
user: 'node'
, password: 'pass'
});
client.query('USE ' + DATABASE);
var mysqlUtil = module.exports = {
insertUser: function(user, res) {
client.query(
'INSERT INTO ' + TABLE + ' SET name = ?, email = ?'
, [user.name, user.email]
, function(err) {
client.query(
'SELECT * FROM ' + TABLE + ' WHERE name = ?'
, [user.name]
, function(err, results, fields) {
mysql: function (conf) {
var mysql = require('mysql');
var client = mysql.createClient(conf);
return require('./ext-mysql-client.js')(client);
},
sqlite: function (conf) {