diff --git a/app/controllers/app.js b/app/controllers/app.js index dded7f24..c7611e47 100755 --- a/app/controllers/app.js +++ b/app/controllers/app.js @@ -55,6 +55,7 @@ var apiKeyAuth = new ApiKeyAuth(Meta, cdbReq); // Set default configuration global.settings.db_pubuser = global.settings.db_pubuser || "publicuser"; +global.settings.bufferedRows = global.settings.bufferedRows || 1000; var tableCache = LRU({ // store no more than these many items in the cache @@ -470,6 +471,8 @@ function handleQuery(req, res) { skipfields: skipfields, sql: sql, filename: filename, + bufferedRows: global.settings.bufferedRows, + callback: params.callback, abortChecker: checkAborted }; diff --git a/app/models/formats/json.js b/app/models/formats/json.js index f30eff27..dfb662a9 100644 --- a/app/models/formats/json.js +++ b/app/models/formats/json.js @@ -1,14 +1,16 @@ -var pg = require('./pg'); +var pg = require('./pg'), + util = require('util'), + _ = require('underscore'); -function json() {} +function JsonFormat() { + this.buffer = ''; +} -json.prototype = new pg('json'); +JsonFormat.prototype = new pg('json'); -var p = json.prototype; +JsonFormat.prototype._contentType = "application/json; charset=utf-8"; -p._contentType = "application/json; charset=utf-8"; - -p.formatResultFields = function(flds) { +JsonFormat.prototype.formatResultFields = function(flds) { var nfields = {}; for (var i=0; i 0 ) { + var notices = {}, + severities = []; + _.each(result.notices, function(notice) { + var severity = notice.severity.toLowerCase() + 's'; + if (!notices[severity]) { + severities.push(severity); + notices[severity] = []; + } + notices[severity].push(notice.message) + }); + _.each(severities, function(severity) { + out.push(','); + out.push(JSON.stringify(severity)); + out.push(':'); + out.push(JSON.stringify(notices[severity])); + }); + } + + out.push('}'); + + + this.buffer += out.join(''); + + if (this.opts.callback) { + this.buffer += ')'; + } + + this.opts.sink.write(this.buffer); + this.opts.sink.end(); + this.buffer = ''; + + this.callback(); +}; + +module.exports = JsonFormat; diff --git a/app/models/formats/pg.js b/app/models/formats/pg.js index 7580ffd8..23e6f8a9 100644 --- a/app/models/formats/pg.js +++ b/app/models/formats/pg.js @@ -30,15 +30,14 @@ PostgresFormat.prototype.handleQueryRowWithSkipFields = function(row, result) { for ( var j=0; j