mysql2
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
denque | 2.1.0 | 9.01 kB | Apache-2.0 | prod | |
generate-function | 2.3.1 | 3.55 kB | MIT | prod | |
iconv-lite | 0.6.3 | 186.2 kB | MIT | prod | |
long | 5.2.3 | 24.15 kB | Apache-2.0 | prod | |
lru-cache | 8.0.5 | 133.41 kB | ISC | prod | |
named-placeholders | 1.1.3 | 2.96 kB | MIT | prod | |
seq-queue | 0.0.5 | 5.31 kB | UNKNOWN | prod | 1 |
sqlstring | 2.3.3 | 6.22 kB | MIT | prod |
MySQL2 is a robust MySQL client for Node.js, putting an exclusive focus on performance. It supports features such as prepared statements, non-UTF8 encodings, binary log protocol, data compression, and SSL among others. MySQL2 is free from native bindings, meaning it can be smoothly installed on Linux, Mac OS, or Windows without any issues.
To use MySQL2, you first need to install it by running the command npm install --save mysql2
. Once installed, you can start incorporating it in your code as follows:
// importing the client
const mysql = require('mysql2');
// creating a connection to your database
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'test'
});
// executing a simple query
connection.query(
'SELECT * FROM `table` WHERE `name` = "Page" AND `age` > 45',
function(err, results, fields) {
console.log(results); // returns rows provided by the server
console.log(fields); // contains extra meta data about results, if available
}
);
// executing a query with a placeholder
connection.query(
'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',
['Page', 45],
function(err, results) {
console.log(results);
}
);
For more advanced usages such as using prepared statements, connection pools, Promise wrapper, and more, refer to the code provided in the readme.
The MySQL2 documentation can be found directly here in the GitHub repository. It provides comprehensive insights on how to use the package, including a multitude of code examples for understanding advanced concepts. Also, the readme provides a precise overview of the package, starting from installation and basic usage, to more advanced topics. For TypeScript users, there's also a separate TypeScript documentation with relevant code examples.