@zenorm/generate 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.6.0] - 2023-5-18
4
+ - 使用构造器提前初始化对象的属性,用于优化 v8 对象缓存机制
5
+
6
+ ## [1.5.0] - 2023-4-19
7
+ - 更新: update 方法使用 UpdateRow<M>
8
+
3
9
  ## [1.4.0] - 2023-3-29
4
10
  - createRepositoryQuery 添加表描述
5
11
  - 如果没有主键 pkType = never
package/dist/generate.js CHANGED
@@ -18,6 +18,7 @@ async function generate(tables, cfg) {
18
18
  await (0, utils_1.checkFileDir)(outputDir);
19
19
  console.log('database:', config.database);
20
20
  const remark = [
21
+ `// @ts-nocheck`,
21
22
  '// zenorm 自动生成文件',
22
23
  '// 请不要修改此文件,因为此文件在每次重新生成数据库结构时会被覆盖',
23
24
  `// create at: ${(0, utils_1.currentDatetime)()}`,
@@ -65,6 +66,13 @@ async function generate(tables, cfg) {
65
66
  structs.push(`export class ${className}Table${config.globalFilename ? ' extends _Global' : ''} {`);
66
67
  structs.push(` static columns = ${JSON.stringify(columns)};`);
67
68
  structs.push(...props);
69
+ structs.push('');
70
+ // 使用构造器提前初始化对象的属性,用于优化 v8 对象缓存机制
71
+ structs.push(` constructor(data: Partial<${className}Table> = {}) {`);
72
+ for (const c of columns) {
73
+ structs.push(` this.${c} = data.${c};`);
74
+ }
75
+ structs.push(` }`);
68
76
  structs.push('}');
69
77
  structs.push('');
70
78
  // model class
@@ -90,7 +98,7 @@ async function generate(tables, cfg) {
90
98
  await fs_1.promises.writeFile(tablesFilename, structs.filter(i => i !== null).join('\n'));
91
99
  const repositories = [
92
100
  ...remark,
93
- `import { ${(config.generateRepositories || config.bindQuery) ? `QueryParam, ` : ''}createRepositoryQuery } from '${zenormName}';`,
101
+ `import { ${(config.generateRepositories || config.bindQuery) ? `QueryParam, UpdateRow, ` : ''}createRepositoryQuery } from '${zenormName}';`,
94
102
  `import * as _tables from './_tables';`,
95
103
  ...models.map(({ name, className }) => `import _${className} from './${name}';`),
96
104
  ];
@@ -121,7 +129,7 @@ async function generate(tables, cfg) {
121
129
  repositories.push(` /** 保存当前实例数据 */`);
122
130
  repositories.push(` save() { return ${className}.repository.save(this); }`);
123
131
  repositories.push(` /** 更新当前实例数据 */`);
124
- repositories.push(` update(data: Partial<${className}>) { return ${className}.repository.update(this, data); }`);
132
+ repositories.push(` update(data: UpdateRow<${className}>) { return ${className}.repository.update(this, data); }`);
125
133
  repositories.push(` /** 删除当前实例数据 */`);
126
134
  repositories.push(` delete() { return ${className}.repository.delete(this); }`);
127
135
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zenorm/generate",
3
3
  "description": "Easy ORM, easy query. easy typing! Auto generate typescript declaration.",
4
- "version": "1.4.0",
4
+ "version": "1.6.0",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "homepage": "https://zenorm.node.ltd",
@@ -29,13 +29,13 @@
29
29
  ],
30
30
  "devDependencies": {
31
31
  "@types/node": "^12.20.41",
32
- "@zenorm/generate-mysql": "^1.2.0",
32
+ "@zenorm/generate-mysql": "^1.3.0",
33
33
  "cross-env": "^7.0.3",
34
- "mysql-easy-query": "^3.12.0",
34
+ "mysql-easy-query": "^3.13.0",
35
35
  "rimraf": "^4.4.1",
36
36
  "ts-node": "^10.9.1",
37
- "typescript": "^5.0.2",
38
- "zenorm": "^3.29.0"
37
+ "typescript": "^5.0.4",
38
+ "zenorm": "^3.31.0"
39
39
  },
40
40
  "dependencies": {
41
41
  "pascal-case": "^3.1.2",