Skip to content

Commit 3093528

Browse files
authored
feat: use @eggjs/rds instead of ali-rds (#32)
BREAKING CHANGE: drop Node.js < 18 support BREAKING CHANGE: use mysql2 instead of mysql closes #31 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Documentation** - Updated usage instructions and contributor displays with corrected typographical errors. - **Chores** - Removed outdated contributor templates and automation workflows. - **Dependencies** - Migrated to a new database client package and raised the minimum Node.js version requirement. - **Tests** - Refined error validations in database operations for improved error reporting. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 7086a99 commit 3093528

10 files changed

+32
-138
lines changed

.github/PULL_REQUEST_TEMPLATE.md

-24
This file was deleted.

.github/workflows/codeql-analysis.yml

-72
This file was deleted.

.github/workflows/nodejs.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ name: CI
33
on:
44
push:
55
branches: [ master ]
6-
76
pull_request:
87
branches: [ master ]
98

10-
workflow_dispatch: {}
11-
129
jobs:
1310
Job:
1411
name: Node.js
15-
uses: fengmk2/github-actions/.github/workflows/node-test-mysql.yml@master
12+
uses: node-modules/github-actions/.github/workflows/node-test-mysql.yml@master
1613
with:
1714
os: 'ubuntu-latest'
18-
version: '16, 18'
15+
version: '16, 18, 20, 22'
16+
secrets:
17+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/release.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ on:
44
push:
55
branches: [ master ]
66

7-
workflow_dispatch: {}
8-
97
jobs:
108
release:
119
name: Node.js
12-
uses: artusjs/github-actions/.github/workflows/node-release.yml@v1
10+
uses: eggjs/github-actions/.github/workflows/node-release.yml@master
1311
secrets:
1412
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1513
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
16-
with:
17-
checkTest: false

README.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[download-image]: https://img.shields.io/npm/dm/egg-mysql.svg?style=flat-square
1313
[download-url]: https://npmjs.org/package/egg-mysql
1414

15-
Aliyun rds client(support mysql portocal) for egg framework
15+
Aliyun rds client(support mysql protocol) for egg framework
1616

1717
## Install
1818

@@ -22,7 +22,7 @@ npm i egg-mysql --save
2222

2323
MySQL Plugin for egg, support egg application access to MySQL database.
2424

25-
This plugin based on [ali-rds](https://github.com/ali-sdk/ali-rds), if you want to know specific usage, you should refer to the document of [ali-rds](https://github.com/ali-sdk/ali-rds).
25+
This plugin based on [@eggjs/rds], if you want to know specific usage, you should refer to the document of [@eggjs/rds].
2626

2727
## Configuration
2828

@@ -225,7 +225,7 @@ await app.mysql.insert(table, {
225225

226226
#### Custom literal
227227

228-
The following demo showed how to call `CONCAT(s1, ...sn)` funtion in mysql to do string splicing.
228+
The following demo showed how to call `CONCAT(s1, ...sn)` function in mysql to do string splicing.
229229

230230
```ts
231231
const Literal = app.mysql.literals.Literal;
@@ -247,14 +247,10 @@ Please open an issue [here](https://github.com/eggjs/egg/issues).
247247

248248
[MIT](LICENSE)
249249

250-
<!-- GITCONTRIBUTOR_START -->
251-
252250
## Contributors
253251

254-
|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/893152?v=4" width="100px;"/><br/><sub><b>jtyjty99999</b></sub>](https://github.com/jtyjty99999)<br/>|[<img src="https://avatars.githubusercontent.com/u/360661?v=4" width="100px;"/><br/><sub><b>popomore</b></sub>](https://github.com/popomore)<br/>|[<img src="https://avatars.githubusercontent.com/u/32174276?v=4" width="100px;"/><br/><sub><b>semantic-release-bot</b></sub>](https://github.com/semantic-release-bot)<br/>|[<img src="https://avatars.githubusercontent.com/u/227713?v=4" width="100px;"/><br/><sub><b>atian25</b></sub>](https://github.com/atian25)<br/>|[<img src="https://avatars.githubusercontent.com/u/985607?v=4" width="100px;"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|
255-
| :---: | :---: | :---: | :---: | :---: | :---: |
256-
[<img src="https://avatars.githubusercontent.com/u/6587734?v=4" width="100px;"/><br/><sub><b>AntiMoron</b></sub>](https://github.com/AntiMoron)<br/>|[<img src="https://avatars.githubusercontent.com/u/7298095?v=4" width="100px;"/><br/><sub><b>guoshencheng</b></sub>](https://github.com/guoshencheng)<br/>|[<img src="https://avatars.githubusercontent.com/u/37185773?v=4" width="100px;"/><br/><sub><b>Krryxa</b></sub>](https://github.com/Krryxa)<br/>|[<img src="https://avatars.githubusercontent.com/u/7459652?v=4" width="100px;"/><br/><sub><b>cnwangjie</b></sub>](https://github.com/cnwangjie)<br/>|[<img src="https://avatars.githubusercontent.com/u/613990?v=4" width="100px;"/><br/><sub><b>starandtina</b></sub>](https://github.com/starandtina)<br/>|[<img src="https://avatars.githubusercontent.com/u/5218468?v=4" width="100px;"/><br/><sub><b>shangwenhe</b></sub>](https://github.com/shangwenhe)<br/>
252+
[![Contributors](https://contrib.rocks/image?repo=eggjs/core)](https://github.com/eggjs/core/graphs/contributors)
257253

258-
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Mon Mar 06 2023 21:57:18 GMT+0800`.
254+
Made with [contributors-img](https://contrib.rocks).
259255

260-
<!-- GITCONTRIBUTOR_END -->
256+
[@eggjs/rds]: https://github.com/node-modules/rds

README.zh-CN.md

+6-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
MySQL 插件是为 egg 提供 MySQL 数据库访问的功能
1616

17-
此插件基于 [ali-rds] 实现一个简单的配置封装,具体使用方法你还需要阅读 [ali-rds] 的文档。
17+
此插件基于 [@eggjs/rds] 实现一个简单的配置封装,具体使用方法你还需要阅读 [@eggjs/rds] 的文档。
1818

1919
## 安装
2020

@@ -119,7 +119,7 @@ await client2.query(sql, values);
119119

120120
#### app.mysql
121121

122-
如果开启了 `config.mysql.app = true`,则会在 app 上注入 [ali-rds] 客户端 的 [Singleton 单例](https://github.com/eggjs/egg/blob/master/lib/core/singleton.js)
122+
如果开启了 `config.mysql.app = true`,则会在 app 上注入 [@eggjs/rds] 客户端 的 [Singleton 单例](https://github.com/eggjs/egg/blob/master/lib/core/singleton.js)
123123

124124
```ts
125125
await app.mysql.query(sql);
@@ -130,7 +130,7 @@ await app.mysqls.get('db1').query(sql);
130130

131131
#### agent.mysql
132132

133-
如果开启了 `config.mysql.agent = true`,则会在 agent 上注入 [ali-rds] 客户端 的 [Singleton 单例](https://github.com/eggjs/egg/blob/master/lib/core/singleton.js)
133+
如果开启了 `config.mysql.agent = true`,则会在 agent 上注入 [@eggjs/rds] 客户端 的 [Singleton 单例](https://github.com/eggjs/egg/blob/master/lib/core/singleton.js)
134134

135135
```ts
136136
await agent.mysql.query(sql);
@@ -270,16 +270,10 @@ Please open an issue [here](https://github.com/eggjs/egg/issues).
270270

271271
[MIT](LICENSE)
272272

273-
[ali-rds]: https://github.com/ali-sdk/ali-rds
274-
275-
<!-- GITCONTRIBUTOR_START -->
276-
277273
## Contributors
278274

279-
|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/893152?v=4" width="100px;"/><br/><sub><b>jtyjty99999</b></sub>](https://github.com/jtyjty99999)<br/>|[<img src="https://avatars.githubusercontent.com/u/360661?v=4" width="100px;"/><br/><sub><b>popomore</b></sub>](https://github.com/popomore)<br/>|[<img src="https://avatars.githubusercontent.com/u/32174276?v=4" width="100px;"/><br/><sub><b>semantic-release-bot</b></sub>](https://github.com/semantic-release-bot)<br/>|[<img src="https://avatars.githubusercontent.com/u/227713?v=4" width="100px;"/><br/><sub><b>atian25</b></sub>](https://github.com/atian25)<br/>|[<img src="https://avatars.githubusercontent.com/u/985607?v=4" width="100px;"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|
280-
| :---: | :---: | :---: | :---: | :---: | :---: |
281-
[<img src="https://avatars.githubusercontent.com/u/6587734?v=4" width="100px;"/><br/><sub><b>AntiMoron</b></sub>](https://github.com/AntiMoron)<br/>|[<img src="https://avatars.githubusercontent.com/u/7298095?v=4" width="100px;"/><br/><sub><b>guoshencheng</b></sub>](https://github.com/guoshencheng)<br/>|[<img src="https://avatars.githubusercontent.com/u/37185773?v=4" width="100px;"/><br/><sub><b>Krryxa</b></sub>](https://github.com/Krryxa)<br/>|[<img src="https://avatars.githubusercontent.com/u/7459652?v=4" width="100px;"/><br/><sub><b>cnwangjie</b></sub>](https://github.com/cnwangjie)<br/>|[<img src="https://avatars.githubusercontent.com/u/613990?v=4" width="100px;"/><br/><sub><b>starandtina</b></sub>](https://github.com/starandtina)<br/>|[<img src="https://avatars.githubusercontent.com/u/5218468?v=4" width="100px;"/><br/><sub><b>shangwenhe</b></sub>](https://github.com/shangwenhe)<br/>
275+
[![Contributors](https://contrib.rocks/image?repo=eggjs/core)](https://github.com/eggjs/core/graphs/contributors)
282276

283-
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Mon Mar 06 2023 21:57:18 GMT+0800`.
277+
Made with [contributors-img](https://contrib.rocks).
284278

285-
<!-- GITCONTRIBUTOR_END -->
279+
[@eggjs/rds]: https://github.com/node-modules/rds

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RDSClient } from 'ali-rds';
1+
import type { RDSClient } from '@eggjs/rds';
22

33
type EggMySQL = RDSClient;
44

lib/mysql.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Application, Agent } from 'egg';
2-
import { RDSClient } from 'ali-rds';
2+
import { RDSClient } from '@eggjs/rds';
33

44
let count = 0;
55
function createOneClient(config: Record<string, any>, app: Application | Agent) {

package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"database"
2121
],
2222
"dependencies": {
23-
"ali-rds": "^6.4.0"
23+
"@eggjs/rds": "^1.2.1"
2424
},
2525
"devDependencies": {
2626
"@eggjs/tsconfig": "^1.3.2",
@@ -31,15 +31,13 @@
3131
"egg-mock": "^5.10.6",
3232
"eslint": "^8.16.0",
3333
"eslint-config-egg": "^12.1.0",
34-
"git-contributor": "^2.0.0",
3534
"tsd": "^0.26.0",
3635
"typescript": "^4.9.5"
3736
},
3837
"engines": {
39-
"node": ">=16.0.0"
38+
"node": ">=18.0.0"
4039
},
4140
"scripts": {
42-
"contributor": "git-contributor",
4341
"tsd": "tsd",
4442
"test": "npm run lint -- --fix && npm run test-local",
4543
"test-local": "egg-bin test",

test/mysql.test.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ describe('test/mysql.test.ts', () => {
9595
assert(user);
9696
assert(typeof user.user_id === 'string' && user.user_id);
9797

98-
const row = await app.mysql.get('npm_auth', { password: new app.mysql.literals.Literal('is not NULL') });
99-
assert(row.id === user.id);
98+
// breaking change on mysql2
99+
// SELECT * FROM `npm_auth` WHERE `password` = is not NULL LIMIT 0, 1
100+
// const row = await app.mysql.get('npm_auth', { password: new app.mysql.literals.Literal('is not NULL') });
101+
// assert(row.id === user.id);
100102
});
101103

102104
it('should query one not exists return null', async () => {
@@ -118,8 +120,13 @@ describe('test/mysql.test.ts', () => {
118120
});
119121
await assert.rejects(async () => {
120122
await app.ready();
121-
}, (err: Error) => {
122-
assert.match(err.message, /ER_ACCESS_DENIED_ERROR/);
123+
}, (err: any) => {
124+
assert.match(err.message, /Access denied for user/);
125+
assert.equal(err.code, 'ER_ACCESS_DENIED_ERROR');
126+
assert.equal(err.errno, 1045);
127+
assert.equal(err.sqlState, '28000');
128+
assert.match(err.sqlMessage, /^Access denied for user 'root'@'[^\']+' \(using password: YES\)$/);
129+
assert.equal(err.name, 'RDSClientGetConnectionError');
123130
return true;
124131
});
125132
});

0 commit comments

Comments
 (0)