<p align="center">
<a href="http://mariadb.com/">
<img src="https://mariadb.com/kb/static/images/logo-2018-black.png">
</a>
</p>
# MariaDB Node.js connector
[![npm package][npm-image]][npm-url]
[![Test Build][travis-image]][travis-url]
[![License (LGPL version 2.1)][licence-image]][licence-url]
[![codecov][codecov-image]][codecov-url]
**Non-blocking MariaDB and MySQL client for Node.js.**
MariaDB and MySQL client, 100% JavaScript, with TypeScript definition, with the Promise API.
version before 2.4 is compatible with Node.js 6+
version after 2.4 is compatible with Node.js 10+
## Documentation
See [promise documentation](https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/master/documentation/promise-api.md) for detailed API.
[Callback documentation](https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/master/documentation/callback-api.md) describe the callback wrapper for compatibility with existing drivers.
See [dedicated part](https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/master/documentation/promise-api.md#migrating-from-2x-or-mysqlmysql2-to-3x) for migration from mysql/mysql2 or from 2.x version.
## Why a New Client?
While there are existing MySQL clients that work with MariaDB, (such as the [`mysql`](https://www.npmjs.com/package/mysql) and [`mysql2`](https://www.npmjs.com/package/mysql2) clients), the MariaDB Node.js Connector offers new functionality, like [Insert Streaming](#insert-streaming), [Pipelining](#pipelining), [ed25519 plugin authentication](https://mariadb.org/history-of-mysql-mariadb-authentication-protocols/) while making no compromises on performance.
### Insert Streaming
Using a Readable stream in your application, you can stream `INSERT` statements to MariaDB through the Connector.
```javascript
https.get('https://someContent', readableStream => {
//readableStream implement Readable, driver will stream data to database
connection.query("INSERT INTO myTable VALUE (?)", [readableStream]);
});
```
### Pipelining
With Pipelining, the Connector sends commands without waiting for server results, preserving order. For instance, consider the use of executing two `INSERT` statements.
<p align="center">
<img src="./documentation/misc/pip.png">
</p>
The Connector doesn't wait for query results before sending the next `INSERT` statement. Instead, it sends queries one after the other, avoiding much of the network latency.
For more information, see the [Pipelining](/documentation/pipelining.md) documentation.
### Bulk insert
Some use cases require a large amount of data to be inserted into a database table. By using batch processing, these queries can be sent to the database in one call, thus improving performance.
For more information, see the [Batch](/documentation/batch.md) documentation.
## Benchmarks
MariaDB provides benchmarks comparing the Connector with popular Node.js MySQL clients, including:
* [`promise-mysql`](https://www.npmjs.com/package/promise-mysql) version 4.0.4 + [`mysql`](https://www.npmjs.com/package/mysql) version 2.17.1
* [`mysql2`](https://www.npmjs.com/package/mysql2) version 1.6.5
```
promise-mysql : 646 ops/sec ±2.20%
mysql2 : 746 ops/sec ±2.35%
mariadb : 961 ops/sec ±2.82%
```
query: **SELECT < all mysql fields >, 1 FROM mysql.user LIMIT 1**
<img src="./documentation/misc/bench.png" width="559" height="209"/>
For more information, see the [Benchmarks](/documentation/benchmarks.md) page.
## Quick Start
The MariaDB Connector is available through the Node.js repositories. You can install it using npm :
```
$ npm install mariadb
```
Using ECMAScript < 2017:
```js
const mariadb = require('mariadb');
const pool = mariadb.createPool({host: process.env.DB_HOST, user: process.env.DB_USER, connectionLimit: 5});
pool.getConnection()
.then(conn => {
conn.query("SELECT 1 as val")
.then(rows => { // rows: [ {val: 1}, meta: ... ]
return conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
})
.then(res => { // res: { affectedRows: 1, insertId: 1, warningStatus: 0 }
conn.release(); // release to pool
})
.catch(err => {
conn.release(); // release to pool
})
}).catch(err => {
//not connected
});
```
Using ECMAScript 2017:
```js
const mariadb = require('mariadb');
const pool = mariadb.createPool({host: process.env.DB_HOST, user: process.env.DB_USER, connectionLimit: 5});
async function asyncFunction() {
let conn;
try {
conn = await pool.getConnection();
const rows = await conn.query("SELECT 1 as val");
// rows: [ {val: 1}, meta: ... ]
const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
// res: { affectedRows: 1, insertId: 1, warningStatus: 0 }
} catch (err) {
throw err;
} finally {
if (conn) conn.release(); //release to pool
}
}
```
## Contributing
If you would like to contribute to the MariaDB Node.js Connector, please follow the instructions given in the [Developers Guide.](/documentation/developers-guide.md)
To file an issue or follow the development, see [JIRA](https://jira.mariadb.org/projects/CONJS/issues/).
[travis-image]:https://travis-ci.com/mariadb-corporation/mariadb-connector-nodejs.svg?branch=master
[travis-url]:https://travis-ci.com/mariadb-corporation/mariadb-connector-nodejs
[npm-image]:https://img.shields.io/npm/v/mariadb.svg
[npm-url]:http://npmjs.org/package/mariadb
[licence-image]:https://img.shields.io/badge/license-GNU%20LGPL%20version%202.1-green.svg?style=flat-square
[licence-url]:http://opensource.org/licenses/LGPL-2.1
[codecov-image]:https://codecov.io/gh/mariadb-corporation/mariadb-connector-nodejs/branch/master/graph/badge.svg
[codecov-url]:https://codecov.io/gh/mariadb-corporation/mariadb-connector-nodejs
没有合适的资源?快使用搜索试试~ 我知道了~
MariaDB Connector/Node.js(mariadb-connector-nodejs-3.0.0)Beta
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 47 浏览量
2022-01-17
21:10:35
上传
评论
收藏 383KB GZ 举报
温馨提示
共178个文件
js:145个
md:9个
png:5个
MariaDB Connector/Node.js(mariadb-connector-nodejs-3.0.0.tar.gz)Beta
资源推荐
资源详情
资源评论
收起资源包目录
MariaDB Connector/Node.js(mariadb-connector-nodejs-3.0.0)Beta (178个子文件)
ca.crt 1KB
server.crt 993B
client.crt 985B
.eslintrc 356B
.eslintrc 272B
.gitignore 99B
error-code.js 54KB
connection.js 45KB
test-batch.js 42KB
test-cluster.js 41KB
test-geometry.js 39KB
test-batch-callback.js 38KB
test-pool.js 37KB
collations.js 28KB
test-connection.js 27KB
test-batch-geometry-type.js 26KB
parser.js 23KB
test-error.js 23KB
test-pool-callback.js 21KB
packet-output-stream.js 20KB
test-ssl.js 19KB
test-auth-plugin.js 18KB
pool-base.js 16KB
batch-bulk.js 15KB
packet.js 15KB
ed25519-password-auth.js 15KB
test-connection-opts.js 14KB
test-integer.js 13KB
common_benchmarks.js 13KB
connection-options.js 12KB
binary-encoder.js 12KB
test-execute.js 12KB
pool-cluster.js 11KB
test-local-infile.js 11KB
test-transaction.js 11KB
test-multi-results.js 10KB
parse.js 10KB
test-debug.js 10KB
test-change-user.js 10KB
test-query.js 10KB
test-mapping.js 10KB
test-placholders.js 9KB
execute.js 9KB
handshake.js 9KB
text-encoder.js 9KB
test-utils.js 9KB
test-ok-packet.js 9KB
utils.js 8KB
test-query-values-in-sql.js 8KB
test-typecast.js 8KB
query.js 8KB
test-datetime.js 8KB
test-connection-options.js 8KB
test-execute-callback.js 7KB
pool-callback.js 7KB
test-parse.js 7KB
test-buffer.js 6KB
binary-decoder.js 6KB
test-packet-inputstream.js 6KB
test-json.js 6KB
caching-sha2-password-auth.js 6KB
test-string.js 5KB
compression-output-stream.js 5KB
test-streaming.js 5KB
change-user.js 5KB
command.js 5KB
connection-callback.js 5KB
packet-input-stream.js 5KB
errors.js 4KB
sha256-password-auth.js 4KB
compression-input-stream.js 4KB
test-reset.js 4KB
client-handshake-response.js 4KB
test-resultset-streaming.js 4KB
test-packet-compress-inputstream.js 4KB
test-compression.js 4KB
text-decoder.js 4KB
generate-mariadb.js 3KB
proxy.js 3KB
test-pipelining.js 3KB
test-initial-commands.js 3KB
test-big-query.js 3KB
pool-promise.js 3KB
test-socket.js 3KB
test-metadata.js 3KB
column-definition.js 3KB
capabilities.js 3KB
test-call.js 3KB
filtered-pool-cluster.js 3KB
test-enum.js 3KB
bench_promise_insert_batch.js 2KB
test-connection-meta.js 2KB
client-capabilities.js 2KB
initial-handshake.js 2KB
test-pool-options.js 2KB
test-pool-callback-event.js 2KB
pool-options.js 2KB
test-pool-event.js 2KB
test-options.js 2KB
base.js 2KB
共 178 条
- 1
- 2
资源评论
YunFeiDong
- 粉丝: 33
- 资源: 3849
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功