@zenorm/generate 1.3.1 → 1.4.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 +4 -0
- package/dist/generate.js +6 -5
- package/dist/utils.js +1 -1
- package/package.json +4 -5
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
|
`})`,
|
|
@@ -91,6 +91,7 @@ async function generate(tables, cfg) {
|
|
|
91
91
|
const repositories = [
|
|
92
92
|
...remark,
|
|
93
93
|
`import { ${(config.generateRepositories || config.bindQuery) ? `QueryParam, ` : ''}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);`);
|
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.4.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": {
|
|
@@ -35,8 +34,8 @@
|
|
|
35
34
|
"mysql-easy-query": "^3.12.0",
|
|
36
35
|
"rimraf": "^4.4.1",
|
|
37
36
|
"ts-node": "^10.9.1",
|
|
38
|
-
"typescript": "^
|
|
39
|
-
"zenorm": "^3.
|
|
37
|
+
"typescript": "^5.0.2",
|
|
38
|
+
"zenorm": "^3.29.0"
|
|
40
39
|
},
|
|
41
40
|
"dependencies": {
|
|
42
41
|
"pascal-case": "^3.1.2",
|