Skip to content

Commit a116170

Browse files
committed
f
1 parent 52ff431 commit a116170

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

plugin/ajv/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,23 @@ exports.teggDal = {
4141

4242
## standalone 模式
4343

44-
默认内置。
44+
### Install
45+
46+
```shell
47+
# tegg 注解
48+
npm i --save @eggjs/tegg
49+
# tegg ajv 插件
50+
npm i --save @eggjs/tegg-ajv-plugin
51+
```
52+
53+
### Prepare
54+
55+
```json
56+
// tsconfig.json
57+
{
58+
"extends": "@eggjs/tsconfig"
59+
}
60+
```
4561

4662
## Usage
4763

plugin/dal/README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## egg 模式
66

77
### Install
8+
89
```shell
910
# tegg 注解
1011
npm i --save @eggjs/tegg
@@ -15,6 +16,7 @@ npm i --save @eggjs/tegg-dal-plugin
1516
```
1617

1718
### Prepare
19+
1820
```json
1921
// tsconfig.json
2022
{
@@ -40,6 +42,7 @@ exports.teggDal = {
4042
## standalone 模式
4143

4244
### Install
45+
4346
```shell
4447
# tegg 注解
4548
npm i --save @eggjs/tegg
@@ -48,6 +51,7 @@ npm i --save @eggjs/tegg-dal-plugin
4851
```
4952

5053
### Prepare
54+
5155
```json
5256
// tsconfig.json
5357
{
@@ -58,6 +62,7 @@ npm i --save @eggjs/tegg-dal-plugin
5862
## Usage
5963

6064
### module.yml
65+
6166
通过 module.yml 来配置 module 中的 mysql 数据源。
6267

6368
```yaml
@@ -73,6 +78,7 @@ dataSource:
7378
```
7479
7580
### Table
81+
7682
`TableModel` 定义一个表结构,包括表配置、列、索引。
7783

7884
```ts
@@ -108,6 +114,7 @@ export class Foo {
108114
详细参数定义如下,具体参数值可以参考 https://dev.mysql.com/doc/refman/8.0/en/create-table.html
109115

110116
建表参数,使用方式为 `@Table(parmas?: TableParams)`
117+
111118
```ts
112119
export interface TableParams {
113120
// 数据库表名
@@ -134,6 +141,7 @@ export interface TableParams {
134141
```
135142

136143
建索引参数,使用方式为 `@Index(parmas?: IndexParams)`
144+
137145
```ts
138146
export interface IndexParams {
139147
// 索引的列
@@ -153,6 +161,7 @@ export interface IndexParams {
153161
```
154162

155163
建列参数,使用方式为 `@Column(type: ColumnTypeParams, parmas?: ColumnParams)`
164+
156165
```ts
157166
export interface ColumnParams {
158167
// 列名,默认转换规则 userName 至 user_name
@@ -174,6 +183,7 @@ export interface ColumnParams {
174183
```
175184

176185
支持的类型
186+
177187
```ts
178188
export enum ColumnType {
179189
// Numeric
@@ -225,6 +235,7 @@ export enum ColumnType {
225235
支持的类型参数,详细可参考 https://dev.mysql.com/doc/refman/8.0/en/data-types.html
226236

227237
如果 mysql 类型和 ts 类型对应关系不确定可直接使用 `ColumnTsType` 类型,如
238+
228239
```ts
229240
import { Table, Index, Column, ColumnType, IndexType, ColumnTsType } from '@eggjs/tegg/dal';
230241
@@ -506,7 +517,8 @@ export interface GeometryCollectionParams {
506517
```
507518

508519
### 目录结构
509-
运行 `egg-bin dal gen` 即可生成 `dal` 相关目录,包括 dao、extension、structure
520+
521+
运行 `egg-bin dal gen` 即可生成 `dal` 相关目录,包括 dao、extension、structure
510522

511523
```plain
512524
dal
@@ -519,7 +531,7 @@ dal
519531
└── structure
520532
├── Foo.json
521533
└── Foo.sql
522-
```
534+
```
523535

524536
- dao: 表访问类,生成的 BaseDAO 请勿修改,其中包含了根据表结构生成的基础访问方法,如 insert/update/delete 以及根据索引信息生成的 find 方法
525537
- extension: 扩展文件,如果需要自定义 sql,需要在 extension 文件中定义
@@ -543,8 +555,9 @@ export class FooRepository {
543555
}
544556
```
545557

546-
#### 自定义 Sql
547-
1. 在 extension 中定义自定义 Sql
558+
#### 自定义 SQL
559+
560+
1. 在 extension 中定义自定义 SQL
548561

549562
```ts
550563
// dal/extension/FooExtension.ts
@@ -559,6 +572,7 @@ export default {
559572
```
560573

561574
2. 在 dao 中定义自定义方法
575+
562576
```ts
563577
import { SingletonProto, AccessLevel } from '@eggjs/tegg';
564578
import { BaseFooDAO } from './base/BaseFooDAO';
@@ -577,6 +591,7 @@ export default class FooDAO extends BaseFooDAO {
577591
```
578592

579593
支持的自定义 filter
594+
580595
```
581596
- toPoint
582597
- toLine
@@ -589,6 +604,7 @@ export default class FooDAO extends BaseFooDAO {
589604
```
590605
591606
支持自定义 block 来简化 sql, 如内置的 allColumns
607+
592608
```ts
593609
export default {
594610
findByName: {
@@ -599,7 +615,8 @@ export default {
599615
```
600616

601617
### DataSource
602-
DataSource 仅能在 DAO 中使用,可以将 mysql 返回的数据反序列化为类。支持的方法有
618+
619+
DataSource 仅能在 DAO 中使用,可以将 MySQL 返回的数据反序列化为类。支持的方法有
603620

604621
```ts
605622
export interface DataSource<T> {
@@ -634,6 +651,7 @@ dataSource:
634651
```
635652
636653
可以通过以下 SQL 来查看数据库时区
654+
637655
```sql
638656
SELECT @@GLOBAL.time_zone;
639657
```

standalone/standalone/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"@eggjs/tegg-background-task": "^3.35.1",
4545
"@eggjs/tegg-common-util": "^3.35.1",
4646
"@eggjs/tegg-dal-plugin": "^3.35.1",
47-
"@eggjs/tegg-ajv-plugin": "^3.35.1",
4847
"@eggjs/tegg-dynamic-inject-runtime": "^3.35.1",
4948
"@eggjs/tegg-lifecycle": "^3.35.1",
5049
"@eggjs/tegg-loader": "^3.35.1",
@@ -55,6 +54,7 @@
5554
"access": "public"
5655
},
5756
"devDependencies": {
57+
"@eggjs/tegg-ajv-plugin": "^3.35.1",
5858
"@types/mocha": "^10.0.1",
5959
"@types/node": "^20.2.4",
6060
"cross-env": "^7.0.3",

standalone/standalone/test/index.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ describe('standalone/standalone/test/index.test.ts', () => {
253253
describe('ajv runner', () => {
254254
it('should throw AjvInvalidParamError', async () => {
255255
await assert.rejects(async () => {
256-
await main<string>(path.join(__dirname, './fixtures/ajv-module'));
256+
await main<string>(path.join(__dirname, './fixtures/ajv-module'), {
257+
dependencies: [
258+
path.dirname(require.resolve('@eggjs/tegg-ajv-plugin/package.json')),
259+
],
260+
});
257261
}, (err: any) => {
258262
assert.equal(err.name, 'AjvInvalidParamError');
259263
assert.equal(err.message, 'Validation Failed');
@@ -275,7 +279,11 @@ describe('standalone/standalone/test/index.test.ts', () => {
275279
});
276280

277281
it('should pass', async () => {
278-
const result = await main<string>(path.join(__dirname, './fixtures/ajv-module-pass'));
282+
const result = await main<string>(path.join(__dirname, './fixtures/ajv-module-pass'), {
283+
dependencies: [
284+
path.dirname(require.resolve('@eggjs/tegg-ajv-plugin/package.json')),
285+
],
286+
});
279287
assert.equal(result, '{"body":{"fullname":"mock fullname","skipDependencies":true,"registryName":"ok"}}');
280288
});
281289
});

0 commit comments

Comments
 (0)