mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Normalize parameter values
This commit is contained in:
parent
cc9f08a042
commit
f1dbe7884c
5
index.js
5
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'
|
||||
|
||||
@ -14,5 +14,6 @@
|
||||
"devDependencies": {
|
||||
"pg.js": "~2.8.1",
|
||||
"mocha": "~1.17.1"
|
||||
}
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user