oak-db 3.3.12 → 3.3.14

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.
@@ -1,4 +1,4 @@
1
- import { EntityDict, Q_FullTextValue, RefOrExpression, Ref, StorageSchema } from "oak-domain/lib/types";
1
+ import { EntityDict, Q_FullTextValue, RefOrExpression, Ref, StorageSchema, Attribute } from "oak-domain/lib/types";
2
2
  import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
3
3
  import { DataType } from "oak-domain/lib/types/schema/DataTypes";
4
4
  import { SqlOperateOption, SqlSelectOption, SqlTranslator } from "../sqlTranslator";
@@ -6,6 +6,12 @@ import { CreateEntityOption } from '../types/Translator';
6
6
  export interface PostgreSQLSelectOption extends SqlSelectOption {
7
7
  }
8
8
  export interface PostgreSQLOperateOption extends SqlOperateOption {
9
+ /**
10
+ * PostgreSQL RETURNING 子句的投影
11
+ * 仅在 update/remove 时有效
12
+ * 返回受影响的行
13
+ */
14
+ returning?: Record<string, any>;
9
15
  }
10
16
  export declare class PostgreSQLTranslator<ED extends EntityDict & BaseEntityDict> extends SqlTranslator<ED> {
11
17
  private getEnumTypeName;
@@ -63,16 +69,22 @@ export declare class PostgreSQLTranslator<ED extends EntityDict & BaseEntityDict
63
69
  protected translateExpression<T extends keyof ED>(entity: T, alias: string, expression: RefOrExpression<keyof ED[T]["OpSchema"]>, refDict: Record<string, [string, keyof ED]>): string;
64
70
  protected populateSelectStmt<T extends keyof ED>(projectionText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, groupByText?: string, indexFrom?: number, count?: number, option?: PostgreSQLSelectOption): string;
65
71
  translateUpdate<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Update'], option?: OP): string;
66
- translateRemove<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Remove'], option?: OP): string;
67
72
  /**
68
- * PostgreSQL专用的结构化JOIN分析
69
- * 返回结构化的JOIN信息,而不是拼接好的FROM字符串
73
+ * 将 projection 转换为 RETURNING 子句的列列表
74
+ * @param entity 实体名
75
+ * @param alias 表别名
76
+ * @param projection 投影定义
70
77
  */
71
- private analyzeJoinStructured;
78
+ private buildReturningClause;
72
79
  /**
73
- * 构建JOIN条件(用于UPDATE/DELETE的WHERE子句)
80
+ * 验证操作参数的合法性
74
81
  */
75
- private buildJoinConditions;
82
+ private validateOperationParams;
83
+ /**
84
+ * 添加RETURNING子句
85
+ */
86
+ private appendReturningClause;
87
+ translateRemove<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Remove'], option?: OP): string;
76
88
  /**
77
89
  * 生成 PostgreSQL UPSERT 语句
78
90
  * INSERT ... ON CONFLICT (key) DO UPDATE SET ...
@@ -80,4 +92,24 @@ export declare class PostgreSQLTranslator<ED extends EntityDict & BaseEntityDict
80
92
  translateUpsert<T extends keyof ED>(entity: T, data: ED[T]['CreateMulti']['data'], conflictKeys: string[], updateAttrs?: string[]): string;
81
93
  protected populateUpdateStmt(updateText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: PostgreSQLOperateOption): string;
82
94
  protected populateRemoveStmt(updateText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: PostgreSQLOperateOption): string;
95
+ /**
96
+ * 将 PostgreSQL 返回的 Type 回译成 oak 的类型,是 populateDataTypeDef 的反函数
97
+ * @param type PostgreSQL 类型字符串
98
+ */
99
+ private reTranslateToAttribute;
100
+ /**
101
+ * 从 PostgreSQL 数据库读取当前的 schema 结构
102
+ */
103
+ readSchema(execFn: (sql: string) => Promise<any>): Promise<StorageSchema<ED>>;
104
+ /**
105
+ * 将属性定义转换为 PostgreSQL DDL 语句
106
+ * @param attr 属性名
107
+ * @param attrDef 属性定义
108
+ */
109
+ translateAttributeDef(attr: string, attrDef: Attribute): string;
110
+ /**
111
+ * 比较两个 SQL 语句是否等价(用于 schema diff)
112
+ * 忽略空格、大小写等格式差异
113
+ */
114
+ compareSql(sql1: string, sql2: string): boolean;
83
115
  }