mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Re-implement other patch
This commit is contained in:
parent
f9390dab6b
commit
ca4ac9983a
14
lib/utils.js
14
lib/utils.js
@ -32,6 +32,8 @@ function arrayString (val) {
|
||||
result = result + 'NULL'
|
||||
} else if (Array.isArray(val[i])) {
|
||||
result = result + arrayString(val[i])
|
||||
} else if (val[i] instanceof Buffer) {
|
||||
result += '\\\\x' + val[i].toString('hex')
|
||||
} else {
|
||||
result += escapeElement(prepareValue(val[i]))
|
||||
}
|
||||
@ -106,12 +108,12 @@ function dateToString (date) {
|
||||
|
||||
function dateToStringUTC (date) {
|
||||
var ret = pad(date.getUTCFullYear(), 4) + '-' +
|
||||
pad(date.getUTCMonth() + 1, 2) + '-' +
|
||||
pad(date.getUTCDate(), 2) + 'T' +
|
||||
pad(date.getUTCHours(), 2) + ':' +
|
||||
pad(date.getUTCMinutes(), 2) + ':' +
|
||||
pad(date.getUTCSeconds(), 2) + '.' +
|
||||
pad(date.getUTCMilliseconds(), 3)
|
||||
pad(date.getUTCMonth() + 1, 2) + '-' +
|
||||
pad(date.getUTCDate(), 2) + 'T' +
|
||||
pad(date.getUTCHours(), 2) + ':' +
|
||||
pad(date.getUTCMinutes(), 2) + ':' +
|
||||
pad(date.getUTCSeconds(), 2) + '.' +
|
||||
pad(date.getUTCMilliseconds(), 3)
|
||||
|
||||
return ret + '+00:00'
|
||||
}
|
||||
|
||||
@ -139,6 +139,13 @@ test('prepareValue: objects with simple toPostgres prepared properly', function
|
||||
assert.strictEqual(out, 'zomgcustom!')
|
||||
})
|
||||
|
||||
test('prepareValue: buffer array prepared properly', function() {
|
||||
var buffer1 = Buffer.from('dead', 'hex')
|
||||
var buffer2 = Buffer.from('beef', 'hex')
|
||||
var out = utils.prepareValue([buffer1, buffer2])
|
||||
assert.strictEqual(out, '{\\\\xdead,\\\\xbeef}')
|
||||
})
|
||||
|
||||
test('prepareValue: objects with complex toPostgres prepared properly', function () {
|
||||
var buf = Buffer.from('zomgcustom!')
|
||||
var customType = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user