UNPKG

sqlmongoose

Version:

Mongoose-like schemas and models for SQLite3

44 lines (43 loc) 1.18 kB
import { Database } from 'sqlite3'; import { Schema } from './Schema'; type Operator = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'in'; interface QueryCondition { [key: string]: { [op in Operator]?: any; }; } interface UpdateOperators { $inc?: { [key: string]: number; }; $set?: { [key: string]: any; }; $unset?: { [key: string]: any; }; } export declare class Model<T extends object> { private db; private tableName; private schema; constructor(db: Database, tableName: string, schema: Schema); private initialize; find(query?: QueryCondition | Partial<T>, options?: { populate?: string[]; limit?: number; offset?: number; orderBy?: { [key: string]: 'ASC' | 'DESC'; }; }): Promise<T[]>; findOne(query: Partial<T>): Promise<T | null>; create(data: T): Promise<T>; update(query: Partial<T>, update: UpdateOperators | Partial<T>): Promise<number>; private isUpdateOperator; delete(query: Partial<T>): Promise<number>; private populateRelationships; private isSimpleQuery; private query; } export {};