@zenorm/generate 1.3.1 → 1.5.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 +7 -0
- package/dist/generate.js +8 -7
- package/dist/utils.js +1 -1
- package/package.json +6 -7
package/CHANGELOG.md
CHANGED
package/dist/generate.js
CHANGED
|
@@ -43,12 +43,12 @@ async function generate(tables, cfg) {
|
|
|
43
43
|
const name = (0, snake_case_1.snakeCase)(tableName);
|
|
44
44
|
const outputFilename = path.join(outputDir, name + '.ts');
|
|
45
45
|
console.log('table:', tableName);
|
|
46
|
-
let pk
|
|
47
|
-
let pkType = '
|
|
46
|
+
let pk;
|
|
47
|
+
let pkType = 'never';
|
|
48
48
|
const props = [];
|
|
49
49
|
const columns = [];
|
|
50
50
|
for (const c of t.columns) {
|
|
51
|
-
if (c.pk) {
|
|
51
|
+
if (!pk && c.pk) {
|
|
52
52
|
pk = c.name;
|
|
53
53
|
pkType = c.type;
|
|
54
54
|
}
|
|
@@ -74,7 +74,7 @@ async function generate(tables, cfg) {
|
|
|
74
74
|
`import { ${className}Table } from './${config.tablesFilename}';`,
|
|
75
75
|
'',
|
|
76
76
|
`@model({`,
|
|
77
|
-
` pk: '${pk}'
|
|
77
|
+
pk ? ` pk: '${pk}',` : null,
|
|
78
78
|
name != tableName ? ` name: '${name}',` : null,
|
|
79
79
|
` table: '${tableName}',`,
|
|
80
80
|
`})`,
|
|
@@ -90,7 +90,8 @@ async function generate(tables, cfg) {
|
|
|
90
90
|
await fs_1.promises.writeFile(tablesFilename, structs.filter(i => i !== null).join('\n'));
|
|
91
91
|
const repositories = [
|
|
92
92
|
...remark,
|
|
93
|
-
`import { ${(config.generateRepositories || config.bindQuery) ? `QueryParam, ` : ''}createRepositoryQuery } from '${zenormName}';`,
|
|
93
|
+
`import { ${(config.generateRepositories || config.bindQuery) ? `QueryParam, UpdateRow, ` : ''}createRepositoryQuery } from '${zenormName}';`,
|
|
94
|
+
`import * as _tables from './_tables';`,
|
|
94
95
|
...models.map(({ name, className }) => `import _${className} from './${name}';`),
|
|
95
96
|
];
|
|
96
97
|
// 绑定静态 Query
|
|
@@ -99,7 +100,7 @@ async function generate(tables, cfg) {
|
|
|
99
100
|
}
|
|
100
101
|
// static
|
|
101
102
|
models.forEach(({ className, pkType }) => {
|
|
102
|
-
repositories.push('', `export class ${className} extends _${className} {`, ` /** 使用指定 Query 对象查询 ${className}Repository */`, ` static query = createRepositoryQuery<${className}, ${pkType}>(${className});`);
|
|
103
|
+
repositories.push('', `export class ${className} extends _${className} {`, ` /** 使用指定 Query 对象查询 ${className}Repository */`, ` static query = createRepositoryQuery<${className}, _tables.${className}Table, ${pkType}>(${className});`);
|
|
103
104
|
if (config.bindQuery) {
|
|
104
105
|
repositories.push(` /** Query 绑定的 ${className}Repository */`);
|
|
105
106
|
repositories.push(` static repository = ${className}.query(_query);`);
|
|
@@ -120,7 +121,7 @@ async function generate(tables, cfg) {
|
|
|
120
121
|
repositories.push(` /** 保存当前实例数据 */`);
|
|
121
122
|
repositories.push(` save() { return ${className}.repository.save(this); }`);
|
|
122
123
|
repositories.push(` /** 更新当前实例数据 */`);
|
|
123
|
-
repositories.push(` update(data:
|
|
124
|
+
repositories.push(` update(data: UpdateRow<${className}>) { return ${className}.repository.update(this, data); }`);
|
|
124
125
|
repositories.push(` /** 删除当前实例数据 */`);
|
|
125
126
|
repositories.push(` delete() { return ${className}.repository.delete(this); }`);
|
|
126
127
|
}
|
package/dist/utils.js
CHANGED
|
@@ -15,7 +15,7 @@ function checkFileDir(dir) {
|
|
|
15
15
|
}
|
|
16
16
|
exports.checkFileDir = checkFileDir;
|
|
17
17
|
function fileExists(f) {
|
|
18
|
-
return fs_1.promises.access(f).then(() => true,
|
|
18
|
+
return fs_1.promises.access(f).then(() => true, () => false);
|
|
19
19
|
}
|
|
20
20
|
exports.fileExists = fileExists;
|
|
21
21
|
/**
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenorm/generate",
|
|
3
3
|
"description": "Easy ORM, easy query. easy typing! Auto generate typescript declaration.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"
|
|
7
|
+
"homepage": "https://zenorm.node.ltd",
|
|
8
8
|
"author": "YeFei <316606233@qq.com>",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"bin": {
|
|
11
11
|
"zenorm-generate": "./dist/bin/zenorm-generate.js"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"docs",
|
|
15
14
|
"dist"
|
|
16
15
|
],
|
|
17
16
|
"scripts": {
|
|
@@ -30,13 +29,13 @@
|
|
|
30
29
|
],
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"@types/node": "^12.20.41",
|
|
33
|
-
"@zenorm/generate-mysql": "^1.
|
|
32
|
+
"@zenorm/generate-mysql": "^1.3.0",
|
|
34
33
|
"cross-env": "^7.0.3",
|
|
35
|
-
"mysql-easy-query": "^3.
|
|
34
|
+
"mysql-easy-query": "^3.13.0",
|
|
36
35
|
"rimraf": "^4.4.1",
|
|
37
36
|
"ts-node": "^10.9.1",
|
|
38
|
-
"typescript": "^
|
|
39
|
-
"zenorm": "^3.
|
|
37
|
+
"typescript": "^5.0.4",
|
|
38
|
+
"zenorm": "^3.31.0"
|
|
40
39
|
},
|
|
41
40
|
"dependencies": {
|
|
42
41
|
"pascal-case": "^3.1.2",
|