import { join } from 'path' ; import { readFileSync , writeFileSync } from 'fs' ; export class DataDB { private path : string ; constructor ( dbPath ) { this . path = join ( dbPath , 'data-' ) ; } async insert ( obj ) { try { writeFileSync ( this . path + obj . txid , typeof obj . data === 'string' ? obj . data : JSON . stringify ( obj . data ) , 'utf8' ) ; return obj ; } catch ( error ) { console . error ( { error } ) ; } } async findOne ( txid ) { const data = readFileSync ( this . path + txid , 'utf8' ) ; return { txid , data } ; } }