diff --git a/index.js b/index.js index 9b14f0f0..6f30e11f 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,9 @@ -var Result = require('./result') +var Result = require('./pg').Result +var prepare = require('./pg').prepareValue var Cursor = function(text, values) { this.text = text - this.values = values + this.values = values ? values.map(prepare) : null this.connection = null this._queue = [] this.state = 'initialized' diff --git a/package.json b/package.json index bda643f6..b027cf87 100644 --- a/package.json +++ b/package.json @@ -14,5 +14,6 @@ "devDependencies": { "pg.js": "~2.8.1", "mocha": "~1.17.1" - } + }, + "dependencies": {} } diff --git a/result.js b/pg.js similarity index 65% rename from result.js rename to pg.js index 45d36b0b..96cd7f9a 100644 --- a/result.js +++ b/pg.js @@ -9,4 +9,5 @@ try { pgPath = path.dirname(require.resolve('pg.js')) + '/lib' } -module.exports = require(path.join(pgPath, 'result.js')) +module.exports.Result = require(path.join(pgPath, 'result.js')) +module.exports.prepareValue = require(path.join(pgPath, 'utils.js')).prepareValue diff --git a/test/index.js b/test/index.js index 6ff31260..77b60cd2 100644 --- a/test/index.js +++ b/test/index.js @@ -84,7 +84,7 @@ describe('cursor', function() { this.timeout(10000) var text = 'SELECT generate_series as num FROM generate_series(0, 100000)' var values = [] - cursor = this.pgCursor(text, values); + var cursor = this.pgCursor(text, values); var count = 0; var read = function() { cursor.read(100, function(err, rows) { @@ -102,4 +102,18 @@ describe('cursor', function() { } read() }) + + it('normalizes parameter values', function(done) { + var text = 'SELECT $1::json me' + var values = [{name: 'brian'}] + var cursor = this.pgCursor(text, values); + cursor.read(1, function(err, rows) { + if(err) return done(err); + assert.equal(rows[0].me.name, 'brian') + cursor.read(1, function(err, rows) { + assert.equal(rows.length, 0) + done() + }) + }) + }) })