oak-db/lib/PostgreSQL/translator.d.ts

84 lines
4.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { EntityDict, Q_FullTextValue, RefOrExpression, Ref, StorageSchema } 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<ED extends EntityDict & BaseEntityDict> extends SqlTranslator<ED> {
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<ED>);
static supportedDataTypes: DataType[];
static spatialTypes: DataType[];
static withLengthDataTypes: DataType[];
static withPrecisionDataTypes: DataType[];
static withScaleDataTypes: DataType[];
static dataTypeDefaults: Record<string, any>;
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<string, any>, alias: string, attr: string): string;
protected translateObjectProjection(projection: Record<string, any>, alias: string, attr: string, prefix: string): string;
protected translateAttrValue(dataType: DataType | Ref, value: any): string;
protected translateFullTextSearch<T extends keyof ED>(value: Q_FullTextValue, entity: T, alias: string): string;
translateCreateEntity<T extends keyof ED>(entity: T, options?: CreateEntityOption): string[];
private translateFnName;
private translateAttrInExpression;
protected translateExpression<T extends keyof ED>(entity: T, alias: string, expression: RefOrExpression<keyof ED[T]["OpSchema"]>, refDict: Record<string, [string, keyof ED]>): string;
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;
translateUpdate<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Update'], option?: OP): string;
translateRemove<T extends keyof ED, OP extends SqlOperateOption>(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<T extends keyof ED>(entity: T, data: ED[T]['CreateMulti']['data'], conflictKeys: string[], updateAttrs?: string[]): string;
protected populateUpdateStmt(updateText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: PostgreSQLOperateOption): string;
protected populateRemoveStmt(updateText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: PostgreSQLOperateOption): string;
}