Skip to content

Commit 57b1add

Browse files
committed
build
1 parent 498f2ae commit 57b1add

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

cjs/src/connection.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
180180
throw Errors.generic('MAX_PARAMETERS_EXCEEDED', 'Max number of parameters (65534) exceeded')
181181

182182
return q.options.simple
183-
? b().Q().str(q.strings[0] + b.N).end()
183+
? b().Q().str(q.statement.string + b.N).end()
184184
: q.describeFirst
185185
? Buffer.concat([describe(q), Flush])
186186
: q.prepare
@@ -266,6 +266,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
266266
socket.removeAllListeners()
267267
socket = tls.connect({
268268
socket,
269+
servername: net.isIP(socket.host) ? undefined : socket.host,
269270
...(ssl === 'require' || ssl === 'allow' || ssl === 'prefer'
270271
? { rejectUnauthorized: false }
271272
: ssl === 'verify-full'

cjs/src/types.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ const Builder = module.exports.Builder = class Builder extends NotTagged {
6666

6767
build(before, parameters, types, options) {
6868
const keyword = builders.map(([x, fn]) => ({ fn, i: before.search(x) })).sort((a, b) => a.i - b.i).pop()
69-
if (keyword.i === -1)
70-
throw new Error('Could not infer helper mode')
71-
72-
return keyword.fn(this.first, this.rest, parameters, types, options)
69+
return keyword.i === -1
70+
? escapeIdentifiers(this.first, options)
71+
: keyword.fn(this.first, this.rest, parameters, types, options)
7372
}
7473
}
7574

@@ -137,7 +136,7 @@ function values(first, rest, parameters, types, options) {
137136
function select(first, rest, parameters, types, options) {
138137
typeof first === 'string' && (first = [first].concat(rest))
139138
if (Array.isArray(first))
140-
return first.map(x => escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x)).join(',')
139+
return escapeIdentifiers(first, options)
141140

142141
let value
143142
const columns = rest.length ? rest.flat() : Object.keys(first)
@@ -170,9 +169,7 @@ const builders = Object.entries({
170169

171170
insert(first, rest, parameters, types, options) {
172171
const columns = rest.length ? rest.flat() : Object.keys(Array.isArray(first) ? first[0] : first)
173-
return '(' + columns.map(x =>
174-
escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x)
175-
).join(',') + ')values' +
172+
return '(' + escapeIdentifiers(columns, options) + ')values' +
176173
valuesBuilder(Array.isArray(first) ? first : [first], parameters, types, columns, options)
177174
}
178175
}).map(([x, fn]) => ([new RegExp('((?:^|[\\s(])' + x + '(?:$|[\\s(]))(?![\\s\\S]*\\1)', 'i'), fn]))
@@ -209,6 +206,10 @@ function typeHandlers(types) {
209206
}, { parsers: {}, serializers: {} })
210207
}
211208

209+
function escapeIdentifiers(xs, { transform: { column } }) {
210+
return xs.map(x => escapeIdentifier(column.to ? column.to(x) : x)).join(',')
211+
}
212+
212213
const escapeIdentifier = module.exports.escapeIdentifier = function escape(str) {
213214
return '"' + str.replace(/"/g, '""').replace(/\./g, '"."') + '"'
214215
}

deno/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
- 🏄‍♀️ Simple surface API
66
- 🖊️ Dynamic query support
77
- 💬 Chat and help on [Gitter](https://gitter.im/porsager/postgres)
8+
- 🐦 Follow on [Twitter](https://twitter.com/rporsager)
89

910
<br>
1011

1112
## Getting started
1213

1314
<br>
14-
<img height="220" alt="Good UX with Postgres.js" src="https://raw.githubusercontent.com/porsager/postgres/master/demo.gif">
15+
<img height="220" width="458" alt="Good UX with Postgres.js" src="https://raw.githubusercontent.com/porsager/postgres/master/demo.gif">
1516
<br>
1617

1718

deno/src/connection.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
184184
throw Errors.generic('MAX_PARAMETERS_EXCEEDED', 'Max number of parameters (65534) exceeded')
185185

186186
return q.options.simple
187-
? b().Q().str(q.strings[0] + b.N).end()
187+
? b().Q().str(q.statement.string + b.N).end()
188188
: q.describeFirst
189189
? Buffer.concat([describe(q), Flush])
190190
: q.prepare
@@ -270,6 +270,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
270270
socket.removeAllListeners()
271271
socket = tls.connect({
272272
socket,
273+
servername: net.isIP(socket.host) ? undefined : socket.host,
273274
...(ssl === 'require' || ssl === 'allow' || ssl === 'prefer'
274275
? { rejectUnauthorized: false }
275276
: ssl === 'verify-full'

deno/src/types.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ export class Builder extends NotTagged {
6767

6868
build(before, parameters, types, options) {
6969
const keyword = builders.map(([x, fn]) => ({ fn, i: before.search(x) })).sort((a, b) => a.i - b.i).pop()
70-
if (keyword.i === -1)
71-
throw new Error('Could not infer helper mode')
72-
73-
return keyword.fn(this.first, this.rest, parameters, types, options)
70+
return keyword.i === -1
71+
? escapeIdentifiers(this.first, options)
72+
: keyword.fn(this.first, this.rest, parameters, types, options)
7473
}
7574
}
7675

@@ -138,7 +137,7 @@ function values(first, rest, parameters, types, options) {
138137
function select(first, rest, parameters, types, options) {
139138
typeof first === 'string' && (first = [first].concat(rest))
140139
if (Array.isArray(first))
141-
return first.map(x => escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x)).join(',')
140+
return escapeIdentifiers(first, options)
142141

143142
let value
144143
const columns = rest.length ? rest.flat() : Object.keys(first)
@@ -171,9 +170,7 @@ const builders = Object.entries({
171170

172171
insert(first, rest, parameters, types, options) {
173172
const columns = rest.length ? rest.flat() : Object.keys(Array.isArray(first) ? first[0] : first)
174-
return '(' + columns.map(x =>
175-
escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x)
176-
).join(',') + ')values' +
173+
return '(' + escapeIdentifiers(columns, options) + ')values' +
177174
valuesBuilder(Array.isArray(first) ? first : [first], parameters, types, columns, options)
178175
}
179176
}).map(([x, fn]) => ([new RegExp('((?:^|[\\s(])' + x + '(?:$|[\\s(]))(?![\\s\\S]*\\1)', 'i'), fn]))
@@ -210,6 +207,10 @@ function typeHandlers(types) {
210207
}, { parsers: {}, serializers: {} })
211208
}
212209

210+
function escapeIdentifiers(xs, { transform: { column } }) {
211+
return xs.map(x => escapeIdentifier(column.to ? column.to(x) : x)).join(',')
212+
}
213+
213214
export const escapeIdentifier = function escape(str) {
214215
return '"' + str.replace(/"/g, '""').replace(/\./g, '"."') + '"'
215216
}

0 commit comments

Comments
 (0)