felixge/node-dirty

using dirty in a module

angelochen960 opened this issue · 1 comments

Hi,
I am trying to dirty in a module, sample code below, that code returns 'not loaded', what is a good way to put dirty in a module? Thanks

var dirty = require('dirty');
var db = dirty('sample.db');

var loaded = false

db.on('load', function() {
    console.log('loaded')
    loaded = true
})

exports.get_all_items = function() {
    return new Promise(function (resolve, reject) {        
        if (loaded)
            resovle(loaded) // just a test for now, should return all items in the db
        else
            reject('not loaded')                    
    })
}