import * as Datastore from 'nedb' ; import IEngine from '../IEngine' ; import IExec from '../IExec' ; import NedbDatastore from './NedbDatastore' ; let db = new Map < string , NedbDatastore > ( ) ; export default class EngineNedb implements IEngine , IExec < NedbDatastore > { datastore : NedbDatastore ; constructor ( path , inMemoryOnly = false ) { let found = db . get ( path ) ; if ( found ) { this . datastore = found ; } else { let datastore = new Datastore ( { filename : path , autoload : true , inMemoryOnly : inMemoryOnly } ) ; this . datastore = new NedbDatastore ( datastore ) ; db . set ( path , this . datastore ) ; } } isConnected ( ) { return true ; } connect ( ) { return Promise . resolve ( ) ; } close ( ) { return Promise . resolve ( ) ; } async drop ( ) { await this . exec ( async ( client ) => { await client . remove ( { } , { multi : true } ) ; } ) ; } async exec < B > ( fn ) { return fn ( this . datastore ) ; } }