@zenorm/generate 1.9.1 → 1.10.1

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/dist/generate.js CHANGED
@@ -97,9 +97,13 @@ async function generate(tables, cfg) {
97
97
  const tablesFilename = path.join(outputDir, config.tablesFilename + '.ts');
98
98
  console.log(`write tables file: ${tablesFilename}`);
99
99
  await fs_1.promises.writeFile(tablesFilename, structs.filter(i => i !== null).join('\n'));
100
+ const imports = ['createRepositoryQuery'];
101
+ if (config.generateRepositories || config.bindQuery) {
102
+ imports.push('QueryParam');
103
+ }
100
104
  const repositories = [
101
105
  ...remark,
102
- `import { ${(config.generateRepositories || config.bindQuery) ? `QueryParam, UpdateRow, ` : ''}createRepositoryQuery } from '${zenormName}';`,
106
+ `import { ${imports.join(', ')} } from '${zenormName}';`,
103
107
  `import * as _tables from './_tables';`,
104
108
  ...models.map(({ name, className }) => `import _${className} from './${name}';`),
105
109
  ];
@@ -124,6 +128,7 @@ async function generate(tables, cfg) {
124
128
  'exists',
125
129
  'create',
126
130
  'createAndGet',
131
+ 'getOrCreate',
127
132
  'save',
128
133
  'update',
129
134
  'delete',
@@ -134,7 +139,7 @@ async function generate(tables, cfg) {
134
139
  repositories.push(` /** 保存当前实例数据 */`);
135
140
  repositories.push(` save() { return ${className}.repository.save(this); }`);
136
141
  repositories.push(` /** 更新当前实例数据 */`);
137
- repositories.push(` update(data: UpdateRow<${className}>) { return ${className}.repository.update(this, data); }`);
142
+ repositories.push(` update(data: Partial<${className}>) { return ${className}.repository.update(this, data); }`);
138
143
  repositories.push(` /** 删除当前实例数据 */`);
139
144
  repositories.push(` delete() { return ${className}.repository.delete(this); }`);
140
145
  }
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.9.1",
4
+ "version": "1.10.1",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "homepage": "https://zenorm.node.ltd",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "build": "rimraf dist && tsc",
18
- "prepublishOnly": "npm run build",
18
+ "prepack": "npm run build",
19
19
  "gen": "cd test && ts-node ../src/bin/zenorm-generate.ts config.json",
20
20
  "t1": "cd test && cross-env DEBUG=* ts-node t1"
21
21
  },
@@ -35,10 +35,11 @@
35
35
  "rimraf": "^4.4.1",
36
36
  "ts-node": "^10.9.1",
37
37
  "typescript": "^5.0.4",
38
- "zenorm": "^3.31.0"
38
+ "zenorm": "^3.38.0"
39
39
  },
40
40
  "dependencies": {
41
41
  "pascal-case": "^3.1.2",
42
42
  "snake-case": "^3.0.4"
43
- }
43
+ },
44
+ "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
44
45
  }
package/CHANGELOG.md DELETED
@@ -1,49 +0,0 @@
1
- # Changelog
2
-
3
- ## [1.9.1] - 2023-8-9
4
- - 默认选项: staticMethods=true
5
-
6
- ## [1.9.0] - 2023-8-9
7
- - 增加配置选项: staticMethods instanceMethods
8
-
9
- ## [1.8.1] - 2023-5-19
10
- - fix: 使用 global 继承时构造函数缺少 super 调用
11
-
12
- ## [1.8.0] - 2023-5-18
13
- - 撤销 [1.6.0] 的修改,动态 as 功能无法满足需求
14
-
15
- ## [1.7.0] - 2023-5-18
16
- - 构造器增加 pkval 参数
17
-
18
- ## [1.6.0] - 2023-5-18
19
- - 使用构造器提前初始化对象的属性,用于优化 v8 对象缓存机制
20
-
21
- ## [1.5.0] - 2023-4-19
22
- - 更新: update 方法使用 UpdateRow<M>
23
-
24
- ## [1.4.0] - 2023-3-29
25
- - createRepositoryQuery 添加表描述
26
- - 如果没有主键 pkType = never
27
-
28
- ## [1.3.1] - 2023-3-27
29
- - fix: windows 换行符问题
30
-
31
- ## [1.3.0] - 2023-3-25
32
- - update: bindQuery 增加 save, update, delete
33
-
34
- ## [1.2.0] - 2023-3-24
35
- - update: bindQuery 改为函数形式
36
-
37
- ## [1.1.1] - 2023-3-24
38
- - fix: 生成格式少个空格和空行
39
- - update: bindQuery 增加 count 和 exists
40
- - 补充注释说明
41
-
42
- ## [1.1.0] - 2023-3-24
43
- - 新增: 绑定静态 Query
44
-
45
- ## [1.0.0] - 2023-3-23
46
- - 完善
47
-
48
- ## [0.0.1] - 2023-3-23
49
- - 从 zenorm@3.25.0 分离为独立项目