import { Collection } from 'couchbase'; import { SchemaTypes } from './utils/utils.schema'; import { CustomQueryPagination } from './search'; export interface AutoModelFields { id: string; createdAt: Date; updatedAt?: Date; deleted?: Date; _type: string; _scope: string; } interface ModalOptions { scope?: string; schema?: Record; } export declare class Model { collection: Collection; collectionName: string; scope: string; schema: Record; constructor(name: string, options?: ModalOptions); /** * Refresh and get default collection from SofaConnection * Because SofaConnection is a singleton, sometimes it might be undefined depending when model was created * So we have to call it from all model methods * to avoid error `Cannot read property 'defaultCollection' of null` */ fresh(): void; /** Get this collection * getCollection */ getCollection(): Collection; /** * create */ create(data: T): Promise; /** * findById */ findById(id: string): Promise; /** * update */ updateById(id: string, data: T): Promise; /** * save */ save(data: T & { id: string; }): Promise; delete(id: string): Promise; /** * Pagination * select = ['id', 'createdAt'] where = { where: { owner: { $eq: "stoqey" }, _type: { $eq: "Trade" } }, }, page = 0, limit = 10, orderBy = { createdAt: "DESC" }, * @param args PaginationArgs */ pagination({ select, where, orderBy, limit, page, customQuery, }: { select?: any[] | string; where?: any; orderBy?: any; limit?: number; page?: number; customQuery?: any; }): Promise; /** * Run a custom query with model parsing * @param { select, query } * @returns */ customQuery({ params, limit, query, }: { params: any; limit: number; query: string; }): Promise<[T[], CustomQueryPagination]>; parse(data: T): T; } export default Model;