Normalize parameter values

This commit is contained in:
Brian M. Carlson 2014-02-26 09:30:00 -06:00
parent cc9f08a042
commit f1dbe7884c
4 changed files with 22 additions and 5 deletions

View File

@ -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'

View File

@ -14,5 +14,6 @@
"devDependencies": {
"pg.js": "~2.8.1",
"mocha": "~1.17.1"
}
},
"dependencies": {}
}

View File

@ -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

View File

@ -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()
})
})
})
})