UNPKG

nodedb-json

Version:

A lightweight JSON-based database for Node.js with TypeScript support, indexing, and complex query capabilities

20 lines (19 loc) 1.1 kB
import type NodedbJson from '../database'; import type { IndexDefinition, MatchObject, PredicateFunction, QueryOptions, QueryOptionsWithSelect, QueryResult, QueryResultForOptions, UpdaterObject } from '../types'; export declare class Collection<T = any> { private readonly db; private readonly key; constructor(db: NodedbJson, key: string); all(): T[]; insert(item: T | T[]): this; findOne(where: MatchObject<T> | PredicateFunction<T>): T | undefined; findMany(where?: MatchObject<T> | PredicateFunction<T>): T[]; updateOne(where: MatchObject<T> | PredicateFunction<T>, updater: UpdaterObject<T>): this; deleteOne(where: MatchObject<T> | PredicateFunction<T>): this; query<TSelected extends Extract<keyof T, string>>(options: QueryOptionsWithSelect<T, TSelected>): QueryResult<Pick<T, TSelected>>; query<TOptions extends QueryOptions<T>>(options: TOptions): QueryResultForOptions<T, TOptions>; query(options?: QueryOptions<T>): QueryResult<T>; createIndex(indexDefinition: IndexDefinition<T>): this; private _toPredicate; private _matches; }