import Datastore from 'nedb' ; import { LocalTag } from '~/src/types/localTag' ; export default class Hashtags { private db : Datastore ; constructor ( db ) { this . db = db ; this . db . ensureIndex ( { fieldName : 'tagName' , unique : true } , _ => { } ) ; } listTags ( ) { return new Promise ( ( resolve , reject ) => { this . db . find < LocalTag > ( { } , ( err , docs ) => { if ( err ) return reject ( err ) ; resolve ( docs ) ; } ) ; } ) ; } insertTag ( tag ) { return new Promise ( ( resolve , reject ) => { this . db . insert ( { tagName : tag } , ( err , doc ) => { if ( err ) return reject ( err ) ; resolve ( doc ) ; } ) ; } ) ; } removeTag ( localTag ) { return new Promise ( ( resolve , reject ) => { this . db . remove ( { tagName : localTag . tagName } , { multi : true } , ( err , numRemoved ) => { if ( err ) return reject ( err ) ; resolve ( numRemoved ) ; } ) ; } ) ; } }