postgres
Advanced tools
Comparing version 3.3.4 to 3.3.5
@@ -169,2 +169,3 @@ const net = require('net') | ||
&& !q.describeFirst | ||
&& !q.cursorFn | ||
&& sent.length < max_pipeline | ||
@@ -739,7 +740,8 @@ && (!q.options.onexecute || q.options.onexecute(connection)) | ||
function addArrayType(oid, typarray) { | ||
if (!!options.parsers[typarray] && !!options.serializers[typarray]) return | ||
const parser = options.parsers[oid] | ||
options.shared.typeArrayMap[oid] = typarray | ||
options.parsers[typarray] = (xs) => arrayParser(xs, parser) | ||
options.parsers[typarray] = (xs) => arrayParser(xs, parser, typarray) | ||
options.parsers[typarray].array = true | ||
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options) | ||
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options, typarray) | ||
} | ||
@@ -746,0 +748,0 @@ |
@@ -238,3 +238,3 @@ const { Query } = require('./query.js') | ||
const arraySerializer = module.exports.arraySerializer = function arraySerializer(xs, serializer, options) { | ||
const arraySerializer = module.exports.arraySerializer = function arraySerializer(xs, serializer, options, typarray) { | ||
if (Array.isArray(xs) === false) | ||
@@ -247,5 +247,7 @@ return xs | ||
const first = xs[0] | ||
// Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter | ||
const delimiter = typarray === 1020 ? ';' : ',' | ||
if (Array.isArray(first) && !first.type) | ||
return '{' + xs.map(x => arraySerializer(x, serializer)).join(',') + '}' | ||
return '{' + xs.map(x => arraySerializer(x, serializer, options, typarray)).join(delimiter) + '}' | ||
@@ -262,3 +264,3 @@ return '{' + xs.map(x => { | ||
: '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : '' + x) + '"' | ||
}).join(',') + '}' | ||
}).join(delimiter) + '}' | ||
} | ||
@@ -274,9 +276,11 @@ | ||
const arrayParser = module.exports.arrayParser = function arrayParser(x, parser) { | ||
const arrayParser = module.exports.arrayParser = function arrayParser(x, parser, typarray) { | ||
arrayParserState.i = arrayParserState.last = 0 | ||
return arrayParserLoop(arrayParserState, x, parser) | ||
return arrayParserLoop(arrayParserState, x, parser, typarray) | ||
} | ||
function arrayParserLoop(s, x, parser) { | ||
function arrayParserLoop(s, x, parser, typarray) { | ||
const xs = [] | ||
// Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter | ||
const delimiter = typarray === 1020 ? ';' : ',' | ||
for (; s.i < x.length; s.i++) { | ||
@@ -299,3 +303,3 @@ s.char = x[s.i] | ||
s.last = ++s.i | ||
xs.push(arrayParserLoop(s, x, parser)) | ||
xs.push(arrayParserLoop(s, x, parser, typarray)) | ||
} else if (s.char === '}') { | ||
@@ -306,3 +310,3 @@ s.quoted = false | ||
break | ||
} else if (s.char === ',' && s.p !== '}' && s.p !== '"') { | ||
} else if (s.char === delimiter && s.p !== '}' && s.p !== '"') { | ||
xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i)) | ||
@@ -309,0 +313,0 @@ s.last = s.i + 1 |
{ | ||
"name": "postgres", | ||
"version": "3.3.4", | ||
"version": "3.3.5", | ||
"description": "Fastest full featured PostgreSQL client for Node.js", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -531,2 +531,24 @@ <img align="left" width="440" height="180" alt="Fastest full PostgreSQL nodejs client" src="https://raw.githubusercontent.com/porsager/postgres/master/postgresjs.svg?sanitize=true"> | ||
``` | ||
You can also nest `sql.unsafe` within a safe `sql` expression. This is useful if only part of your fraction has unsafe elements. | ||
```js | ||
const triggerName = 'friend_created' | ||
const triggerFnName = 'on_friend_created' | ||
const eventType = 'insert' | ||
const schema_name = 'app' | ||
const table_name = 'friends' | ||
await sql` | ||
create or replace trigger ${sql(triggerName)} | ||
after ${sql.unsafe(eventType)} on ${sql.unsafe(`${schema_name}.${table_name}`)} | ||
for each row | ||
execute function ${sql(triggerFnName)}() | ||
` | ||
await sql` | ||
create role friend_service with login password ${sql.unsafe(`'${password}'`)} | ||
` | ||
``` | ||
</details> | ||
@@ -533,0 +555,0 @@ |
@@ -169,2 +169,3 @@ import net from 'net' | ||
&& !q.describeFirst | ||
&& !q.cursorFn | ||
&& sent.length < max_pipeline | ||
@@ -739,7 +740,8 @@ && (!q.options.onexecute || q.options.onexecute(connection)) | ||
function addArrayType(oid, typarray) { | ||
if (!!options.parsers[typarray] && !!options.serializers[typarray]) return | ||
const parser = options.parsers[oid] | ||
options.shared.typeArrayMap[oid] = typarray | ||
options.parsers[typarray] = (xs) => arrayParser(xs, parser) | ||
options.parsers[typarray] = (xs) => arrayParser(xs, parser, typarray) | ||
options.parsers[typarray].array = true | ||
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options) | ||
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options, typarray) | ||
} | ||
@@ -746,0 +748,0 @@ |
@@ -238,3 +238,3 @@ import { Query } from './query.js' | ||
export const arraySerializer = function arraySerializer(xs, serializer, options) { | ||
export const arraySerializer = function arraySerializer(xs, serializer, options, typarray) { | ||
if (Array.isArray(xs) === false) | ||
@@ -247,5 +247,7 @@ return xs | ||
const first = xs[0] | ||
// Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter | ||
const delimiter = typarray === 1020 ? ';' : ',' | ||
if (Array.isArray(first) && !first.type) | ||
return '{' + xs.map(x => arraySerializer(x, serializer)).join(',') + '}' | ||
return '{' + xs.map(x => arraySerializer(x, serializer, options, typarray)).join(delimiter) + '}' | ||
@@ -262,3 +264,3 @@ return '{' + xs.map(x => { | ||
: '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : '' + x) + '"' | ||
}).join(',') + '}' | ||
}).join(delimiter) + '}' | ||
} | ||
@@ -274,9 +276,11 @@ | ||
export const arrayParser = function arrayParser(x, parser) { | ||
export const arrayParser = function arrayParser(x, parser, typarray) { | ||
arrayParserState.i = arrayParserState.last = 0 | ||
return arrayParserLoop(arrayParserState, x, parser) | ||
return arrayParserLoop(arrayParserState, x, parser, typarray) | ||
} | ||
function arrayParserLoop(s, x, parser) { | ||
function arrayParserLoop(s, x, parser, typarray) { | ||
const xs = [] | ||
// Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter | ||
const delimiter = typarray === 1020 ? ';' : ',' | ||
for (; s.i < x.length; s.i++) { | ||
@@ -299,3 +303,3 @@ s.char = x[s.i] | ||
s.last = ++s.i | ||
xs.push(arrayParserLoop(s, x, parser)) | ||
xs.push(arrayParserLoop(s, x, parser, typarray)) | ||
} else if (s.char === '}') { | ||
@@ -306,3 +310,3 @@ s.quoted = false | ||
break | ||
} else if (s.char === ',' && s.p !== '}' && s.p !== '"') { | ||
} else if (s.char === delimiter && s.p !== '}' && s.p !== '"') { | ||
xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i)) | ||
@@ -309,0 +313,0 @@ s.last = s.i + 1 |
210039
5074
1241