Skip to content

Commit f5ec5a0

Browse files
committed
build
1 parent f347061 commit f5ec5a0

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

cjs/src/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function Postgres(a, b) {
8383

8484
return sql
8585

86-
function Sql(handler, instant) {
86+
function Sql(handler) {
8787
handler.debug = options.debug
8888

8989
Object.entries(options.types).reduce((acc, [name, type]) => {
@@ -112,7 +112,6 @@ function Postgres(a, b) {
112112
: typeof strings === 'string' && !args.length
113113
? new Identifier(options.transform.column.to ? options.transform.column.to(strings) : strings)
114114
: new Builder(strings, args)
115-
instant && query instanceof Query && query.execute()
116115
return query
117116
}
118117

@@ -123,7 +122,6 @@ function Postgres(a, b) {
123122
...options,
124123
simple: 'simple' in options ? options.simple : args.length === 0
125124
})
126-
instant && query.execute()
127125
return query
128126
}
129127

@@ -141,7 +139,6 @@ function Postgres(a, b) {
141139
...options,
142140
simple: 'simple' in options ? options.simple : args.length === 0
143141
})
144-
instant && query.execute()
145142
return query
146143
}
147144
}

cjs/src/subscribe.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,15 @@ module.exports = Subscribe;function Subscribe(postgres, options) {
9797
}
9898

9999
stream.on('data', data)
100-
stream.on('error', sql.close)
100+
stream.on('error', error)
101101
stream.on('close', sql.close)
102102

103103
return { stream, state: xs.state }
104104

105+
function error(e) {
106+
console.error('Unexpected error during logical streaming - reconnecting', e)
107+
}
108+
105109
function data(x) {
106110
if (x[0] === 0x77)
107111
parse(x.subarray(25), state, sql.options.parsers, handle, options.transform)
@@ -191,7 +195,7 @@ function parse(x, state, parsers, handle, transform) {
191195
i += 4
192196
const key = x[i] === 75
193197
handle(key || x[i] === 79
194-
? tuples(x, key ? relation.keys : relation.columns, i += 3, transform).row
198+
? tuples(x, relation.columns, i += 3, transform).row
195199
: null
196200
, {
197201
command: 'delete',
@@ -205,7 +209,7 @@ function parse(x, state, parsers, handle, transform) {
205209
i += 4
206210
const key = x[i] === 75
207211
const xs = key || x[i] === 79
208-
? tuples(x, key ? relation.keys : relation.columns, i += 3, transform)
212+
? tuples(x, relation.columns, i += 3, transform)
209213
: null
210214

211215
xs && (i = xs.i)

cjs/tests/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,9 +1989,9 @@ t('subscribe', { timeout: 2 }, async() => {
19891989

19901990
const result = []
19911991

1992-
const { unsubscribe } = await sql.subscribe('*', (row, { command, old }) =>
1993-
result.push(command, row.name || row.id, old && old.name)
1994-
)
1992+
const { unsubscribe } = await sql.subscribe('*', (row, { command, old }) => {
1993+
result.push(command, row.name, row.id, old && old.name, old && old.id)
1994+
})
19951995

19961996
await sql`
19971997
create table test (
@@ -2003,6 +2003,7 @@ t('subscribe', { timeout: 2 }, async() => {
20032003
await sql`alter table test replica identity default`
20042004
await sql`insert into test (name) values ('Murray')`
20052005
await sql`update test set name = 'Rothbard'`
2006+
await sql`update test set id = 2`
20062007
await sql`delete from test`
20072008
await sql`alter table test replica identity full`
20082009
await sql`insert into test (name) values ('Murray')`
@@ -2013,7 +2014,7 @@ t('subscribe', { timeout: 2 }, async() => {
20132014
await sql`insert into test (name) values ('Oh noes')`
20142015
await delay(10)
20152016
return [
2016-
'insert,Murray,,update,Rothbard,,delete,1,,insert,Murray,,update,Rothbard,Murray,delete,Rothbard,',
2017+
'insert,Murray,1,,,update,Rothbard,1,,,update,Rothbard,2,,1,delete,,2,,,insert,Murray,2,,,update,Rothbard,2,Murray,2,delete,Rothbard,2,,',
20172018
result.join(','),
20182019
await sql`drop table test`,
20192020
await sql`drop publication alltables`,
@@ -2139,7 +2140,7 @@ t('Cancel queued query', async() => {
21392140
const query = sql`select pg_sleep(2) as nej`
21402141
const tx = sql.begin(sql => (
21412142
query.cancel(),
2142-
sql`select pg_sleep(0.1) as hej, 'hejsa'`
2143+
sql`select pg_sleep(0.5) as hej, 'hejsa'`
21432144
))
21442145
const error = await query.catch(x => x)
21452146
await tx

deno/src/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function Postgres(a, b) {
8484

8585
return sql
8686

87-
function Sql(handler, instant) {
87+
function Sql(handler) {
8888
handler.debug = options.debug
8989

9090
Object.entries(options.types).reduce((acc, [name, type]) => {
@@ -113,7 +113,6 @@ function Postgres(a, b) {
113113
: typeof strings === 'string' && !args.length
114114
? new Identifier(options.transform.column.to ? options.transform.column.to(strings) : strings)
115115
: new Builder(strings, args)
116-
instant && query instanceof Query && query.execute()
117116
return query
118117
}
119118

@@ -124,7 +123,6 @@ function Postgres(a, b) {
124123
...options,
125124
simple: 'simple' in options ? options.simple : args.length === 0
126125
})
127-
instant && query.execute()
128126
return query
129127
}
130128

@@ -142,7 +140,6 @@ function Postgres(a, b) {
142140
...options,
143141
simple: 'simple' in options ? options.simple : args.length === 0
144142
})
145-
instant && query.execute()
146143
return query
147144
}
148145
}

deno/src/subscribe.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ export default function Subscribe(postgres, options) {
9898
}
9999

100100
stream.on('data', data)
101-
stream.on('error', sql.close)
101+
stream.on('error', error)
102102
stream.on('close', sql.close)
103103

104104
return { stream, state: xs.state }
105105

106+
function error(e) {
107+
console.error('Unexpected error during logical streaming - reconnecting', e)
108+
}
109+
106110
function data(x) {
107111
if (x[0] === 0x77)
108112
parse(x.subarray(25), state, sql.options.parsers, handle, options.transform)
@@ -192,7 +196,7 @@ function parse(x, state, parsers, handle, transform) {
192196
i += 4
193197
const key = x[i] === 75
194198
handle(key || x[i] === 79
195-
? tuples(x, key ? relation.keys : relation.columns, i += 3, transform).row
199+
? tuples(x, relation.columns, i += 3, transform).row
196200
: null
197201
, {
198202
command: 'delete',
@@ -206,7 +210,7 @@ function parse(x, state, parsers, handle, transform) {
206210
i += 4
207211
const key = x[i] === 75
208212
const xs = key || x[i] === 79
209-
? tuples(x, key ? relation.keys : relation.columns, i += 3, transform)
213+
? tuples(x, relation.columns, i += 3, transform)
210214
: null
211215

212216
xs && (i = xs.i)

deno/tests/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,9 +1991,9 @@ t('subscribe', { timeout: 2 }, async() => {
19911991

19921992
const result = []
19931993

1994-
const { unsubscribe } = await sql.subscribe('*', (row, { command, old }) =>
1995-
result.push(command, row.name || row.id, old && old.name)
1996-
)
1994+
const { unsubscribe } = await sql.subscribe('*', (row, { command, old }) => {
1995+
result.push(command, row.name, row.id, old && old.name, old && old.id)
1996+
})
19971997

19981998
await sql`
19991999
create table test (
@@ -2005,6 +2005,7 @@ t('subscribe', { timeout: 2 }, async() => {
20052005
await sql`alter table test replica identity default`
20062006
await sql`insert into test (name) values ('Murray')`
20072007
await sql`update test set name = 'Rothbard'`
2008+
await sql`update test set id = 2`
20082009
await sql`delete from test`
20092010
await sql`alter table test replica identity full`
20102011
await sql`insert into test (name) values ('Murray')`
@@ -2015,7 +2016,7 @@ t('subscribe', { timeout: 2 }, async() => {
20152016
await sql`insert into test (name) values ('Oh noes')`
20162017
await delay(10)
20172018
return [
2018-
'insert,Murray,,update,Rothbard,,delete,1,,insert,Murray,,update,Rothbard,Murray,delete,Rothbard,',
2019+
'insert,Murray,1,,,update,Rothbard,1,,,update,Rothbard,2,,1,delete,,2,,,insert,Murray,2,,,update,Rothbard,2,Murray,2,delete,Rothbard,2,,',
20192020
result.join(','),
20202021
await sql`drop table test`,
20212022
await sql`drop publication alltables`,
@@ -2141,7 +2142,7 @@ t('Cancel queued query', async() => {
21412142
const query = sql`select pg_sleep(2) as nej`
21422143
const tx = sql.begin(sql => (
21432144
query.cancel(),
2144-
sql`select pg_sleep(0.1) as hej, 'hejsa'`
2145+
sql`select pg_sleep(0.5) as hej, 'hejsa'`
21452146
))
21462147
const error = await query.catch(x => x)
21472148
await tx

0 commit comments

Comments
 (0)