@zenorm/generate 1.5.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,8 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.6.0] - 2023-5-18
4
+ - 使用构造器提前初始化对象的属性,用于优化 v8 对象缓存机制
5
+
3
6
  ## [1.5.0] - 2023-4-19
4
7
  - 更新: update 方法使用 UpdateRow<M>
5
8
 
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
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.5.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",