import Field from "./Field"; declare type PostConstructionFun = (obj: any) => void; export { PostConstructionFun }; export default abstract class DBConnection { /** * 开始事务 */ abstract beginTransaction(): Promise; /** * 提交 */ abstract commit(): Promise; /** * 回滚 */ abstract rollback(): Promise; /** * 关闭 */ abstract close(): Promise; /** * 执行update/delete查询,返回影响记录的数量 * @param sql * @param params */ abstract executeUpdate(sql: string, params: Array): Promise; /** * 执行select查询语句,返回数据列表 * @param sql * @param params * @param postConstruction */ listQuery(sql: string, params: Array | void, postConstruction: PostConstructionFun | void): Promise>; /** * 查询单条记录,如果有多条,返回第一条 * @param sql * @param params * @param postConstruction */ find(sql: string, params: Array | void, postConstruction: PostConstructionFun | void): Promise; /** * 执行sql,获取数据 * @param sql * @param params * @param postConstruction */ abstract fetchData(sql: string, params: Array | void, postConstruction: PostConstructionFun | void): Promise; /** * 获取查询结果对应的字段名列表 * @param result */ abstract getFields(result: any): Array; /** * 从结果中获得数据集 * @param result */ protected abstract getRowSet(result: any): Array; /** * 返回受影响的行数 * @param result */ abstract getAffectRows(result: any): number; /** * 下划线转换驼峰 * @param name * @returns {*} */ protected toCamel(name: any): any; /** * 构建字段对应列表 * @param fields * @protected */ protected buildFieldsMap(fields: Array): Map; /** * 将返回的多行数据转换成数组对象 * @param result * @protected */ resultToList(result: any): Array; /** * 返回设定结果集大小的附加语句 * @param rowCount * @param offset */ getRowSetLimitClause(rowCount: number, offset: number): string; /** * 将首行转换为对象,如果首行不存在,返回空 * @param result * @protected */ protected abstract getFirstRow(result: any): any; }