pao-aop-server
Version:
基于pao-aop的服务端框架
278 lines • 7.99 kB
TypeScript
import { MongoClient, InsertWriteOpResult, FilterQuery } from 'mongodb';
import { BaseService } from '../../base';
import { BaseAddon, IDataService, DataProcessResult, DataServiceMethods } from 'pao-aop';
/** 连接配置 */
export declare type ConnectionOption = {
ip: string;
port: string;
database: string;
};
/** 逻辑运算符 */
export declare enum LogicKeys {
AND = 0,
OR = 1
}
/** 数据过滤器接口 */
export interface IMongoDataFilter {
/**
* 获取条件
* @param paramValues 参数
*/
getCondition?(paramValues: {}): any;
}
/**
* 名称:过滤器
* @description 用于描述Mongo数据操作的过滤器
* @author huyl
*/
export declare class BaseMongoDataFilter extends BaseAddon implements IMongoDataFilter {
name?: string;
childrenFilters?: IMongoDataFilter[];
/**
* 过滤器
* @param name 名称
* @param childrenFilters 子过滤器
*/
constructor(name?: string, childrenFilters?: IMongoDataFilter[]);
/** 获取提条件 */
getCondition?(paramValues: {}): any;
/** 获取逻辑运算符 */
protected getLogicKey?(): any;
}
/**
* 名称:And逻辑过滤器
* @description 用于描述 Mongo 数据操作 AND 逻辑过滤器
* @author huyl
*/
export declare class AndMongoDataFilter extends BaseMongoDataFilter {
name?: string;
childrenFilters?: IMongoDataFilter[];
/**
* And逻辑过滤器
* @param name 名称
* @param childrenFilters 子过滤器
*/
constructor(name?: string, childrenFilters?: IMongoDataFilter[]);
protected getLogicKey(): any;
}
/**
* 名称:Or逻辑过滤器
* @description 用于描述 Mongo 数据操作 OR 逻辑过滤器
* @author huyl
*/
export declare class OrMongoDataFilter extends BaseMongoDataFilter {
name?: string;
childrenFilters?: IMongoDataFilter[];
/**
* And逻辑过滤器
* @param name 名称
* @param childrenFilters 子过滤器
*/
constructor(name?: string, childrenFilters?: IMongoDataFilter[]);
protected getLogicKey(): any;
}
/**
* 数据类型
*/
export declare enum DataType {
Date = 0,
String = 1,
Number = 2
}
/**
* 名称:字符串条件语句
* @description 用于Mongo数据操作条件的最基础的语句
* @author huyl
*/
export declare class StringMongoDataFilter extends BaseMongoDataFilter {
key?: string;
condition?: string;
/** 数据类型 */
dataType?: DataType;
/**
* 字符串条件语句
* @param name 名称
* @param key 字段名称
* @param condition 条件
* @param dataType 数据类型
*/
constructor(name?: string, key?: string, condition?: string, dataType?: DataType);
getCondition?(paramValues: {}): any;
/**
* 字符串格式化
* @description 需要处理特殊格式,如时间等
*/
format?(origin: string, ...args: any[]): string;
}
/**
* 名称:集合
* @description 用于描述Mongo数据集合的对象
* @author huyl
*/
export declare class BaseMongoCollection extends BaseAddon {
name?: string;
collection?: string;
primaryKeys?: string[];
filters?: {
[index: string]: {
name: string;
filter?: BaseMongoDataFilter;
};
};
/**
* 命令
* @param {string} name 名称
* @param {string} collection 集合名称
* @param {Object} filters 过滤器
*/
constructor(name?: string, collection?: string, primaryKeys?: string[], filters?: {
[index: string]: {
name: string;
filter?: BaseMongoDataFilter;
};
});
/**
* 获取条件
*/
getCondition?(filterName: string, paramValues?: {}): any;
}
/**
* 名称:Mongo DB 连接池
* @description 用于操作Mongo DB连接信息的对象
* @author huyl
*/
export declare class MongoConnectionPool extends BaseAddon {
protected conn: ConnectionOption | string;
protected database?: string;
/** Mongo DB 连接池 */
constructor(conn: ConnectionOption | string, database?: string);
/** 连接信息 */
protected readonly uri: string | undefined;
/** 创建连接 */
readonly connection: Promise<MongoClient>;
/** 获取数据库名称 */
readonly dbName: string;
}
/**
* 名称:Mongo DB 数据存储
* @description 完成Mongo DB主要增删查改等操作
* @author huyl
*/
export declare class MongoStorage extends BaseAddon {
protected pool: MongoConnectionPool;
/** Mongo 数据库每个文本的_id */
private obj_id_key?;
/** Mongo DB 数据存储 */
constructor(pool: MongoConnectionPool);
/**
* 查询
* @param {string} collection 集合名称
* @param {{}} where 条件
* @param {{}} option 统计配置
* @returns {Promise<any[]>} 结果
*/
select?(collection: string, where?: FilterQuery<any>, option?: {
skip: number;
limit: number;
}): Promise<Object[]>;
/**
* 更新
* @param {string} collection 集合名称
* @param {any[]} document 文档集合
* @returns {Promise<WriteOpResult>} 结果
*/
update?(collection: string, documents?: Object[]): Promise<number>;
/**
* 添加
* @param collection 集合名称
* @param documents 文档列表
*/
insert?(collection: string, documents: Object[]): Promise<InsertWriteOpResult>;
/**
* 删除
* @param {string} collection 集合名称
* @param {string[]} primaryKeys 主键列表
* @param {Object[]} objects 对象
* @returns {Promise<any>} 结果
*/
delete?(collection: string, primaryKeys: string[], objects?: Object[]): Promise<number>;
/**
* 获取集合文档数量
* @param collection 集合名称
* @param where 条件
*/
count?(collection: string, where?: {}): Promise<number>;
/**
*
* @param primaryKeys 主键关键字
* @param object
*/
private getFilterByObject?;
}
/**
* 名称:Mongo 数据查询服务
* @description 提供Mongo数据库查询的服务
* @author huyl
*/
export declare class MongoQueryService extends BaseService implements IDataService {
storage?: MongoStorage;
/** 集合列表 */
collectionList?: {
[index: string]: BaseMongoCollection;
};
/**
* Mongo 数据服务
* @param storage 数据存储
*/
constructor(storage?: MongoStorage);
/**
* 检查合法性
* @protected
* @param {string} commandString 命令ID
* @returns {BaseMongoCollection}
*/
protected checkValidity?(commandString: string): BaseMongoCollection;
/**
* 获取命令和过滤器名称
* @param commandID 命令ID
*/
private getCommandAndFilterName?;
/**
* 获取支持的方法
*/
getSupportMethods?(): Promise<DataServiceMethods[]>;
/**
* 查询
* @param {string} commandID 命令ID
* @param {{}} paramValues 参数
* @param {number} startIndex 开始索引
* @param {number} maxCount 最大行数,默认0为查询全部数据
*/
query?(commandID: string, paramValues: {}, startIndex?: number, maxCount?: number): Promise<any[]>;
/**
* 插入
* @param commandID 命令名称
* @param objects 对象
*/
insert?(commandID: string, objects: Object[]): Promise<DataProcessResult>;
/**
* 获取数量
* @param {string} commandID 命令ID
* @param {{}} paramValues 参数
*/
count?(commandID: string, paramValues: {}): Promise<number>;
/**
* 更新
* @param commandID 命令ID
* @param objects 待更新对象列表
*
*/
update?(commandID: string, objects: Object[]): Promise<number>;
/**
* 删除数据
* @param {string} commandID 命令ID
* @param {Object[]} objects 插入对象集合
*/
delete?(commandID: string, objects: Object[]): Promise<number>;
}
//# sourceMappingURL=index.d.ts.map