Skip to content

Commit c2eb7c9

Browse files
committed
Cleanup
1 parent c1de3d8 commit c2eb7c9

File tree

13 files changed

+30
-23
lines changed

13 files changed

+30
-23
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,12 +860,12 @@ import ssh2 from 'ssh2'
860860

861861
const sql = postgres({
862862
...options,
863-
socket: ({ hostname, port }) => new Promise((resolve, reject) => {
863+
socket: ({ host: [host], port: [port] }) => new Promise((resolve, reject) => {
864864
const ssh = new ssh2.Client()
865865
ssh
866866
.on('error', reject)
867867
.on('ready', () =>
868-
ssh.forwardOut('127.0.0.1', 12345, hostname, port,
868+
ssh.forwardOut('127.0.0.1', 12345, host, port,
869869
(err, socket) => err ? reject(err) : resolve(socket)
870870
)
871871
)

cjs/src/connection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
350350
statementCount = 1
351351
lifeTimer.start()
352352
socket.on('data', data)
353-
socket.setKeepAlive && socket.setKeepAlive(true, 1000 * keep_alive)
353+
keep_alive != null && socket.setKeepAlive(true, 1000 * keep_alive)
354354
const s = StartupMessage()
355355
write(s)
356356
} catch (err) {
@@ -529,7 +529,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
529529
return
530530
}
531531

532-
while (sent.length && (query = sent.shift()) && (query.active = true) && query.cancelled)
532+
while (sent.length && (query = sent.shift()) && (query.active = true, query.cancelled))
533533
Connection(options).cancel(query.state, query.cancelled.resolve, query.cancelled.reject)
534534

535535
if (query)

cjs/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ function parseOptions(a, b) {
375375

376376
const env = process.env // eslint-disable-line
377377
, o = (typeof a === 'string' ? b : a) || {}
378-
, { url, multihost } = parseUrl(a, env)
378+
, { url, multihost } = parseUrl(a)
379379
, query = url.searchParams
380380
, host = o.hostname || o.host || multihost || url.hostname || env.PGHOST || 'localhost'
381381
, port = o.port || url.port || env.PGPORT || 5432

cjs/src/subscribe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = Subscribe;function Subscribe(postgres, options) {
2424
return
2525
stream = null
2626
state.pid = state.secret = undefined
27-
!ended && connected(await init(sql, slot, options.publications))
27+
connected(await init(sql, slot, options.publications))
2828
subscribers.forEach(event => event.forEach(({ onsubscribe }) => onsubscribe()))
2929
},
3030
no_subscribe: true
@@ -212,7 +212,7 @@ function parse(x, state, parsers, handle) {
212212
old && (i = tuples(x, old, key ? relation.keys : relation.columns, i += 3))
213213

214214
const row = {}
215-
i = tuples(x, row, relation.columns, i += 3)
215+
i = tuples(x, row, relation.columns, i + 3)
216216

217217
handle(row, {
218218
command: 'update',

deno/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,11 @@ const sql = postgres({ publications: 'alltables' })
605605

606606
const { unsubscribe } = await sql.subscribe(
607607
'insert:events',
608-
function(row, { command, relation, key, old }) => {
608+
(row, { command, relation, key, old }) => {
609609
// Callback function for each row change
610610
// tell about new event row over eg. websockets or do something else
611611
},
612-
function onsubscribe() => {
612+
() => {
613613
// Callback on initial connect and potential reconnects
614614
}
615615
)
@@ -856,12 +856,12 @@ import ssh2 from 'ssh2'
856856

857857
const sql = postgres({
858858
...options,
859-
socket: ({ hostname, port }) => new Promise((resolve, reject) => {
859+
socket: ({ host: [host], port: [port] }) => new Promise((resolve, reject) => {
860860
const ssh = new ssh2.Client()
861861
ssh
862862
.on('error', reject)
863863
.on('ready', () =>
864-
ssh.forwardOut('127.0.0.1', 12345, hostname, port,
864+
ssh.forwardOut('127.0.0.1', 12345, host, port,
865865
(err, socket) => err ? reject(err) : resolve(socket)
866866
)
867867
)
@@ -996,6 +996,7 @@ Postgres.js doesn't come with any migration solution since it's way out of scope
996996
997997
- https://github.com/porsager/postgres-shift
998998
- https://github.com/lukeed/ley
999+
- https://github.com/JAForbes/pgmg
9991000
10001001
## Thank you
10011002

deno/polyfills.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ export const net = {
2424
Socket() {
2525
let paused
2626
, resume
27+
, keepAlive
2728

2829
const socket = {
2930
error,
3031
success,
3132
readyState: 'open',
33+
setKeepAlive: x => {
34+
keepAlive = x
35+
socket.raw && socket.raw.setKeepAlive && socket.raw.setKeepAlive(x)
36+
},
3237
connect: (port, hostname) => {
3338
socket.raw = null
3439
socket.readyState = 'connecting'
@@ -72,7 +77,7 @@ export const net = {
7277
})
7378
return false
7479
},
75-
destroy: () => close(true),
80+
destroy: () => close(),
7681
end: (x) => {
7782
x && socket.write(x)
7883
close()
@@ -87,6 +92,7 @@ export const net = {
8792

8893
const encrypted = socket.encrypted
8994
socket.raw = raw
95+
keepAlive != null && raw.setKeepAlive(keepAlive)
9096
socket.readyState = 'open'
9197
socket.encrypted
9298
? call(socket.events.secureConnect)

deno/src/connection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
354354
statementCount = 1
355355
lifeTimer.start()
356356
socket.on('data', data)
357-
socket.setKeepAlive && socket
357+
keep_alive != null && socket.setKeepAlive(true)
358358
const s = StartupMessage()
359359
write(s)
360360
} catch (err) {
@@ -533,7 +533,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
533533
return
534534
}
535535

536-
while (sent.length && (query = sent.shift()) && (query.active = true) && query.cancelled)
536+
while (sent.length && (query = sent.shift()) && (query.active = true, query.cancelled))
537537
Connection(options).cancel(query.state, query.cancelled.resolve, query.cancelled.reject)
538538

539539
if (query)

deno/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ function parseOptions(a, b) {
376376

377377
const env = process.env // eslint-disable-line
378378
, o = (typeof a === 'string' ? b : a) || {}
379-
, { url, multihost } = parseUrl(a, env)
379+
, { url, multihost } = parseUrl(a)
380380
, query = url.searchParams
381381
, host = o.hostname || o.host || multihost || url.hostname || env.PGHOST || 'localhost'
382382
, port = o.port || url.port || env.PGPORT || 5432

deno/src/subscribe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function Subscribe(postgres, options) {
2525
return
2626
stream = null
2727
state.pid = state.secret = undefined
28-
!ended && connected(await init(sql, slot, options.publications))
28+
connected(await init(sql, slot, options.publications))
2929
subscribers.forEach(event => event.forEach(({ onsubscribe }) => onsubscribe()))
3030
},
3131
no_subscribe: true
@@ -213,7 +213,7 @@ function parse(x, state, parsers, handle) {
213213
old && (i = tuples(x, old, key ? relation.keys : relation.columns, i += 3))
214214

215215
const row = {}
216-
i = tuples(x, row, relation.columns, i += 3)
216+
i = tuples(x, row, relation.columns, i + 3)
217217

218218
handle(row, {
219219
command: 'update',

src/connection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
350350
statementCount = 1
351351
lifeTimer.start()
352352
socket.on('data', data)
353-
socket.setKeepAlive && socket.setKeepAlive(true, 1000 * keep_alive)
353+
keep_alive != null && socket.setKeepAlive(true, 1000 * keep_alive)
354354
const s = StartupMessage()
355355
write(s)
356356
} catch (err) {
@@ -529,7 +529,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
529529
return
530530
}
531531

532-
while (sent.length && (query = sent.shift()) && (query.active = true) && query.cancelled)
532+
while (sent.length && (query = sent.shift()) && (query.active = true, query.cancelled))
533533
Connection(options).cancel(query.state, query.cancelled.resolve, query.cancelled.reject)
534534

535535
if (query)

0 commit comments

Comments
 (0)