How to read a sqlite3 database, using node js, synchronously?

前端 未结 3 2007
清歌不尽
清歌不尽 2021-01-03 20:32
exports.allProbes = function() {
    var rows = db.all(\"SELECT * FROM probes;\");
    return rows;
};

main:
var json_values = allPro         


        
3条回答
  •  梦谈多话
    2021-01-03 20:52

    You will not be able to do that with sqlite3. With sqlite3 module the only available mode of operation is asynchronous execution, and you will have to use a callback. Eg.

    exports.allProbes = function(callback) {
        db.all("SELECT * FROM probes;", function(err, all) {
            callback(err, all);  
        });
    };
    

    Then in your code:

    var json_values;
    
    allProbes(function(err, all) {
        json_values = all;
    });
    

    Check sqlite3 API Docs.

提交回复
热议问题