import { EntityDict, Q_FullTextValue, RefOrExpression, Ref, StorageSchema, Attribute } from "oak-domain/lib/types"; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { DataType } from "oak-domain/lib/types/schema/DataTypes"; import { SqlOperateOption, SqlSelectOption, SqlTranslator } from "../sqlTranslator"; import { CreateEntityOption, SqlStatement } from '../types/Translator'; export interface PostgreSQLSelectOption extends SqlSelectOption { } export interface PostgreSQLOperateOption extends SqlOperateOption { /** * PostgreSQL RETURNING 子句的投影 * 仅在 update/remove 时有效 * 返回受影响的行 */ returning?: Record; } export declare class PostgreSQLTranslator extends SqlTranslator { readonly maxIndexNameLength = 63; private physicalIndexNameCache?; private escapeSqlCommentLiteral; buildColumnCommentSql(tableName: string, column: string, attrDef: Attribute): string | undefined; clearColumnCommentSql(tableName: string, column: string): string; private makeIndexNameCacheKey; private getIndexSuffixes; private ensurePhysicalIndexNameCache; getEnumTypeName(entity: string, attr: string): string; getPhysicalIndexName(entityName: string, tableName: string, logicalName: string, suffix?: string): string; getLegacyPhysicalIndexNames(entityName: string, tableName: string, logicalName: string, suffix?: string): string[]; /** * 将 MySQL 风格的 JSON 路径转换为 PostgreSQL 路径数组格式 * 例如: ".foo.bar[0].baz" -> '{foo,bar,0,baz}' */ private convertJsonPath; /** * 生成 PostgreSQL JSON 访问表达式 * @param column 列名(包含别名) * @param path JSON 路径 * @param asText 是否返回文本(使用 #>> 而不是 #>) */ private buildJsonAccessor; protected getDefaultSelectFilter(alias: string, option?: PostgreSQLSelectOption): string; private normalizePostgreSqlIndexConfig; private makeUpSchema; constructor(schema: StorageSchema); static supportedDataTypes: DataType[]; static spatialTypes: DataType[]; static withLengthDataTypes: DataType[]; static withPrecisionDataTypes: DataType[]; static withScaleDataTypes: DataType[]; static dataTypeDefaults: Record; maxAliasLength: number; private populateDataTypeDef; /** * PostgreSQL 字符串值转义 * 防御SQL注入 */ escapeStringValue(value: string): string; /** * LIKE 模式转义 * 转义 LIKE 语句中的特殊字符 */ escapeLikePattern(value: string): string; /** * PostgreSQL 标识符转义 * 用于表名、列名等 */ escapeIdentifier(identifier: string): string; /** * tsquery 搜索词转义 */ escapeTsQueryValue(value: string): string; quoteIdentifier(identifier: string): string; protected translateAttrProjection(dataType: DataType, alias: string, attr: string): string; protected translateObjectPredicate(predicate: Record, alias: string, attr: string): string; protected translateObjectProjection(projection: Record, alias: string, attr: string, prefix: string, resultColumnMap: Record): string; protected translateAttrValue(dataType: DataType | Ref, value: any): string; protected translateAttributePredicate(column: string, predicate: string, value: any, type?: DataType | Ref): string; protected translateFullTextSearch(value: Q_FullTextValue, entity: T, alias: string): string; translateCreateEntity(entity: T, options?: CreateEntityOption): string[]; private translateFnName; private translateAttrInExpression; protected translateExpression(entity: T, alias: string, expression: RefOrExpression, refDict: Record): string; protected populateSelectStmt(projectionText: string, fromText: string, aliasDict: Record, filterText: string, sorterText?: string, groupByText?: string, indexFrom?: number, count?: number, option?: PostgreSQLSelectOption): string; translateUpdate(entity: T, operation: ED[T]['Update'], option?: OP): SqlStatement; /** * 将 projection 转换为 RETURNING 子句的列列表 * @param entity 实体名 * @param alias 表别名 * @param projection 投影定义 */ private buildReturningClause; /** * 验证操作参数的合法性 */ private validateOperationParams; /** * 添加RETURNING子句 */ private appendReturningClause; translateRemove(entity: T, operation: ED[T]['Remove'], option?: OP): SqlStatement; /** * 生成 PostgreSQL UPSERT 语句 * INSERT ... ON CONFLICT (key) DO UPDATE SET ... */ translateUpsert(entity: T, data: ED[T]['CreateMulti']['data'], conflictKeys: string[], updateAttrs?: string[]): string; protected populateUpdateStmt(updateText: string, fromText: string, aliasDict: Record, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: PostgreSQLOperateOption): string; protected populateRemoveStmt(updateText: string, fromText: string, aliasDict: Record, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: PostgreSQLOperateOption): string; /** * 将 PostgreSQL 返回的 Type 回译成 oak 的类型,是 populateDataTypeDef 的反函数 * @param type PostgreSQL 类型字符串 */ reTranslateToAttribute(type: string): Attribute; /** * 从 PostgreSQL 数据库读取当前的 schema 结构 */ readSchema(execFn: (sql: string) => Promise): Promise>; /** * 将属性定义转换为 PostgreSQL DDL 语句 * @param attr 属性名 * @param attrDef 属性定义 */ translateAttributeDef(attr: string, attrDef: Attribute): string; translateColumnDefinition(entity: string, attr: string, attrDef: Attribute): string; /** * 比较两个 SQL 语句是否等价(用于 schema diff) * 忽略空格、大小写等格式差异 */ compareSql(sql1: string, sql2: string): boolean; }