import { IKvDefineIndexesOptions, IKvIndex } from "./defineIndexes.js"; import { Kvlite } from "./Kvlite.js"; import { IKvFilter, IKvUpdateOp, IKvFindOptions } from "./type.js"; export interface IKvliteCollectionOptions { } /** * KvliteCollection * * 实现类似 MongoDB Collection 的接口 */ export declare class KvliteCollection { collectionName: string; _kvlite: Kvlite; _options: IKvliteCollectionOptions; /** 预编译的 SQL */ _stmts: ReturnType; constructor(kvlite: Kvlite, collectionName: string, options?: IKvliteCollectionOptions); /** 初始化预编译语句 */ _prepareStmts(): { stmtGet: import("../sqlite/type.js").Statement; stmtSet: import("../sqlite/type.js").Statement; stmtDel: import("../sqlite/type.js").Statement; stmtAll: import("../sqlite/type.js").Statement; stmtKeys: import("../sqlite/type.js").Statement; stmtCount: import("../sqlite/type.js").Statement; stmtClear: import("../sqlite/type.js").Statement; }; /** * 获取数据 */ get(key: string): TData | undefined; /** * 设置数据 */ set(key: string, data: TData): import("../sqlite/type.js").RunResult; /** * 更新 data 中的 JSON 字段 */ update(filter: string | IKvFilter, updateOp: IKvUpdateOp): any; /** * 删除数据 */ delete(key: string): import("../sqlite/type.js").RunResult; /** * 获取所有数据 */ getAll(): TData[]; /** * 获取所有 key */ keys(): string[]; /** * 根据 filter 在数据集合中查找数据 */ find(filter: IKvFilter, findOptions?: IKvFindOptions): [string, TData][]; /** * 遍历数据集合 */ forEach(each: (keyValue: [string, TData], index: number) => void): void; /** * 遍历数据集合,如果有回调函数返回 true,则停止遍历 */ some(each: (data: TData, key: string, index: number) => boolean): boolean; /** * 返回数据集合的数量 */ count(filter?: IKvFilter): number; /** * 清空数据集合 */ clear(): import("../sqlite/type.js").RunResult; /** * 定义索引 * 指定 data 中哪些字段需要创建索引,可以加快查询速度 * * field 为 false 会删除索引 * * @example * defineIndexes({ id:{unique:true}, name:true, age:{type:'number'} }) */ defineIndexes(indexes: { [field: string]: IKvIndex; }, options?: IKvDefineIndexesOptions): void; /** * 高性能的遍历数据集合,每次返回一批数据 * 最终会调用 each 函数,直到所有数据遍历完成 * @param options * @param each */ eachBatch(options: { filter: IKvFilter; limit?: number; projection?: string[]; }, each: (list: [string, TData][], batch: number) => void): void; /** * 异步高性能批量遍历,支持异步 each 回调 * @param options * @param each */ eachBatchAsync(options: { filter: IKvFilter; limit?: number; projection?: string[]; }, each: (list: [string, TData][], batch: number) => Promise): Promise; /** * 执行事务 * 执行一个函数,保证事务的完整性。 * 如果有大量的数据操作,如批量插入、删除、更新,使用事务能大幅度提高性能 */ runTransaction(func: () => any): void; /** * 内部复用的批量遍历核心方法 */ private _eachBatchCore; /** * 将集合所属的 Kvlite 导出为 Buffer 数据,可以保存为文件 */ toBuffer(): Buffer; } //# sourceMappingURL=KvliteCollection.d.ts.map