import "reflect-metadata" ; import { ActiveQuery } from "./ActiveQuery" ; import { FuseDB } from "./FuseDB" ; import { storeProp } from "./Utils" ; import { IInsertManyResponse } from "./adapters/Adapter" ; export class Model < T > { public $fusedb : FuseDB ; public _id : any ; constructor ( props ? ) { storeProp ( this , "$fusedb" , ( ) => new FuseDB ( this ) ) ; if ( props ) { this . $fusedb . assignProps ( props ) ; } } public async save ( ) { return this . $fusedb . saveRecord ( ) as Promise < Model < T > > ; } public async remove ( ) { return this . $fusedb . remove ( ) ; } public static drop < T > ( opts ? ) { const Cls = new this ( ) ; return Cls . $fusedb . drop ( ) ; } public static find < T > ( opts ? ) { const Cls = new this ( ) ; return Cls . $fusedb . find ( opts ) as ActiveQuery < T > ; } public static insertMany < T > ( data ) { const Cls = new this ( ) ; return Cls . $fusedb . insertMany ( data ) ; } public static findById < T > ( id ) { const Cls = new this ( ) ; return Cls . $fusedb . find ( { _id : id } ) . first ( ) ; } public toJSON ( ) { return this . $fusedb . toJSON ( ) ; } }