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 } from '../types/Translator'; export interface PostgreSQLSelectOption extends SqlSelectOption { } export interface PostgreSQLOperateOption extends SqlOperateOption { } export declare class PostgreSQLTranslator extends SqlTranslator { private getEnumTypeName; /** * 将 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 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): string; protected translateAttrValue(dataType: DataType | Ref, value: any): 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): string; translateRemove(entity: T, operation: ED[T]['Remove'], option?: OP): string; /** * PostgreSQL专用的结构化JOIN分析 * 返回结构化的JOIN信息,而不是拼接好的FROM字符串 */ private analyzeJoinStructured; /** * 构建JOIN条件(用于UPDATE/DELETE的WHERE子句) */ private buildJoinConditions; /** * 生成 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 类型字符串 */ private reTranslateToAttribute; /** * 从 PostgreSQL 数据库读取当前的 schema 结构 */ readSchema(execFn: (sql: string) => Promise): Promise>; /** * 将属性定义转换为 PostgreSQL DDL 语句 * @param attr 属性名 * @param attrDef 属性定义 */ translateAttributeDef(attr: string, attrDef: Attribute): string; /** * 比较两个 SQL 语句是否等价(用于 schema diff) * 忽略空格、大小写等格式差异 */ compareSql(sql1: string, sql2: string): boolean; }