@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 CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.2.0] - 2023-3-24
4
+ - update: bindQuery 改为函数形式
5
+
3
6
  ## [1.1.1] - 2023-3-24
4
7
  - fix: 生成格式少个空格和空行
5
8
  - update: bindQuery 增加 count 和 exists
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 | `string` | | 绑定 Query 对象 - 设置 query 源,格式: 'QueryParam@filename' 例如: 'pool@../db'
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
- const [v, p] = config.bindQuery.split('@', 2);
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
- * - 设置 query 源,格式: 'QueryParam@filename' 例如: 'pool@../db'
90
- * - 生成模型的静态 Repository 方法
91
- * - 对于多租户数据库系统不适用
89
+ * - repositories 文件生成 bindQuery(query: QueryParam) 方法用于设置模型的 Query 源
90
+ * - 并生成模型的静态 Repository 方法
91
+ * - 对于多租户多数据库系统不适用
92
+ * @default false
92
93
  */
93
- bindQuery?: string;
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.1.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",