Skip to content

Instantly share code, notes, and snippets.

@gbrault
Created November 15, 2016 16:21
Show Gist options
  • Save gbrault/4859a8af6378bbb0e482575d0cb5f6bb to your computer and use it in GitHub Desktop.
Save gbrault/4859a8af6378bbb0e482575d0cb5f6bb to your computer and use it in GitHub Desktop.
How to shrink sqlite3.node verbose output for big tables
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