
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
namshi-node-mysql
Advanced tools
This wrapper provides some enhancements for node-mysql2
This module can be installed with either yarn or npm:
$ yarn add namshi-node-mysql
$ npm install namshi-node-mysql --save
query()
uses prepared statements but does not support bulk operations.
let config = {
host: "localhost",
user: "foo",
password: "bar",
database: "db"
}
let db = require('namshi-node-mysql')(config);
db.query('UPDATE foo SET key = ?', ['value']).then(() => {
return db.query('SELECT * FROM foo');
}).spread(rows => {
console.log('Look at all the foo', rows);
});
// using multiple databases, you can add a "name" key to your config object. For example:
let config = {
name: "second-db",
host: "localhost",
user: "foo",
password: "bar",
database: "db"
}
let db2 = require('namshi-node-mysql')(config);
db2.query('SELECT * FROM users').spread(users => {
console.log('Hello users', users);
});
// You can enable debugging by passing the `debug` parameter as follow:
// by default it is set to false.
let config = {
host: "localhost",
user: "foo",
password: "bar",
database: "db",
debug: true;
}
bulk()
uses execute
which supports prepared statements and we use prepared statements for bulk.
let config = {
host: "localhost",
user: "foo",
password: "bar",
database: "db"
}
var values = [
['demian', 'demian@gmail.com', 1],
['john', 'john@gmail.com', 2],
['mark', 'mark@gmail.com', 3],
['pete', 'pete@gmail.com', 4]
];
let db = require('namshi-node-mysql')(config);
db.bulk('INSERT INTO foo (name, email, n) VALUES ?', values).then(() => {
return db.query('SELECT * FROM foo');
}).spread(rows => {
console.log('Look at all the foo', rows);
});
prepareBulk()
can be used if you want to format a query for bulk operation with a connection reused for a transaction.
let config = {
host: "localhost",
user: "foo",
password: "bar",
database: "db"
}
var values = [
['demian', 'demian@gmail.com', 1],
['john', 'john@gmail.com', 2],
['mark', 'mark@gmail.com', 3],
['pete', 'pete@gmail.com', 4]
];
let db = require('namshi-node-mysql')(config);
let connection;
db.startTransaction().then(conn => {
connection = conn;
}).then(() => {
let [query, params] = db.prepareBulk('INSERT INTO foo (name, email, n) VALUES ?', [values]);
return connection.execute(query, params);
}).then(result => {
return db.commit(connection);
}).then(result => {
console.log('Rows committed');
}).catch(err => {
db.rollback(connection).then(result => {
console.log('Rollback executed due to ', err.message);
});
})
let config = {
host: "localhost",
user: "foo",
password: "bar",
database: "db",
namedPlaceholders: true
}
let db = require('namshi-node-mysql')(config);
db.query('SELECT * FROM users WHERE LIMIT = :limit', {limit: 10}).spread( users => {
console.log('Hello users', users);
});
let config = {
host: "localhost",
user: "foo",
password: "bar",
database: "db"
}
let db = require('namshi-node-mysql')(config);
let connection;
db.startTransaction(30).then(conn => {
connection = con;
}).catch(err) {
//handle error
};
//default timeout here is set to 20
db.startTransaction().then(conn => {
connection = con;
}).catch(err) {
//handle error
};
db.commit(connection).catch(err => {
//handle err
});
db.rollback(connection).catch(err => {
//handle err
});
This library depends on node-mysql2. It is also considered a breaking-change upgrade of node-mysql2-promise.
FAQs
Small wrapper for mysql2.
We found that namshi-node-mysql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.