UNPKG

jdb-lite

Version:

A lightweight schema-based JSON database library with validation

69 lines 2.77 kB
import { Schema } from './schema'; import { DatabaseManager } from './database'; import { Document, Query, Model, ModelInstance } from './types'; export declare class QueryBuilder<T extends Document> implements Query<T> { private db; private collectionName; private _filter; private _sort; private _limit; private _skip; private _select; private _populate; constructor(db: DatabaseManager, collectionName: string); then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>; catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T[] | TResult>; find(filter?: Partial<T>): Promise<T[]>; findOne(filter?: Partial<T>): Promise<T | null>; findById(id: string): Promise<T | null>; findByIdAndUpdate(id: string, update: Partial<T>, options?: { new?: boolean; }): Promise<T | null>; findByIdAndDelete(id: string): Promise<T | null>; findOneAndUpdate(filter: Partial<T>, update: Partial<T>, options?: { new?: boolean; }): Promise<T | null>; findOneAndDelete(filter: Partial<T>): Promise<T | null>; updateOne(filter: Partial<T>, update: Partial<T>): Promise<{ modifiedCount: number; }>; updateMany(filter: Partial<T>, update: Partial<T>): Promise<{ modifiedCount: number; }>; deleteOne(filter: Partial<T>): Promise<{ deletedCount: number; }>; deleteMany(filter: Partial<T>): Promise<{ deletedCount: number; }>; countDocuments(filter?: Partial<T>): Promise<number>; sort(sortBy: string | { [key: string]: 1 | -1; }): Query<T>; limit(limit: number): Query<T>; skip(skip: number): Query<T>; select(fields: string | string[] | { [key: string]: 0 | 1; }): Query<T>; populate(path: string | string[]): Query<T>; exec(): Promise<T[]>; } export declare class DocumentInstance<T extends Document> implements ModelInstance<T> { private _doc; private _schema; private _isNew; private _modified; constructor(doc: T, schema: Schema<T>, isNew?: boolean); get isNew(): boolean; isModified(path?: string): boolean; markModified(path: string): void; save(): Promise<T>; remove(): Promise<T>; toObject(): T; toJSON(): T; populate(path: string | string[]): Promise<T>; depopulate(path: string): T; validate(): Promise<void>; } export declare function createModel<T extends Document>(name: string, schema: Schema<T>, db: DatabaseManager): Model<T>; //# sourceMappingURL=model.d.ts.map