Skip to content

Commit 36a70df

Browse files
committed
Fix BigInt handling
1 parent 410cff7 commit 36a70df

File tree

10 files changed

+49
-37
lines changed

10 files changed

+49
-37
lines changed

cjs/src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ Object.assign(Postgres, {
3030
fromPascal,
3131
fromCamel,
3232
fromKebab,
33-
BigInt
33+
BigInt: {
34+
to: 20,
35+
from: [20],
36+
parse: x => BigInt(x), // eslint-disable-line
37+
serialize: x => x.toString()
38+
}
3439
})
3540

3641
module.exports = Postgres

cjs/src/subscribe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = Subscribe;function Subscribe(postgres, options) {
3131

3232
const fns = listeners.has(event)
3333
? listeners.get(event).add(fn)
34-
: listeners.set(event, new Set([fn]))
34+
: listeners.set(event, new Set([fn])).get(event)
3535

3636
const unsubscribe = () => {
3737
fns.delete(fn)
@@ -180,7 +180,7 @@ function parse(x, state, parsers, handle) {
180180
? {}
181181
: null
182182

183-
old && (i = tuples(x, old, key ? relation.keys : relation.columns, ++i))
183+
old && (i = tuples(x, old, key ? relation.keys : relation.columns, i += 3))
184184

185185
const row = {}
186186
i = tuples(x, row, relation.columns, i += 3)

cjs/src/types.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ const types = module.exports.types = {
3939
}
4040
}
4141

42-
const BigInt = module.exports.BigInt = {
43-
to: 1700,
44-
from: [20, 701, 1700],
45-
parse: x => BigInt(x), // eslint-disable-line
46-
serialize: x => x.toString()
47-
}
48-
4942
class NotTagged { then() { notTagged() } catch() { notTagged() } finally() { notTagged() }}
5043

5144
const Identifier = module.exports.Identifier = class Identifier extends NotTagged {
@@ -196,7 +189,7 @@ const inferType = module.exports.inferType = function inferType(x) {
196189
x instanceof Date ? 1184 :
197190
x instanceof Uint8Array ? 17 :
198191
(x === true || x === false) ? 16 :
199-
typeof x === 'bigint' ? 1700 :
192+
typeof x === 'bigint' ? 20 :
200193
Array.isArray(x) ? inferType(x[0]) :
201194
0
202195
)

cjs/tests/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,8 +1712,8 @@ t('subscribe', { timeout: 2 }, async() => {
17121712

17131713
const result = []
17141714

1715-
await sql.subscribe('*', (row, info) =>
1716-
result.push(info.command, row.name || row.id)
1715+
const { unsubscribe } = await sql.subscribe('*', (row, { command, old }) =>
1716+
result.push(command, row.name || row.id, old && old.name)
17171717
)
17181718

17191719
await sql`
@@ -1722,12 +1722,21 @@ t('subscribe', { timeout: 2 }, async() => {
17221722
name text
17231723
)
17241724
`
1725+
1726+
await sql`alter table test replica identity default`
17251727
await sql`insert into test (name) values ('Murray')`
17261728
await sql`update test set name = 'Rothbard'`
17271729
await sql`delete from test`
1730+
await sql`alter table test replica identity full`
1731+
await sql`insert into test (name) values ('Murray')`
1732+
await sql`update test set name = 'Rothbard'`
1733+
await sql`delete from test`
1734+
await delay(100)
1735+
await unsubscribe()
1736+
await sql`insert into test (name) values ('Oh noes')`
17281737
await delay(100)
17291738
return [
1730-
'insert,Murray,update,Rothbard,delete,1',
1739+
'insert,Murray,,update,Rothbard,,delete,1,,insert,Murray,,update,Rothbard,Murray,delete,Rothbard,',
17311740
result.join(','),
17321741
await sql`drop table test`,
17331742
await sql`drop publication alltables`,

deno/src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ Object.assign(Postgres, {
3131
fromPascal,
3232
fromCamel,
3333
fromKebab,
34-
BigInt
34+
BigInt: {
35+
to: 20,
36+
from: [20],
37+
parse: x => BigInt(x), // eslint-disable-line
38+
serialize: x => x.toString()
39+
}
3540
})
3641

3742
export default Postgres

deno/src/subscribe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function Subscribe(postgres, options) {
3232

3333
const fns = listeners.has(event)
3434
? listeners.get(event).add(fn)
35-
: listeners.set(event, new Set([fn]))
35+
: listeners.set(event, new Set([fn])).get(event)
3636

3737
const unsubscribe = () => {
3838
fns.delete(fn)
@@ -181,7 +181,7 @@ function parse(x, state, parsers, handle) {
181181
? {}
182182
: null
183183

184-
old && (i = tuples(x, old, key ? relation.keys : relation.columns, ++i))
184+
old && (i = tuples(x, old, key ? relation.keys : relation.columns, i += 3))
185185

186186
const row = {}
187187
i = tuples(x, row, relation.columns, i += 3)

deno/src/types.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ export const types = {
4040
}
4141
}
4242

43-
export const BigInt = {
44-
to: 1700,
45-
from: [20, 701, 1700],
46-
parse: x => BigInt(x), // eslint-disable-line
47-
serialize: x => x.toString()
48-
}
49-
5043
class NotTagged { then() { notTagged() } catch() { notTagged() } finally() { notTagged() }}
5144

5245
export class Identifier extends NotTagged {
@@ -197,7 +190,7 @@ export const inferType = function inferType(x) {
197190
x instanceof Date ? 1184 :
198191
x instanceof Uint8Array ? 17 :
199192
(x === true || x === false) ? 16 :
200-
typeof x === 'bigint' ? 1700 :
193+
typeof x === 'bigint' ? 20 :
201194
Array.isArray(x) ? inferType(x[0]) :
202195
0
203196
)

deno/tests/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,8 +1713,8 @@ t('subscribe', { timeout: 2 }, async() => {
17131713

17141714
const result = []
17151715

1716-
await sql.subscribe('*', (row, info) =>
1717-
result.push(info.command, row.name || row.id)
1716+
const { unsubscribe } = await sql.subscribe('*', (row, { command, old }) =>
1717+
result.push(command, row.name || row.id, old && old.name)
17181718
)
17191719

17201720
await sql`
@@ -1723,12 +1723,21 @@ t('subscribe', { timeout: 2 }, async() => {
17231723
name text
17241724
)
17251725
`
1726+
1727+
await sql`alter table test replica identity default`
17261728
await sql`insert into test (name) values ('Murray')`
17271729
await sql`update test set name = 'Rothbard'`
17281730
await sql`delete from test`
1731+
await sql`alter table test replica identity full`
1732+
await sql`insert into test (name) values ('Murray')`
1733+
await sql`update test set name = 'Rothbard'`
1734+
await sql`delete from test`
1735+
await delay(100)
1736+
await unsubscribe()
1737+
await sql`insert into test (name) values ('Oh noes')`
17291738
await delay(100)
17301739
return [
1731-
'insert,Murray,update,Rothbard,delete,1',
1740+
'insert,Murray,,update,Rothbard,,delete,1,,insert,Murray,,update,Rothbard,Murray,delete,Rothbard,',
17321741
result.join(','),
17331742
await sql`drop table test`,
17341743
await sql`drop publication alltables`,

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ Object.assign(Postgres, {
3030
fromPascal,
3131
fromCamel,
3232
fromKebab,
33-
BigInt
33+
BigInt: {
34+
to: 20,
35+
from: [20],
36+
parse: x => BigInt(x), // eslint-disable-line
37+
serialize: x => x.toString()
38+
}
3439
})
3540

3641
export default Postgres

src/types.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ export const types = {
3939
}
4040
}
4141

42-
export const BigInt = {
43-
to: 1700,
44-
from: [20, 701, 1700],
45-
parse: x => BigInt(x), // eslint-disable-line
46-
serialize: x => x.toString()
47-
}
48-
4942
class NotTagged { then() { notTagged() } catch() { notTagged() } finally() { notTagged() }}
5043

5144
export class Identifier extends NotTagged {
@@ -196,7 +189,7 @@ export const inferType = function inferType(x) {
196189
x instanceof Date ? 1184 :
197190
x instanceof Uint8Array ? 17 :
198191
(x === true || x === false) ? 16 :
199-
typeof x === 'bigint' ? 1700 :
192+
typeof x === 'bigint' ? 20 :
200193
Array.isArray(x) ? inferType(x[0]) :
201194
0
202195
)

0 commit comments

Comments
 (0)