diff --git a/packages/pg-native/bench/index.js b/packages/pg-native/bench/index.js index 05dbc949b..88238dc90 100644 --- a/packages/pg-native/bench/index.js +++ b/packages/pg-native/bench/index.js @@ -19,7 +19,7 @@ var warmup = function (fn, cb) { var native = Native() native.connectSync() -var queryText = 'SELECT generate_series(0, 1000)' +var queryText = 'SELECT generate_series(0, 1000) as X, generate_series(0, 1000) as Y, generate_series(0, 1000) as Z' var client = new pg.Client() client.connect(function () { var pure = function (cb) { @@ -36,12 +36,12 @@ client.connect(function () { } var run = function () { - var start = Date.now() + console.time('pure') warmup(pure, function () { - console.log('pure done', Date.now() - start) - start = Date.now() + console.timeEnd('pure') + console.time('native') warmup(nativeQuery, function () { - console.log('native done', Date.now() - start) + console.timeEnd('native') }) }) } diff --git a/packages/pg-native/lib/build-result.js b/packages/pg-native/lib/build-result.js index 38408a608..bc2e194a3 100644 --- a/packages/pg-native/lib/build-result.js +++ b/packages/pg-native/lib/build-result.js @@ -18,46 +18,43 @@ class Result { consumeFields(pq) { const nfields = pq.nfields() + this.fields = new Array(nfields) for (var x = 0; x < nfields; x++) { - this.fields.push({ + this.fields[x] = { name: pq.fname(x), - dataTypeID: pq.ftype(x), - }) + dataTypeID: pq.ftype(x) + } } } consumeRows(pq) { const tupleCount = pq.ntuples() + this.rows = new Array(tupleCount) for (var i = 0; i < tupleCount; i++) { - const row = this._arrayMode ? this.consumeRowAsArray(pq, i) : this.consumeRowAsObject(pq, i) - this.rows.push(row) + this.rows[i] = this._arrayMode ? this.consumeRowAsArray(pq, i) : this.consumeRowAsObject(pq, i) } } consumeRowAsObject(pq, rowIndex) { const row = {} for (var j = 0; j < this.fields.length; j++) { - const value = this.readValue(pq, rowIndex, j) - row[this.fields[j].name] = value + row[this.fields[j].name] = this.readValue(pq, rowIndex, j) } return row } consumeRowAsArray(pq, rowIndex) { - const row = [] + const row = new Array(this.fields.length) for (var j = 0; j < this.fields.length; j++) { - const value = this.readValue(pq, rowIndex, j) - row.push(value) + row[j] = this.readValue(pq, rowIndex, j) } return row } readValue(pq, rowIndex, colIndex) { var rawValue = pq.getvalue(rowIndex, colIndex) - if (rawValue === '') { - if (pq.getisnull(rowIndex, colIndex)) { - return null - } + if (rawValue === '' && pq.getisnull(rowIndex, colIndex)) { + return null } const dataTypeId = this.fields[colIndex].dataTypeID return this._types.getTypeParser(dataTypeId)(rawValue) diff --git a/packages/pg/lib/result.js b/packages/pg/lib/result.js index 98018a7d8..f510d2463 100644 --- a/packages/pg/lib/result.js +++ b/packages/pg/lib/result.js @@ -37,7 +37,7 @@ class Result { if (match) { this.command = match[1] if (match[3]) { - // COMMMAND OID ROWS + // COMMAND OID ROWS this.oid = parseInt(match[2], 10) this.rowCount = parseInt(match[3], 10) } else if (match[2]) {