database-proxy
Version:
Through a set of access control rules configuration database access to realize the client directly access the database via HTTP.
117 lines • 3.59 kB
TypeScript
import { JoinParam, Order, Params } from '../types';
/**
* SqlBuilder: Mongo 操作语法生成 SQL 语句
*/
export declare class SqlBuilder {
readonly params: Params;
private _values;
constructor(params: Params);
static from(params: Params): SqlBuilder;
get table(): string;
get query(): any;
get projection(): any;
get orders(): Order[];
get data(): any;
get joins(): JoinParam[];
select(): {
sql: string;
values: any[];
};
update(): {
sql: string;
values: any[];
};
delete(): {
sql: string;
values: any[];
};
insert(): {
sql: string;
values: any[];
};
count(): {
sql: string;
values: any[];
};
protected addValues(values: any[]): void;
protected buildJoins(): string;
protected checkJoinType(joinType: string): boolean;
protected buildQuery(): string;
/**
*
* ```js
* {
* action: 'database.updateDocument',
* collection: 'categories',
* query: { _id: '6024f815acbf480fbb9648ce' },
* data: {
* '$set': { title: 'updated-title' },
* '$inc': { age: 1 },
* '$unset': { content: '' }
* },
* merge: true
* }
* ```
*/
protected buildUpdateData(): string;
protected buildInsertData(): string;
protected _buildData(): {
fields: string[];
values: any[];
};
protected buildOrder(): string;
protected buildLimit(_limit?: number): string;
/**
* 指定返回的字段
* @tip 在 mongo 中可以指定只显示哪些字段 或者 不显示哪些字段,而在 SQL 中我们只支持[只显示哪些字段]
* 示例数据: `projection: { age: 1, f1: 1}`
*/
protected buildProjection(): string;
protected values(): any[];
protected isBasicValue(value: any): boolean;
protected checkData(): void;
protected checkField(field_name: string): void;
protected checkProjection(name: string): void;
}
/**
* Mongo 查询转换为 SQL 查询
*/
export declare class SqlQueryBuilder {
readonly query: any;
private _values;
constructor(query: any);
static from(query: any): SqlQueryBuilder;
build(): string | null;
values(): any[];
protected buildOne(key: string, value: any): string;
/**
```js
query = {
f1: 0,
'$or': [
{ f2: 1},
{ f6: { '$lt': 4000 } },
{
'$and': [ { f6: { '$gt': 6000 } }, { f6: { '$lt': 8000 } } ]
}
]
}
// where 1=1 and f1 = 0 and (f2 = 1 and f6 < 4000 or (f6 > 6000 and f6 < 8000))
```
*/
protected processLogicOperator(operator: string, value: any[]): string;
protected processBasicValue(field: string, value: string | number | boolean | [], operator: string): string;
protected processQueryOperator(field: string, value: any): string;
protected addValue(value: any): void;
protected isBasicValue(value: any): boolean;
protected isLogicOperator(key: string): boolean;
protected isQueryOperator(key: string): boolean;
protected isOperator(key: string): boolean;
protected getQueryOperators(): string[];
hasNestedFieldInQuery(): boolean;
protected hasObjectIn(object: any): boolean;
protected mapQueryOperator(operator: string): string;
protected mapLogicOperator(operator: string): string;
protected checkField(field_name: any): void;
}
//# sourceMappingURL=sql_builder.d.ts.map