@7digital/mysql2-timeout 中文文档教程
MySQL2 Timeout
[mysql2
] 连接池query
的封装,支持acquireTimeout
和queryTimeout
选项。
Installation
npm install mysql2 @7digital/mysql2-timeout
Usage
只需使用它代替 mysql2
并调用 connect
传递 queryTimeout
和 acquireTimeout
毫秒值。 如果没有通过,每个将默认为 10 秒。 所有其他选项将直接传递给 mysql2
。
如果连接获取超时,将抛出 DatabaseTimeout
错误。
如果查询超时,将
- kill the connection
- attempt to kill the outstanding query in the background
- throw a
DatabaseTimeout
error
只暴露mysql2
连接池promise接口。
Example
const database = require('@7digital/mysql2-timeout');
async function main() {
const db = await database.connect({
host: 'localhost',
user: 'root',
database: 'test',
queryTimeout: 5000,
acquireTimeout: 2000
});
await db.query('SELECT 1');
}
Developing
docker-compose run test
运行一次测试。
docker-compose run watch
当源或测试更改时运行测试。
MySQL2 Timeout
A wrapper for [mysql2
] connection pool query
to support acquireTimeout
and queryTimeout
options.
Installation
npm install mysql2 @7digital/mysql2-timeout
Usage
Just use this instead of mysql2
and call connect
passing queryTimeout
and acquireTimeout
millisecond values. If not passed, each will default to 10 seconds. All other options will be passed directly to mysql2
.
If connection aquisition times out, a DatabaseTimeout
error will be thrown.
If querying times out, it will
- kill the connection
- attempt to kill the outstanding query in the background
- throw a
DatabaseTimeout
error
This only exposes the mysql2
connection pool promise interface.
Example
const database = require('@7digital/mysql2-timeout');
async function main() {
const db = await database.connect({
host: 'localhost',
user: 'root',
database: 'test',
queryTimeout: 5000,
acquireTimeout: 2000
});
await db.query('SELECT 1');
}
Developing
docker-compose run test
Runs the tests once.
docker-compose run watch
Runs the tests when the source or tests change.