Skip to content

Commit e810f84

Browse files
committed
feat: support cjs and esm both by tshy
BREAKING CHANGE: drop Node.js < 18.19.0 support and only support egg>=4 part of eggjs/egg#3644 eggjs/egg#5257
1 parent c978241 commit e810f84

29 files changed

+452
-249
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ jobs:
1212
uses: node-modules/github-actions/.github/workflows/node-test-mysql.yml@master
1313
with:
1414
os: 'ubuntu-latest'
15-
version: '16, 18, 20, 22'
15+
version: '18, 20, 22'
1616
secrets:
1717
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.oxlintrc.json

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"env": {
4+
"node": true,
5+
"mocha": true
6+
},
7+
"categories": {
8+
"correctness": "error",
9+
"perf": "error",
10+
"nursery": "error",
11+
"restriction": "error",
12+
"style": "error",
13+
"pedantic": "error",
14+
"suspicious": "error"
15+
},
16+
"plugins": [
17+
"import",
18+
"typescript",
19+
"unicorn",
20+
"jsdoc",
21+
"node",
22+
"promise",
23+
"oxc"
24+
],
25+
"rules": {
26+
// eslint
27+
"constructor-super": "error",
28+
"getter-return": "error",
29+
"no-undef": "error",
30+
"no-unreachable": "error",
31+
"no-var": "error",
32+
"no-eq-null": "error",
33+
"no-await-in-loop": "allow",
34+
"eqeqeq": ["error", "smart"],
35+
"init-declarations": "allow",
36+
"curly": "allow",
37+
"no-ternary": "allow",
38+
"max-params": ["error", 5],
39+
"no-await-expression-member": "error",
40+
"no-continue": "allow",
41+
"guard-for-in": "allow",
42+
"func-style": "allow",
43+
"sort-imports": "allow",
44+
"yoda": "allow",
45+
"sort-keys": "allow",
46+
"no-magic-numbers": "allow",
47+
"no-duplicate-imports": "error",
48+
"no-multi-assign": "error",
49+
"func-names": "error",
50+
"default-param-last": "error",
51+
"prefer-object-spread": "error",
52+
"no-undefined": "allow",
53+
"no-plusplus": "allow",
54+
// maybe warn
55+
"no-console": "warn",
56+
"no-extraneous-class": "allow",
57+
"no-empty-function": "error",
58+
"max-depth": ["error", 6],
59+
"max-lines-per-function": "allow",
60+
"no-lonely-if": "error",
61+
"max-lines": "allow",
62+
"require-await": "allow",
63+
"max-nested-callbacks": ["error", 5],
64+
"max-classes-per-file": "allow",
65+
"radix": "allow",
66+
"no-negated-condition": "error",
67+
"no-else-return": "error",
68+
"no-throw-literal": "error",
69+
70+
// import
71+
"import/exports-last": "allow",
72+
"import/max-dependencies": "allow",
73+
"import/no-cycle": "error",
74+
"import/no-anonymous-default-export": "allow",
75+
"import/no-namespace": "error",
76+
"import/named": "error",
77+
"import/export": "error",
78+
"import/no-default-export": "allow",
79+
"import/unambiguous": "error",
80+
81+
// promise
82+
"promise/no-return-wrap": "error",
83+
"promise/param-names": "error",
84+
"promise/prefer-await-to-callbacks": "error",
85+
"promise/prefer-await-to-then": "error",
86+
"promise/prefer-catch": "error",
87+
"promise/no-return-in-finally": "error",
88+
"promise/avoid-new": "error",
89+
90+
// unicorn
91+
"unicorn/error-message": "error",
92+
"unicorn/no-null": "allow",
93+
"unicorn/filename-case": "allow",
94+
"unicorn/prefer-structured-clone": "error",
95+
"unicorn/prefer-logical-operator-over-ternary": "error",
96+
"unicorn/prefer-number-properties": "error",
97+
"unicorn/prefer-array-some": "error",
98+
"unicorn/prefer-string-slice": "error",
99+
// "unicorn/no-null": "error",
100+
"unicorn/throw-new-error": "error",
101+
"unicorn/catch-error-name": "allow",
102+
"unicorn/prefer-spread": "allow",
103+
"unicorn/numeric-separators-style": "error",
104+
"unicorn/prefer-string-raw": "error",
105+
"unicorn/text-encoding-identifier-case": "error",
106+
"unicorn/no-array-for-each": "error",
107+
"unicorn/explicit-length-check": "error",
108+
"unicorn/no-lonely-if": "error",
109+
"unicorn/no-useless-undefined": "allow",
110+
"unicorn/prefer-date-now": "error",
111+
"unicorn/no-static-only-class": "allow",
112+
"unicorn/no-typeof-undefined": "error",
113+
"unicorn/prefer-negative-index": "error",
114+
115+
// oxc
116+
"oxc/no-map-spread": "error",
117+
"oxc/no-rest-spread-properties": "allow",
118+
"oxc/no-optional-chaining": "allow",
119+
"oxc/no-async-await": "allow",
120+
121+
// typescript
122+
"typescript/explicit-function-return-type": "allow",
123+
"typescript/consistent-type-imports": "error",
124+
"typescript/consistent-type-definitions": "error",
125+
"typescript/consistent-indexed-object-style": "allow",
126+
"typescript/no-inferrable-types": "error",
127+
"typescript/array-type": "error",
128+
"typescript/no-non-null-assertion": "error",
129+
"typescript/no-explicit-any": "error",
130+
"typescript/no-import-type-side-effects": "error",
131+
"typescript/no-dynamic-delete": "error",
132+
"typescript/prefer-ts-expect-error": "error",
133+
"typescript/ban-ts-comment": "error",
134+
"typescript/prefer-enum-initializers": "error",
135+
136+
// jsdoc
137+
"jsdoc/require-returns": "allow",
138+
"jsdoc/require-param": "allow"
139+
},
140+
"ignorePatterns": ["index.d.ts", "test/fixtures/**"]
141+
}

README.md

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
# egg-mysql
1+
# @eggjs/mysql
22

33
[![NPM version][npm-image]][npm-url]
4-
[![Node.js CI](https://github.com/eggjs/egg-mysql/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-mysql/actions/workflows/nodejs.yml)
4+
[![CI](https://github.com/eggjs/mysql/actions/workflows/nodejs.yml/badge.svg?branch=master)](https://github.com/eggjs/mysql/actions/workflows/nodejs.yml)
55
[![Test coverage][codecov-image]][codecov-url]
66
[![npm download][download-image]][download-url]
7+
[![Node.js Version](https://img.shields.io/node/v/@eggjs/mysql.svg?style=flat)](https://nodejs.org/en/download/)
8+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
9+
![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/eggjs/mysql)
710

8-
[npm-image]: https://img.shields.io/npm/v/egg-mysql.svg?style=flat-square
9-
[npm-url]: https://npmjs.org/package/egg-mysql
10-
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-mysql.svg?style=flat-square
11-
[codecov-url]: https://codecov.io/github/eggjs/egg-mysql?branch=master
12-
[download-image]: https://img.shields.io/npm/dm/egg-mysql.svg?style=flat-square
13-
[download-url]: https://npmjs.org/package/egg-mysql
11+
[npm-image]: https://img.shields.io/npm/v/@eggjs/mysql.svg?style=flat-square
12+
[npm-url]: https://npmjs.org/package/@eggjs/mysql
13+
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/mysql.svg?style=flat-square
14+
[codecov-url]: https://codecov.io/github/eggjs/mysql?branch=master
15+
[download-image]: https://img.shields.io/npm/dm/@eggjs/mysql.svg?style=flat-square
16+
[download-url]: https://npmjs.org/package/@eggjs/mysql
1417

15-
Aliyun rds client(support mysql protocol) for egg framework
18+
MySQL plugin for Egg.js
1619

1720
## Install
1821

1922
```bash
20-
npm i egg-mysql --save
23+
npm i @eggjs/mysql
2124
```
2225

2326
MySQL Plugin for egg, support egg application access to MySQL database.
@@ -32,7 +35,7 @@ Change `${app_root}/config/plugin.ts` to enable MySQL plugin:
3235
export default {
3336
mysql: {
3437
enable: true,
35-
package: 'egg-mysql',
38+
package: '@eggjs/mysql',
3639
},
3740
}
3841
```
@@ -57,9 +60,9 @@ export default {
5760
// database
5861
database: 'test',
5962
},
60-
// load into app, default is open
63+
// load into app, default is `true`
6164
app: true,
62-
// load into agent, default is close
65+
// load into agent, default is `false`
6366
agent: false,
6467
},
6568
}
@@ -107,10 +110,10 @@ export default {
107110
Usage:
108111

109112
```ts
110-
const client1 = app.mysqls.get('db1');
113+
const client1 = app.mysqls.getSingletonInstance('db1');
111114
await client1.query(sql, values);
112115

113-
const client2 = app.mysqls.get('db2');
116+
const client2 = app.mysqls.getSingletonInstance('db2');
114117
await client2.query(sql, values);
115118
```
116119

@@ -239,17 +242,38 @@ await app.mysql.insert(table, {
239242
// INSERT INTO `$table`(`id`, `fullname`) VALUES(123, CONCAT("James", "Bond"))
240243
```
241244

245+
## For the local dev
246+
247+
Run docker compose to start test mysql service
248+
249+
```bash
250+
docker compose -f docker-compose.yml up -d
251+
# if you run the first time, should wait for ~20s to let mysql service init started
252+
```
253+
254+
Run the unit tests
255+
256+
```bash
257+
npm test
258+
```
259+
260+
Stop test mysql service
261+
262+
```bash
263+
docker compose -f docker-compose.yml down
264+
```
265+
242266
## Questions & Suggestions
243267

244-
Please open an issue [here](https://github.com/eggjs/egg/issues).
268+
Please open an issue [here](https://github.com/eggjs/mysql/issues).
245269

246270
## License
247271

248272
[MIT](LICENSE)
249273

250274
## Contributors
251275

252-
[![Contributors](https://contrib.rocks/image?repo=eggjs/core)](https://github.com/eggjs/core/graphs/contributors)
276+
[![Contributors](https://contrib.rocks/image?repo=eggjs/mysql)](https://github.com/eggjs/mysql/graphs/contributors)
253277

254278
Made with [contributors-img](https://contrib.rocks).
255279

README.zh-CN.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
# egg-mysql
1+
# @eggjs/mysql
22

33
[![NPM version][npm-image]][npm-url]
4-
[![Node.js CI](https://github.com/eggjs/egg-mysql/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-mysql/actions/workflows/nodejs.yml)
4+
[![CI](https://github.com/eggjs/mysql/actions/workflows/nodejs.yml/badge.svg?branch=master)](https://github.com/eggjs/mysql/actions/workflows/nodejs.yml)
55
[![Test coverage][codecov-image]][codecov-url]
66
[![npm download][download-image]][download-url]
7+
[![Node.js Version](https://img.shields.io/node/v/@eggjs/mysql.svg?style=flat)](https://nodejs.org/en/download/)
8+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
9+
![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/eggjs/mysql)
710

8-
[npm-image]: https://img.shields.io/npm/v/egg-mysql.svg?style=flat-square
9-
[npm-url]: https://npmjs.org/package/egg-mysql
10-
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-mysql.svg?style=flat-square
11-
[codecov-url]: https://codecov.io/github/eggjs/egg-mysql?branch=master
12-
[download-image]: https://img.shields.io/npm/dm/egg-mysql.svg?style=flat-square
13-
[download-url]: https://npmjs.org/package/egg-mysql
11+
[npm-image]: https://img.shields.io/npm/v/@eggjs/mysql.svg?style=flat-square
12+
[npm-url]: https://npmjs.org/package/@eggjs/mysql
13+
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/mysql.svg?style=flat-square
14+
[codecov-url]: https://codecov.io/github/eggjs/mysql?branch=master
15+
[download-image]: https://img.shields.io/npm/dm/@eggjs/mysql.svg?style=flat-square
16+
[download-url]: https://npmjs.org/package/@eggjs/mysql
1417

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

@@ -19,7 +22,7 @@ MySQL 插件是为 egg 提供 MySQL 数据库访问的功能
1922
## 安装
2023

2124
```bash
22-
npm i egg-mysql --save
25+
npm i @eggjs/mysql
2326
```
2427

2528
## 配置
@@ -30,7 +33,7 @@ npm i egg-mysql --save
3033
export default {
3134
mysql: {
3235
enable: true,
33-
package: 'egg-mysql',
36+
package: '@eggjs/mysql',
3437
},
3538
}
3639
```
@@ -119,22 +122,22 @@ await client2.query(sql, values);
119122

120123
#### app.mysql
121124

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

124127
```ts
125128
await app.mysql.query(sql);
126-
await app.mysqls.get('db1').query(sql);
129+
await app.mysqls.getSingletonInstance('db1').query(sql);
127130
```
128131

129132
### Agent
130133

131134
#### agent.mysql
132135

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

135138
```ts
136139
await agent.mysql.query(sql);
137-
await agent.mysqls.get('db1').query(sql);
140+
await agent.mysqls.getSingletonInstance('db1').query(sql);
138141
```
139142

140143
## CRUD 使用指南
@@ -236,7 +239,7 @@ const results = await app.mysql.query('update posts set hits = (hits + ?) where
236239

237240
#### 内置表达式
238241

239-
- NOW(): 数据库当前系统时间,通过`app.mysql.literals.now`获取。
242+
- `NOW()`: 数据库当前系统时间,通过 `app.mysql.literals.now` 获取。
240243

241244
```ts
242245
await app.mysql.insert(table, {
@@ -248,7 +251,7 @@ await app.mysql.insert(table, {
248251

249252
#### 自定义表达式
250253

251-
下例展示了如何调用mysql内置的`CONCAT(s1, ...sn)`函数,做字符串拼接。
254+
下例展示了如何调用mysql内置的 `CONCAT(s1, ...sn)` 函数,做字符串拼接。
252255

253256
```ts
254257
const Literal = app.mysql.literals.Literal;
@@ -264,15 +267,15 @@ await app.mysql.insert(table, {
264267

265268
## Questions & Suggestions
266269

267-
Please open an issue [here](https://github.com/eggjs/egg/issues).
270+
Please open an issue [here](https://github.com/eggjs/mysql/issues).
268271

269272
## License
270273

271274
[MIT](LICENSE)
272275

273276
## Contributors
274277

275-
[![Contributors](https://contrib.rocks/image?repo=eggjs/core)](https://github.com/eggjs/core/graphs/contributors)
278+
[![Contributors](https://contrib.rocks/image?repo=eggjs/mysql)](https://github.com/eggjs/mysql/graphs/contributors)
276279

277280
Made with [contributors-img](https://contrib.rocks).
278281

agent.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)