Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Jun 25, 2023
1 parent f347061 commit f5ec5a0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
5 changes: 1 addition & 4 deletions cjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function Postgres(a, b) {

return sql

function Sql(handler, instant) {
function Sql(handler) {
handler.debug = options.debug

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

Expand All @@ -123,7 +122,6 @@ function Postgres(a, b) {
...options,
simple: 'simple' in options ? options.simple : args.length === 0
})
instant && query.execute()
return query
}

Expand All @@ -141,7 +139,6 @@ function Postgres(a, b) {
...options,
simple: 'simple' in options ? options.simple : args.length === 0
})
instant && query.execute()
return query
}
}
Expand Down
10 changes: 7 additions & 3 deletions cjs/src/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,15 @@ module.exports = Subscribe;function Subscribe(postgres, options) {
}

stream.on('data', data)
stream.on('error', sql.close)
stream.on('error', error)
stream.on('close', sql.close)

return { stream, state: xs.state }

function error(e) {
console.error('Unexpected error during logical streaming - reconnecting', e)
}

function data(x) {
if (x[0] === 0x77)
parse(x.subarray(25), state, sql.options.parsers, handle, options.transform)
Expand Down Expand Up @@ -191,7 +195,7 @@ function parse(x, state, parsers, handle, transform) {
i += 4
const key = x[i] === 75
handle(key || x[i] === 79
? tuples(x, key ? relation.keys : relation.columns, i += 3, transform).row
? tuples(x, relation.columns, i += 3, transform).row
: null
, {
command: 'delete',
Expand All @@ -205,7 +209,7 @@ function parse(x, state, parsers, handle, transform) {
i += 4
const key = x[i] === 75
const xs = key || x[i] === 79
? tuples(x, key ? relation.keys : relation.columns, i += 3, transform)
? tuples(x, relation.columns, i += 3, transform)
: null

xs && (i = xs.i)
Expand Down
11 changes: 6 additions & 5 deletions cjs/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1989,9 +1989,9 @@ t('subscribe', { timeout: 2 }, async() => {

const result = []

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

await sql`
create table test (
Expand All @@ -2003,6 +2003,7 @@ t('subscribe', { timeout: 2 }, async() => {
await sql`alter table test replica identity default`
await sql`insert into test (name) values ('Murray')`
await sql`update test set name = 'Rothbard'`
await sql`update test set id = 2`
await sql`delete from test`
await sql`alter table test replica identity full`
await sql`insert into test (name) values ('Murray')`
Expand All @@ -2013,7 +2014,7 @@ t('subscribe', { timeout: 2 }, async() => {
await sql`insert into test (name) values ('Oh noes')`
await delay(10)
return [
'insert,Murray,,update,Rothbard,,delete,1,,insert,Murray,,update,Rothbard,Murray,delete,Rothbard,',
'insert,Murray,1,,,update,Rothbard,1,,,update,Rothbard,2,,1,delete,,2,,,insert,Murray,2,,,update,Rothbard,2,Murray,2,delete,Rothbard,2,,',
result.join(','),
await sql`drop table test`,
await sql`drop publication alltables`,
Expand Down Expand Up @@ -2139,7 +2140,7 @@ t('Cancel queued query', async() => {
const query = sql`select pg_sleep(2) as nej`
const tx = sql.begin(sql => (
query.cancel(),
sql`select pg_sleep(0.1) as hej, 'hejsa'`
sql`select pg_sleep(0.5) as hej, 'hejsa'`
))
const error = await query.catch(x => x)
await tx
Expand Down
5 changes: 1 addition & 4 deletions deno/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function Postgres(a, b) {

return sql

function Sql(handler, instant) {
function Sql(handler) {
handler.debug = options.debug

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

Expand All @@ -124,7 +123,6 @@ function Postgres(a, b) {
...options,
simple: 'simple' in options ? options.simple : args.length === 0
})
instant && query.execute()
return query
}

Expand All @@ -142,7 +140,6 @@ function Postgres(a, b) {
...options,
simple: 'simple' in options ? options.simple : args.length === 0
})
instant && query.execute()
return query
}
}
Expand Down
10 changes: 7 additions & 3 deletions deno/src/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ export default function Subscribe(postgres, options) {
}

stream.on('data', data)
stream.on('error', sql.close)
stream.on('error', error)
stream.on('close', sql.close)

return { stream, state: xs.state }

function error(e) {
console.error('Unexpected error during logical streaming - reconnecting', e)
}

function data(x) {
if (x[0] === 0x77)
parse(x.subarray(25), state, sql.options.parsers, handle, options.transform)
Expand Down Expand Up @@ -192,7 +196,7 @@ function parse(x, state, parsers, handle, transform) {
i += 4
const key = x[i] === 75
handle(key || x[i] === 79
? tuples(x, key ? relation.keys : relation.columns, i += 3, transform).row
? tuples(x, relation.columns, i += 3, transform).row
: null
, {
command: 'delete',
Expand All @@ -206,7 +210,7 @@ function parse(x, state, parsers, handle, transform) {
i += 4
const key = x[i] === 75
const xs = key || x[i] === 79
? tuples(x, key ? relation.keys : relation.columns, i += 3, transform)
? tuples(x, relation.columns, i += 3, transform)
: null

xs && (i = xs.i)
Expand Down
11 changes: 6 additions & 5 deletions deno/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1991,9 +1991,9 @@ t('subscribe', { timeout: 2 }, async() => {

const result = []

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

await sql`
create table test (
Expand All @@ -2005,6 +2005,7 @@ t('subscribe', { timeout: 2 }, async() => {
await sql`alter table test replica identity default`
await sql`insert into test (name) values ('Murray')`
await sql`update test set name = 'Rothbard'`
await sql`update test set id = 2`
await sql`delete from test`
await sql`alter table test replica identity full`
await sql`insert into test (name) values ('Murray')`
Expand All @@ -2015,7 +2016,7 @@ t('subscribe', { timeout: 2 }, async() => {
await sql`insert into test (name) values ('Oh noes')`
await delay(10)
return [
'insert,Murray,,update,Rothbard,,delete,1,,insert,Murray,,update,Rothbard,Murray,delete,Rothbard,',
'insert,Murray,1,,,update,Rothbard,1,,,update,Rothbard,2,,1,delete,,2,,,insert,Murray,2,,,update,Rothbard,2,Murray,2,delete,Rothbard,2,,',
result.join(','),
await sql`drop table test`,
await sql`drop publication alltables`,
Expand Down Expand Up @@ -2141,7 +2142,7 @@ t('Cancel queued query', async() => {
const query = sql`select pg_sleep(2) as nej`
const tx = sql.begin(sql => (
query.cancel(),
sql`select pg_sleep(0.1) as hej, 'hejsa'`
sql`select pg_sleep(0.5) as hej, 'hejsa'`
))
const error = await query.catch(x => x)
await tx
Expand Down

0 comments on commit f5ec5a0

Please sign in to comment.