import fs from "fs" ; import levelup , { LevelUp } from "levelup" ; import rocksdb from "rocksdb" ; export abstract class RocksdbBase { protected _path : string ; protected _db : LevelUp ; constructor ( path ) { this . _path = path ; fs . mkdirSync ( this . _path , { recursive : true } ) ; this . _db = levelup ( rocksdb ( this . _path ) ) ; } public async open ( ) { return this . _db . open ( ) ; } public async close ( ) { return this . _db . close ( ) ; } protected async _safeGet < T > ( key ) { try { return await this . _db . get ( key ) ; } catch ( err ) { if ( err . notFound ) return ; else throw err ; } } }