
Research
/Security News
Popular npm Packages in the keyv and Cacheable Namespaces Compromised in Active Supply Chain Attack
Popular npm packages keyv and cacheable compromised.
node-mysql-helper
Advanced tools
A lightweight Promise-based wrapper and helper for felixge's node-mysql.
A lightweight Promise-based wrapper and helper for felixge's node-Mysql.
##Features:
##Initialize
Format you connection options based on felixge's options.
var Mysql = require('node-mysql-helper');
var mysqlOptions = {
host: 'localhost',
user: 'myuser',
password: 'chicken',
database: 'mydb',
socketPath: false,
connectionLimit: 5
};
//For 5 pooled connections
Mysql.connect(mysqlOptions);
//find user id 35
Mysql.record('user', 35)
.then(function(record){
console.log(record);
})
.catch(function(err){
console.log('Error fetching record, mysql error:', err.message);
});
//or select with an object
Mysql.record('user', {id: 35})
.then(function(record){
console.log(record);
})
.catch(function(err){
console.log('Error fetching record, mysql error:', err.message);
});
var insert = {
email: 'gdbate@gmail.com',
firstName: 'Greg',
lastName: 'Bate',
createdAt: '2015-10-07 21-22:31'
};
Mysql.insert('user', insert)
.then(function(info){
console.log('New User Entered!', info);
})
.catch(function(err){
console.log('Error creating new user, mysql error:', err.message);
});
//info is an object with affectedRows and insertId
There is also a boolean 3rd argument, true if you want "INSERT IGNORE"
var where = {
firstName: 'Greg',
lastName: 'Bate'
};
var update = {
lastSeen: '2015-10-07 21-54:58'
};
Mysql.update('user', where, update)
.then(function(info){
console.log('User Updated!', info);
})
.catch(function(err){
console.log('Error updating record, mysql error:', err.message);
});
//info is an object with affectedRows, changedRows
Used in case entering data conflicts with a unique index
var insert = {
email: 'gdbate@gmail.com',
firstName: 'Greg',
lastName: 'Bate',
lastSeen: '2015-10-07 21-49:58'
};
var update = {
lastSeen: '2015-10-07 21-49:58'
};
Mysql.insertUpdate('user', insert, update)
.then(function(info){
console.log('New User Entered (or updated)!', info);
})
.catch(function(err){
console.log('Error creating new user, mysql error:', err.message);
});
//info is an object with affectedRows, changedRows and insertId (where applicable)
Don't forget to release the pooled connection so another process can use it.
//query has sql structure
//values will be placed in the query when escaped, and are optional
Mysql.query(query, values)
.then(function(results){
console.log('my query results', results);
})
.catch(function(err){
reject(err);
});
The query values are used in the same way felixge's module expects it. They are also optional.
//or select with an object
Mysql.delete('user', {id: 35})
.then(function(record){
console.log(record);
})
.catch(function(err){
console.log('Error deleting record, mysql error:', err.message);
});
//Get last query (after escaping values)
var last = Mysql.getLastQuery();
//Escape a database,table or column name
var table = Mysql.escapeId(tableName);
//Escape a string
var noSqlInject = Mysql.escapeId(req.body.firstName);
FAQs
A lightweight Promise-based wrapper and helper for felixge's node-mysql.
We found that node-mysql-helper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Popular npm packages keyv and cacheable compromised.

Security News
A misconfiguration gave three Anthropic models internet access, and one, believing it was in a simulation, shipped a credential-stealing package to PyPI.

Security News
/Company News
Socket has joined the new Composer and Packagist sponsorship program as a launch sponsor, supporting the team that keeps PHP's package ecosystem secure.