oak-db 3.3.11 → 3.3.13

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.
@@ -0,0 +1,13 @@
1
+ export type PostgreSQLConfiguration = {
2
+ host: string;
3
+ user: string;
4
+ password: string;
5
+ database: string;
6
+ port?: number;
7
+ max?: number;
8
+ idleTimeoutMillis?: number;
9
+ connectionTimeoutMillis?: number;
10
+ };
11
+ export type Configuration = {
12
+ postgresql: PostgreSQLConfiguration;
13
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- export * from './MySQL/store';
2
- export { MySqlSelectOption, MysqlOperateOption } from './MySQL/translator';
1
+ export * from './MySQL/store';
2
+ export { MySqlSelectOption, MysqlOperateOption } from './MySQL/translator';
3
+ export * from './PostgreSQL/store';
4
+ export { PostgreSQLSelectOption, PostgreSQLOperateOption } from './PostgreSQL/translator';
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./MySQL/store"), exports);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./MySQL/store"), exports);
5
+ tslib_1.__exportStar(require("./PostgreSQL/store"), exports);
@@ -1,55 +1,68 @@
1
- import { EntityDict, OperateOption, Q_FullTextValue, Ref, RefOrExpression, SelectOption, StorageSchema } from "oak-domain/lib/types";
2
- import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
3
- import { DataType } from "oak-domain/lib/types/schema/DataTypes";
4
- import { CreateEntityOption } from './types/Translator';
5
- export interface SqlSelectOption extends SelectOption {
6
- }
7
- export interface SqlOperateOption extends OperateOption {
8
- }
9
- export declare abstract class SqlTranslator<ED extends EntityDict & BaseEntityDict> {
10
- readonly schema: StorageSchema<ED>;
11
- constructor(schema: StorageSchema<ED>);
12
- private makeFullSchema;
13
- protected abstract getDefaultSelectFilter<OP extends SqlSelectOption>(alias: string, option?: OP): string;
14
- protected abstract translateAttrProjection(dataType: DataType, alias: string, attr: string): string;
15
- protected abstract translateObjectProjection(projection: Record<string, any>, alias: string, attr: string, prefix: string): string;
16
- protected abstract translateAttrValue(dataType: DataType | Ref, value: any): string;
17
- protected abstract translateFullTextSearch<T extends keyof ED>(value: Q_FullTextValue, entity: T, alias: string): string;
18
- abstract translateCreateEntity<T extends keyof ED>(entity: T, option: CreateEntityOption): string[];
19
- protected abstract translateObjectPredicate(predicate: Record<string, any>, alias: string, attr: string): string;
20
- 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;
21
- 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;
22
- 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;
23
- protected abstract translateExpression<T extends keyof ED>(entity: T, alias: string, expression: RefOrExpression<keyof ED[T]['OpSchema']>, refDict: Record<string, [string, keyof ED]>): string;
24
- private getStorageName;
25
- translateInsert<T extends keyof ED>(entity: T, data: ED[T]['CreateMulti']['data']): string;
26
- /**
27
- * analyze the join relations in projection/query/sort
28
- * 所有的层次关系都当成left join处理,如果有内表为空的情况,请手动处理
29
- * {
30
- * b: {
31
- * name: {
32
- * $exists: false,
33
- * }
34
- * }
35
- * }
36
- * 这样的query会把内表为空的行也返回
37
- * @param param0
38
- */
39
- private analyzeJoin;
40
- private translateComparison;
41
- private translateEvaluation;
42
- protected translatePredicate(predicate: string, value: any, type?: DataType | Ref): string;
43
- private translateFilter;
44
- private translateSorter;
45
- private translateProjection;
46
- private translateSelectInner;
47
- translateSelect<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
48
- translateWhere<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
49
- translateAggregate<T extends keyof ED, OP extends SqlSelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): string;
50
- translateCount<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, option?: OP): string;
51
- translateRemove<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Remove'], option?: OP): string;
52
- translateUpdate<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Update'], option?: OP): string;
53
- translateDestroyEntity(entity: string, truncate?: boolean): string;
54
- escapeStringValue(value: string): string;
55
- }
1
+ import { EntityDict, OperateOption, Q_FullTextValue, Ref, RefOrExpression, SelectOption, StorageSchema } from "oak-domain/lib/types";
2
+ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
3
+ import { DataType } from "oak-domain/lib/types/schema/DataTypes";
4
+ import { CreateEntityOption } from './types/Translator';
5
+ export interface SqlSelectOption extends SelectOption {
6
+ }
7
+ export interface SqlOperateOption extends OperateOption {
8
+ }
9
+ export declare abstract class SqlTranslator<ED extends EntityDict & BaseEntityDict> {
10
+ readonly schema: StorageSchema<ED>;
11
+ constructor(schema: StorageSchema<ED>);
12
+ private makeFullSchema;
13
+ protected abstract getDefaultSelectFilter<OP extends SqlSelectOption>(alias: string, option?: OP): string;
14
+ protected abstract translateAttrProjection(dataType: DataType, alias: string, attr: string): string;
15
+ protected abstract translateObjectProjection(projection: Record<string, any>, alias: string, attr: string, prefix: string): string;
16
+ protected abstract translateAttrValue(dataType: DataType | Ref, value: any): string;
17
+ protected abstract translateFullTextSearch<T extends keyof ED>(value: Q_FullTextValue, entity: T, alias: string): string;
18
+ abstract translateCreateEntity<T extends keyof ED>(entity: T, option: CreateEntityOption): string[];
19
+ protected abstract translateObjectPredicate(predicate: Record<string, any>, alias: string, attr: string): string;
20
+ 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;
21
+ 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;
22
+ 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;
23
+ protected abstract translateExpression<T extends keyof ED>(entity: T, alias: string, expression: RefOrExpression<keyof ED[T]['OpSchema']>, refDict: Record<string, [string, keyof ED]>): string;
24
+ protected getStorageName<T extends keyof ED>(entity: T): string;
25
+ translateInsert<T extends keyof ED>(entity: T, data: ED[T]['CreateMulti']['data']): string;
26
+ /**
27
+ * analyze the join relations in projection/query/sort
28
+ * 所有的层次关系都当成left join处理,如果有内表为空的情况,请手动处理
29
+ * {
30
+ * b: {
31
+ * name: {
32
+ * $exists: false,
33
+ * }
34
+ * }
35
+ * }
36
+ * 这样的query会把内表为空的行也返回
37
+ * @param param0
38
+ */
39
+ private analyzeJoin;
40
+ /**
41
+ * 对like模式中的特殊字符进行转义
42
+ * 例如 % _,以防止被当成通配符处理
43
+ * @param pattern like模式字符串
44
+ * @returns 转义后的字符串
45
+ */
46
+ escapeLikePattern(pattern: string): string;
47
+ private translateComparison;
48
+ private translateEvaluation;
49
+ protected translatePredicate(predicate: string, value: any, type?: DataType | Ref): string;
50
+ 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): {
51
+ stmt: string;
52
+ currentNumber: number;
53
+ };
54
+ private translateSorter;
55
+ private translateProjection;
56
+ private translateSelectInner;
57
+ translateSelect<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
58
+ translateWhere<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
59
+ translateAggregate<T extends keyof ED, OP extends SqlSelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): string;
60
+ translateCount<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, option?: OP): string;
61
+ translateRemove<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Remove'], option?: OP): string;
62
+ translateUpdate<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Update'], option?: OP): string;
63
+ translateDestroyEntity(entity: string, truncate?: boolean): string;
64
+ escapeStringValue(value: string): string;
65
+ /**比较两段sql是否完全一致,这里是把所有的空格去掉了 */
66
+ compareSql(sql1: string, sql2: string): boolean;
67
+ quoteIdentifier(name: string): string;
68
+ }