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

前端 未结 3 1987
清歌不尽
清歌不尽 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 21:02

    You have to install sql.js with npm install --save sql.js

    Rest follow the below steps :

    var fs = require('fs');    
    var sql = require('sql.js');    
    var bfr = fs.readFileSync('/tmp/db.sqlite');
    
    var db = new sql.Database(bfr);
    db.each('SELECT * FROM test', function (row) {
    
      console.log(row);
    
    });
    

    More details you can get on the below this link : https://discuss.atom.io/t/how-to-access-a-local-db-on-windows-through-electron/22400/13

提交回复
热议问题