@zenorm/generate 1.1.1 → 1.2.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 +3 -0
- package/README.md +1 -1
- package/dist/generate.js +2 -3
- package/dist/types.d.ts +5 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
| tablesFilename | `string` | `'_tables'` | 生成数据库表结构文件名
|
|
18
18
|
| repositoriesFilename | `string` | `'_repositories'` | 生成 repositories 文件名
|
|
19
19
|
| globalFilename | `string` | 无 | 全局文件名 - 如果设置所有表将继承于此 - 例如设置为:'_global' - 如果文件不存在则自动创建
|
|
20
|
-
| bindQuery | `
|
|
20
|
+
| bindQuery | `boolean` | `false` | repositories 文件生成 bindQuery(query: QueryParam) 方法用于设置模型的 Query 源 - 并生成模型的静态 Repository 方法
|
|
21
21
|
| generateRepositories | `boolean` | `false` | 是否生成 Repositories 类 - 通常用于多租户模式做数据库前置绑定 `Query` 对象
|
|
22
22
|
| declareRepositoriesToModules | `string[]` | 无 | 是否需将 Repositories 实例定义到目标模块中 - 例如: `["@zenweb/core.Core.repositories"]`
|
|
23
23
|
| filter | `string` | 无 | 表过滤规则正则
|
package/dist/generate.js
CHANGED
|
@@ -90,13 +90,12 @@ 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 ? `QueryParam, ` : ''}createRepositoryQuery } from '${zenormName}';`,
|
|
93
|
+
`import { ${(config.generateRepositories || config.bindQuery) ? `QueryParam, ` : ''}createRepositoryQuery } from '${zenormName}';`,
|
|
94
94
|
...models.map(({ name, className }) => `import _${className} from './${name}';`),
|
|
95
95
|
];
|
|
96
96
|
// 绑定静态 Query
|
|
97
97
|
if (config.bindQuery) {
|
|
98
|
-
|
|
99
|
-
repositories.push(`import { ${v} as _query } from '${p}';`);
|
|
98
|
+
repositories.push('', `let _bindQuery: QueryParam;`, `function _query() { return typeof _bindQuery === 'function' ? _bindQuery() : _bindQuery }`, `/** 绑定模型 Query 源 */`, `export function bindQuery(query: QueryParam) { _bindQuery = query; }`);
|
|
100
99
|
}
|
|
101
100
|
// static
|
|
102
101
|
models.forEach(({ className, pkType }) => {
|
package/dist/types.d.ts
CHANGED
|
@@ -86,11 +86,12 @@ export interface GenerateConfig {
|
|
|
86
86
|
globalFilename?: string;
|
|
87
87
|
/**
|
|
88
88
|
* 绑定 Query 对象
|
|
89
|
-
* -
|
|
90
|
-
* -
|
|
91
|
-
* -
|
|
89
|
+
* - repositories 文件生成 bindQuery(query: QueryParam) 方法用于设置模型的 Query 源
|
|
90
|
+
* - 并生成模型的静态 Repository 方法
|
|
91
|
+
* - 对于多租户多数据库系统不适用
|
|
92
|
+
* @default false
|
|
92
93
|
*/
|
|
93
|
-
bindQuery?:
|
|
94
|
+
bindQuery?: boolean;
|
|
94
95
|
/**
|
|
95
96
|
* 是否生成 Repositories 类
|
|
96
97
|
* - 通常用于多租户模式做数据库前置绑定 `Query` 对象
|
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
|
+
"version": "1.2.0",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"repository": "https://github.com/yefei/zenorm-generate",
|