oak-db/lib/sqlTranslator.d.ts

69 lines
4.9 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, OperateOption, Q_FullTextValue, Ref, RefOrExpression, SelectOption, 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 { CreateEntityOption } from './types/Translator';
export interface SqlSelectOption extends SelectOption {
}
export interface SqlOperateOption extends OperateOption {
}
export declare abstract class SqlTranslator<ED extends EntityDict & BaseEntityDict> {
readonly schema: StorageSchema<ED>;
constructor(schema: StorageSchema<ED>);
private makeFullSchema;
protected abstract getDefaultSelectFilter<OP extends SqlSelectOption>(alias: string, option?: OP): string;
protected abstract translateAttrProjection(dataType: DataType, alias: string, attr: string): string;
protected abstract translateObjectProjection(projection: Record<string, any>, alias: string, attr: string, prefix: string): string;
protected abstract translateAttrValue(dataType: DataType | Ref, value: any): string;
protected abstract translateFullTextSearch<T extends keyof ED>(value: Q_FullTextValue, entity: T, alias: string): string;
abstract translateCreateEntity<T extends keyof ED>(entity: T, option: CreateEntityOption): string[];
protected abstract translateObjectPredicate(predicate: Record<string, any>, alias: string, attr: string): string;
protected abstract populateSelectStmt<T extends keyof ED, OP extends SqlSelectOption>(projectionText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, groupByText?: string, indexFrom?: number, count?: number, option?: OP, selection?: ED[T]['Selection'], aggregation?: ED[T]['Aggregation']): string;
protected abstract populateUpdateStmt<OP extends SqlOperateOption>(updateText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: OP): string;
protected abstract populateRemoveStmt<OP extends SqlOperateOption>(updateText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: OP): string;
protected abstract translateExpression<T extends keyof ED>(entity: T, alias: string, expression: RefOrExpression<keyof ED[T]['OpSchema']>, refDict: Record<string, [string, keyof ED]>): string;
protected getStorageName<T extends keyof ED>(entity: T): string;
translateInsert<T extends keyof ED>(entity: T, data: ED[T]['CreateMulti']['data']): string;
/**
* analyze the join relations in projection/query/sort
* 所有的层次关系都当成left join处理如果有内表为空的情况请手动处理
* {
* b: {
* name: {
* $exists: false,
* }
* }
* }
* 这样的query会把内表为空的行也返回
* @param param0
*/
private analyzeJoin;
/**
* 对like模式中的特殊字符进行转义
* 例如 % 和 _以防止被当成通配符处理
* @param pattern like模式字符串
* @returns 转义后的字符串
*/
escapeLikePattern(pattern: string): string;
private translateComparison;
private translateEvaluation;
protected translatePredicate(predicate: string, value: any, type?: DataType | Ref): string;
protected translateFilter<T extends keyof ED, OP extends SqlSelectOption>(entity: T, filter: ED[T]['Selection']['filter'], aliasDict: Record<string, string>, filterRefAlias: Record<string, [string, keyof ED]>, initialNumber: number, option?: OP): {
stmt: string;
currentNumber: number;
};
private translateSorter;
private translateProjection;
private translateSelectInner;
translateSelect<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
translateWhere<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
translateAggregate<T extends keyof ED, OP extends SqlSelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): string;
translateCount<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, option?: OP): string;
translateRemove<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Remove'], option?: OP): string;
translateUpdate<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Update'], option?: OP): string;
translateDestroyEntity(entity: string, truncate?: boolean): string;
escapeStringValue(value: string): string;
/**比较两段sql是否完全一致这里是把所有的空格去掉了 */
compareSql(sql1: string, sql2: string): boolean;
quoteIdentifier(name: string): string;
}