Created
November 15, 2016 16:21
-
-
Save gbrault/4859a8af6378bbb0e482575d0cb5f6bb to your computer and use it in GitHub Desktop.
How to shrink sqlite3.node verbose output for big tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sqlite3=require('sqlite3'); | |
var pgu={ | |
db: {}, | |
res: {}, | |
all: function (topic,bind=[]){ | |
this.db.all(topic, bind, function(err, row) { | |
if (err) { console.log(err,msg); return null;} | |
else { | |
this.res=row; | |
console.log(JSON.stringify(this.res)); | |
this.factorize(topic,bind); | |
} | |
}.bind(this)); | |
}, | |
factorize: function (topic,bind=[]){ | |
var rows= this.res; | |
console.log(JSON.stringify(this.res)); | |
if(rows!==undefined && rows!==null && rows.length>0){ | |
var colnames = Object.keys(rows[0]); | |
var arows = []; | |
for(var i=0; i<rows.length; i++){ | |
var trow=[]; | |
for(var j=0; j<colnames.length;j++){ | |
trow.push(rows[i][colnames[j]]); | |
} | |
arows.push(trow); | |
} | |
this.res = {"columns":colnames,"values":arows}; | |
} | |
} | |
}; | |
pgu.db = new sqlite3.Database('Northwind.sqlite'); | |
pgu.all("select * from customer"); | |
if(pgu.res!==null){ | |
console.log(JSON.stringify(pgu.res)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment