"use strict"; import DataUtils from '../../../themes/default/src/com/tools/utilities/DataUtils'; import Dexie from 'dexie'; import * as DataEvent from '../events/DataEvent'; export default class DBUtils { //-------------------------- // constructor //-------------------------- constructor() { this.dataUtils = new DataUtils(); this.db = new Dexie("fipamo_posts"); this.db.version(1).stores( { postList: 'id,post' }); } //-------------------------- // methods //-------------------------- resetLocal(array) { let self = this; return new Promise(function(resolve, reject) { self.db.postList.clear().then(result => { self.db.postList.bulkAdd(array).then(key => { self.db.postList.toArray(array => { let event = DataEvent.LOCAL_DB_READY resolve( { event }) }) }).catch(Dexie.BulkError, e => { reject( { e }) }) }) }) } //-------------------------- // event handlers //-------------------------- }