Skip to content

Commit

Permalink
feat: support mysql2 (#1)
Browse files Browse the repository at this point in the history
- support mysql2
- rename to myrds

Co-authored-by: raoha.rh <raohai.rh@antgroup.com>
  • Loading branch information
RaoHai and RaoHai authored Jan 30, 2024
1 parent 70869e2 commit eb9f391
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 112 deletions.
1 change: 1 addition & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ jobs:
with:
os: 'ubuntu-latest'
version: '16.17.0, 16, 18, 20'
mysql_version: '5, 8'
82 changes: 41 additions & 41 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# Changelog

## [6.3.0](https://github.com/ali-sdk/ali-rds/compare/v6.2.0...v6.3.0) (2023-07-31)
## [6.3.0](https://github.com/node-modules/myrds/v6.2.0...v6.3.0) (2023-07-31)


### Features

* stats 增加使用中的连接数 ([#115](https://github.com/ali-sdk/ali-rds/issues/115)) ([2b152a1](https://github.com/ali-sdk/ali-rds/commit/2b152a14b39291665c74910f2fe803d8318843db))
* stats 增加使用中的连接数 ([#115](https://github.com/node-modules/myrds/issues/115)) ([2b152a1](https://github.com/node-modules/myrds/commit/2b152a14b39291665c74910f2fe803d8318843db))

## [6.2.0](https://github.com/ali-sdk/ali-rds/compare/v6.1.0...v6.2.0) (2023-06-10)
## [6.2.0](https://github.com/node-modules/myrds/v6.1.0...v6.2.0) (2023-06-10)


### Features

* export connection and query diagnostics_channel ([#111](https://github.com/ali-sdk/ali-rds/issues/111)) ([64aa75d](https://github.com/ali-sdk/ali-rds/commit/64aa75d121d63ddae4fa4bd2a6e097773f280dfe))
* export connection and query diagnostics_channel ([#111](https://github.com/node-modules/myrds/issues/111)) ([64aa75d](https://github.com/node-modules/myrds/commit/64aa75d121d63ddae4fa4bd2a6e097773f280dfe))

## [6.1.0](https://github.com/ali-sdk/ali-rds/compare/v6.0.1...v6.1.0) (2023-06-09)
## [6.1.0](https://github.com/node-modules/myrds/v6.0.1...v6.1.0) (2023-06-09)


### Features

* dynamic retrieval of database connection configuration ([#110](https://github.com/ali-sdk/ali-rds/issues/110)) ([f437efb](https://github.com/ali-sdk/ali-rds/commit/f437efb439c1770561c1d4dc79318c632e7321d9))
* dynamic retrieval of database connection configuration ([#110](https://github.com/node-modules/myrds/issues/110)) ([f437efb](https://github.com/node-modules/myrds/commit/f437efb439c1770561c1d4dc79318c632e7321d9))

## [6.0.1](https://github.com/ali-sdk/ali-rds/compare/v6.0.0...v6.0.1) (2023-06-05)
## [6.0.1](https://github.com/node-modules/myrds/v6.0.0...v6.0.1) (2023-06-05)


### Bug Fixes

* mysql type not found ([#109](https://github.com/ali-sdk/ali-rds/issues/109)) ([6a9bc45](https://github.com/ali-sdk/ali-rds/commit/6a9bc452a8a73f9d697ee0e55f91b823ef153df4))
* mysql type not found ([#109](https://github.com/node-modules/myrds/issues/109)) ([6a9bc45](https://github.com/node-modules/myrds/commit/6a9bc452a8a73f9d697ee0e55f91b823ef153df4))

## [6.0.0](https://github.com/ali-sdk/ali-rds/compare/v5.1.2...v6.0.0) (2023-06-03)
## [6.0.0](https://github.com/node-modules/myrds/v5.1.2...v6.0.0) (2023-06-03)


### ⚠ BREAKING CHANGES
Expand All @@ -37,35 +37,35 @@

### Features

* use AsyncLocalStorage to refactor transaction, to make it more safe ([#108](https://github.com/ali-sdk/ali-rds/issues/108)) ([ae327fa](https://github.com/ali-sdk/ali-rds/commit/ae327fa5a350b48c4e1f56c2769524c5786e1152))
* use AsyncLocalStorage to refactor transaction, to make it more safe ([#108](https://github.com/node-modules/myrds/issues/108)) ([ae327fa](https://github.com/node-modules/myrds/commit/ae327fa5a350b48c4e1f56c2769524c5786e1152))


### Bug Fixes

* use master branch ([758877d](https://github.com/ali-sdk/ali-rds/commit/758877d9e01df74b9df12c65b7f625275996656b))
* use master branch ([758877d](https://github.com/node-modules/myrds/commit/758877d9e01df74b9df12c65b7f625275996656b))

## [5.1.2](https://github.com/ali-sdk/ali-rds/compare/v5.1.1...v5.1.2) (2023-03-06)
## [5.1.2](https://github.com/node-modules/myrds/v5.1.1...v5.1.2) (2023-03-06)


### Bug Fixes

* don't export protected methods ([#106](https://github.com/ali-sdk/ali-rds/issues/106)) ([b2757df](https://github.com/ali-sdk/ali-rds/commit/b2757dffdf76bb74e9fff8a89632d19704b03e4f))
* don't export protected methods ([#106](https://github.com/node-modules/myrds/issues/106)) ([b2757df](https://github.com/node-modules/myrds/commit/b2757dffdf76bb74e9fff8a89632d19704b03e4f))

## [5.1.1](https://github.com/ali-sdk/ali-rds/compare/v5.1.0...v5.1.1) (2023-03-05)
## [5.1.1](https://github.com/node-modules/myrds/v5.1.0...v5.1.1) (2023-03-05)


### Bug Fixes

* support multi lifecircle hooks ([#105](https://github.com/ali-sdk/ali-rds/issues/105)) ([53b0a70](https://github.com/ali-sdk/ali-rds/commit/53b0a7058e4f3e583dc4610b1d1338014b9f2c15))
* support multi lifecircle hooks ([#105](https://github.com/node-modules/myrds/issues/105)) ([53b0a70](https://github.com/node-modules/myrds/commit/53b0a7058e4f3e583dc4610b1d1338014b9f2c15))

## [5.1.0](https://github.com/ali-sdk/ali-rds/compare/v5.0.0...v5.1.0) (2023-03-05)
## [5.1.0](https://github.com/node-modules/myrds/v5.0.0...v5.1.0) (2023-03-05)


### Features

* support custom query lifecircle ([#104](https://github.com/ali-sdk/ali-rds/issues/104)) ([5941c69](https://github.com/ali-sdk/ali-rds/commit/5941c69b461ad581aa88c211ee6c60a88d4f5420))
* support custom query lifecircle ([#104](https://github.com/node-modules/myrds/issues/104)) ([5941c69](https://github.com/node-modules/myrds/commit/5941c69b461ad581aa88c211ee6c60a88d4f5420))

## [5.0.0](https://github.com/ali-sdk/ali-rds/compare/v4.1.0...v5.0.0) (2023-03-04)
## [5.0.0](https://github.com/node-modules/myrds/v4.1.0...v5.0.0) (2023-03-04)


### ⚠ BREAKING CHANGES
Expand All @@ -74,100 +74,100 @@

### Features

* impl with typescript ([#103](https://github.com/ali-sdk/ali-rds/issues/103)) ([1cf7814](https://github.com/ali-sdk/ali-rds/commit/1cf7814effb2876919e73d331547ecd14caf45f4))
* impl with typescript ([#103](https://github.com/node-modules/myrds/issues/103)) ([1cf7814](https://github.com/node-modules/myrds/commit/1cf7814effb2876919e73d331547ecd14caf45f4))

## [4.1.0](https://github.com/ali-sdk/ali-rds/compare/v4.0.3...v4.1.0) (2023-01-01)
## [4.1.0](https://github.com/node-modules/myrds/v4.0.3...v4.1.0) (2023-01-01)


### Features

* add unlock/lock tables ([#97](https://github.com/ali-sdk/ali-rds/issues/97)) ([4dc3452](https://github.com/ali-sdk/ali-rds/commit/4dc3452a375e0c242084e23c6e5f1cb76f1b647d))
* add unlock/lock tables ([#97](https://github.com/ali-sdk/ali-rds/issues/97)) ([0a61be6](https://github.com/ali-sdk/ali-rds/commit/0a61be6048db4df298bfff33c6d23bdcc0119b9a))
* add unlock/lock tables ([#97](https://github.com/node-modules/myrds/issues/97)) ([4dc3452](https://github.com/node-modules/myrds/commit/4dc3452a375e0c242084e23c6e5f1cb76f1b647d))
* add unlock/lock tables ([#97](https://github.com/node-modules/myrds/issues/97)) ([0a61be6](https://github.com/node-modules/myrds/commit/0a61be6048db4df298bfff33c6d23bdcc0119b9a))

## [4.0.3](https://github.com/ali-sdk/ali-rds/compare/v4.0.2...v4.0.3) (2022-12-22)
## [4.0.3](https://github.com/node-modules/myrds/v4.0.2...v4.0.3) (2022-12-22)


### Bug Fixes

* export pool getter from rds client ([#102](https://github.com/ali-sdk/ali-rds/issues/102)) ([4048807](https://github.com/ali-sdk/ali-rds/commit/40488070b8bbae853a75ebe7d82a6cff6c8d071d))
* export pool getter from rds client ([#102](https://github.com/node-modules/myrds/issues/102)) ([4048807](https://github.com/node-modules/myrds/commit/40488070b8bbae853a75ebe7d82a6cff6c8d071d))

## [4.0.2](https://github.com/ali-sdk/ali-rds/compare/v4.0.1...v4.0.2) (2022-12-22)
## [4.0.2](https://github.com/node-modules/myrds/v4.0.1...v4.0.2) (2022-12-22)


### Bug Fixes

* should export conn property ([#101](https://github.com/ali-sdk/ali-rds/issues/101)) ([37afa42](https://github.com/ali-sdk/ali-rds/commit/37afa420f3330cbc7a5e6e68da88086339a2a955))
* should export conn property ([#101](https://github.com/node-modules/myrds/issues/101)) ([37afa42](https://github.com/node-modules/myrds/commit/37afa420f3330cbc7a5e6e68da88086339a2a955))

---

4.0.1 / 2022-12-14
==================

**fixes**
* [[`add4669`](http://github.com/ali-sdk/ali-rds/commit/add466917422b15deddd434c25595b6f6082bb6b)] - 🐛 FIX: Export db pool stats (#95) (fengmk2 <<fengmk2@gmail.com>>)
* [[`add4669`](http://github.com/node-modules/myrds/commit/add466917422b15deddd434c25595b6f6082bb6b)] - 🐛 FIX: Export db pool stats (#95) (fengmk2 <<fengmk2@gmail.com>>)

4.0.0 / 2022-12-14
==================

**features**
* [[`6296b5b`](http://github.com/ali-sdk/ali-rds/commit/6296b5b1a0e08bf88097937a0b579a4c90b13a2d)] - 📦 NEW: [BREAKING] Refactor impl base on async/await (#94) (fengmk2 <<fengmk2@gmail.com>>)
* [[`6296b5b`](http://github.com/node-modules/myrds/commit/6296b5b1a0e08bf88097937a0b579a4c90b13a2d)] - 📦 NEW: [BREAKING] Refactor impl base on async/await (#94) (fengmk2 <<fengmk2@gmail.com>>)

3.4.1 / 2022-12-13
==================

**fixes**
* [[`d983478`](http://github.com/ali-sdk/ali-rds/commit/d983478d40203357c71187c94f44ef3afab0b604)] - fix: handle concurrent transaction (#85) (killa <<killa123@126.com>>)
* [[`d983478`](http://github.com/node-modules/myrds/commit/d983478d40203357c71187c94f44ef3afab0b604)] - fix: handle concurrent transaction (#85) (killa <<killa123@126.com>>)

**others**
* [[`61e8e38`](http://github.com/ali-sdk/ali-rds/commit/61e8e38208acf4a9cc1780128063318f7f0e17ac)] - Create codeql.yml (fengmk2 <<fengmk2@gmail.com>>)
* [[`61e8e38`](http://github.com/node-modules/myrds/commit/61e8e38208acf4a9cc1780128063318f7f0e17ac)] - Create codeql.yml (fengmk2 <<fengmk2@gmail.com>>)

3.4.0 / 2020-07-16
==================

**features**
* [[`2e99ab8`](http://github.com/ali-sdk/ali-rds/commit/2e99ab8ce872b8482fe2b0a29af51a7a99aaff84)] - feat: export sqlstring method (#79) (Haoliang Gao <<sakura9515@gmail.com>>)
* [[`2e99ab8`](http://github.com/node-modules/myrds/commit/2e99ab8ce872b8482fe2b0a29af51a7a99aaff84)] - feat: export sqlstring method (#79) (Haoliang Gao <<sakura9515@gmail.com>>)

3.3.1 / 2019-04-24
==================

**fixes**
* [[`52147de`](git@github.com:ali-sdk/ali-rds/commit/52147de9d7405b02efcf84ef28a11a4097675972)] - fix: query parameters are not allowed to be included in where (#67) (Hoyt <<hoythan@gmail.com>>)
* [[`52147de`](git@github.com:node-modules/myrds/commit/52147de9d7405b02efcf84ef28a11a4097675972)] - fix: query parameters are not allowed to be included in where (#67) (Hoyt <<hoythan@gmail.com>>)

**others**
* [[`0f9f23b`](git@github.com:ali-sdk/ali-rds/commit/0f9f23bbd935650a1440537b18aaa982a6db2d44)] - chore: remove node 4 in ci (dead-horse <<dead_horse@qq.com>>)
* [[`0f9f23b`](git@github.com:node-modules/myrds/commit/0f9f23bbd935650a1440537b18aaa982a6db2d44)] - chore: remove node 4 in ci (dead-horse <<dead_horse@qq.com>>)

3.3.0 / 2018-12-11
==================

**features**
* [[`0d4d4ab`](http://github.com/ali-sdk/ali-rds/commit/0d4d4ab99a7cd655180f22d4d95e3cfef8c8714b)] - feat: where condition support NULL value (#60) (fengmk2 <<fengmk2@gmail.com>>)
* [[`0d4d4ab`](http://github.com/node-modules/myrds/commit/0d4d4ab99a7cd655180f22d4d95e3cfef8c8714b)] - feat: where condition support NULL value (#60) (fengmk2 <<fengmk2@gmail.com>>)

3.2.0 / 2018-11-19
==================

**features**
* [[`b227bc1`](http://github.com/ali-sdk/ali-rds/commit/b227bc12e5c6252264d4761b72f915b73d53c688)] - feat: support doomed transaction scope on test cases (#58) (AngrySean <<xujihui1985@gmail.com>>)
* [[`b227bc1`](http://github.com/node-modules/myrds/commit/b227bc12e5c6252264d4761b72f915b73d53c688)] - feat: support doomed transaction scope on test cases (#58) (AngrySean <<xujihui1985@gmail.com>>)

3.1.0 / 2018-09-30
==================

**features**
* [[`859d818`](http://github.com/ali-sdk/ali-rds/commit/859d818d7e327d1ff590d363dfbf3135d8c90454)] - feat: update multiple rows (#55) (Hang Jiang <<jianghangscu@gmail.com>>)
* [[`859d818`](http://github.com/node-modules/myrds/commit/859d818d7e327d1ff590d363dfbf3135d8c90454)] - feat: update multiple rows (#55) (Hang Jiang <<jianghangscu@gmail.com>>)

**fixes**
* [[`db6d596`](http://github.com/ali-sdk/ali-rds/commit/db6d59616f4b5083142bed554fb104c1b5a7c14e)] - fix: add default value now() of `gmt_modified` and `gmt_create` (#56) (Hang Jiang <<jianghangscu@gmail.com>>)
* [[`db6d596`](http://github.com/node-modules/myrds/commit/db6d59616f4b5083142bed554fb104c1b5a7c14e)] - fix: add default value now() of `gmt_modified` and `gmt_create` (#56) (Hang Jiang <<jianghangscu@gmail.com>>)

**others**
* [[`db3524c`](http://github.com/ali-sdk/ali-rds/commit/db3524c8da7f8b32291695a2fc5497ea8fddd155)] - doc: add object arguments in readme (#52) (凯 方 <<fkvsssl@126.com>>)
* [[`db3524c`](http://github.com/node-modules/myrds/commit/db3524c8da7f8b32291695a2fc5497ea8fddd155)] - doc: add object arguments in readme (#52) (凯 方 <<fkvsssl@126.com>>)

3.0.1 / 2017-09-26
==================

**fixes**
* [[`5ca4489`](http://github.com/ali-sdk/ali-rds/commit/5ca4489b903923302c81a8c9c8ac94c0afbce819)] - fix: don't redefined sqlstring.escape (#39) (Yiyu He <<dead_horse@qq.com>>)
* [[`5ca4489`](http://github.com/node-modules/myrds/commit/5ca4489b903923302c81a8c9c8ac94c0afbce819)] - fix: don't redefined sqlstring.escape (#39) (Yiyu He <<dead_horse@qq.com>>)

**others**
* [[`004713c`](http://github.com/ali-sdk/ali-rds/commit/004713cf9a4aa2da84a9f02348996b1a8ec82430)] - doc: fix typo 'Can\'t not' => 'Can not' (#34) (dreamswhite <<dreamswhite@aliyun.com>>)
* [[`004713c`](http://github.com/node-modules/myrds/commit/004713cf9a4aa2da84a9f02348996b1a8ec82430)] - doc: fix typo 'Can\'t not' => 'Can not' (#34) (dreamswhite <<dreamswhite@aliyun.com>>)

3.0.0 / 2017-04-02
==================
Expand Down Expand Up @@ -219,7 +219,7 @@
==================

* feat: add *beginTransactionScope(scope)
* docs: require ali-rds
* docs: require myrds

2.0.0 / 2015-06-08
==================
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This software is licensed under the MIT License.

Copyright (c) 2015-present ali-sdk and other contributors
Copyright (c) 2024-present myrds and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# ali-rds
# myrds

[![NPM version][npm-image]][npm-url]
[![Node.js CI](https://github.com/ali-sdk/ali-rds/actions/workflows/nodejs.yml/badge.svg)](https://github.com/ali-sdk/ali-rds/actions/workflows/nodejs.yml)
[![Node.js CI](https://github.com/node-modules/myrds/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/myrds/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/ali-rds.svg?style=flat-square
[npm-url]: https://npmjs.org/package/ali-rds
[codecov-image]: https://codecov.io/github/ali-sdk/ali-rds/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/ali-sdk/ali-rds?branch=master
[download-image]: https://img.shields.io/npm/dm/ali-rds.svg?style=flat-square
[download-url]: https://npmjs.org/package/ali-rds
[npm-image]: https://img.shields.io/npm/v/myrds.svg?style=flat-square
[npm-url]: https://npmjs.org/package/myrds
[codecov-image]: https://codecov.io/github/node-modules/myrds/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/node-modules/myrds?branch=master
[download-image]: https://img.shields.io/npm/dm/myrds.svg?style=flat-square
[download-url]: https://npmjs.org/package/myrds

Aliyun RDS client.
MY RDS client.
RDS, Relational Database Service. Equal to well know Amazon [RDS](http://aws.amazon.com/rds/).

Support `MySQL` protocol only.
Expand All @@ -22,7 +22,7 @@ Support `MySQL` protocol only.
### Create RDS instance

```ts
import { RDSClient } from 'ali-rds';
import { RDSClient } from 'myrds';

const db = new RDSClient({
host: 'your-rds-address.mysql.rds.aliyuncs.com',
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ali-rds",
"version": "6.3.0",
"description": "Aliyun RDS client",
"name": "myrds",
"version": "7.0.0",
"description": "My RDS Client",
"main": "lib/client.js",
"types": "lib/client.d.ts",
"files": [
Expand All @@ -17,8 +17,7 @@
"prepublishOnly": "npm run clean && npm run build"
},
"dependencies": {
"@types/mysql": "^2.15.21",
"mysql": "^2.18.1"
"mysql2": "^3.9.1"
},
"devDependencies": {
"@eggjs/tsconfig": "^1.3.2",
Expand All @@ -31,17 +30,18 @@
"mm": "^3.3.0",
"typescript": "^5.1.3"
},
"homepage": "https://github.com/ali-sdk/ali-rds",
"homepage": "https://github.com/node-modules/myrds",
"repository": {
"type": "git",
"url": "git://github.com/ali-sdk/ali-rds.git"
"url": "git://github.com/node-modules/myrds.git"
},
"bugs": {
"url": "https://github.com/ali-sdk/ali-rds/issues"
"url": "https://github.com/node-modules/myrds/issues"
},
"keywords": [
"ali-rds",
"mysql"
"myrds",
"mysql",
"mysql2"
],
"engines": {
"node": ">= 16.17.0"
Expand Down
33 changes: 24 additions & 9 deletions src/PoolConfig.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import MySQLPoolConfig from 'mysql/lib/PoolConfig';
import type { PoolConfig, ConnectionConfig } from 'mysql';
import { ConnectionConfig } from 'mysql2';
import type { PoolOptions } from 'mysql2';
import type { GetConnectionConfig } from './types';

export class RDSPoolConfig extends MySQLPoolConfig {
export class RDSPoolConfig {
#getConnectionConfig: GetConnectionConfig;
#options: PoolOptions;

constructor(options: PoolConfig, getConnectionConfig: GetConnectionConfig) {
super(options);
waitForConnections: boolean;
connectionLimit: number;
maxIdle: number;
idleTimeout: number;
queueLimit: number;

constructor(options: PoolOptions, getConnectionConfig: GetConnectionConfig) {
this.#options = options;
this.#getConnectionConfig = getConnectionConfig;

// mysql2 has not exports ConnectionConfig
// so impl it mauanlly
this.waitForConnections = options.waitForConnections === undefined ? true : Boolean(options.waitForConnections);
this.connectionLimit = isNaN(options.connectionLimit!) ? 10 : Number(options.connectionLimit);
this.maxIdle = isNaN(options.maxIdle!) ? this.connectionLimit : Number(options.maxIdle);
this.idleTimeout = isNaN(options.idleTimeout!) ? 60000 : Number(options.idleTimeout);
this.queueLimit = isNaN(options.queueLimit!) ? 0 : Number(options.queueLimit);
}

newConnectionConfig(): ConnectionConfig {
return {
...super.newConnectionConfig(),
get connectionConfig(): any {
return new ConnectionConfig({
...this.#options,
...this.#getConnectionConfig(),
};
});
}
}
Loading

0 comments on commit eb9f391

Please sign in to comment.