Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Dliu/pg browser #2

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bc922a2
Changes for websockets and cursors
daniel-liu-bitio Feb 22, 2022
86558d2
Add pg browser
daniel-liu-bitio Feb 28, 2022
a8d4e8f
Clean up webpack config file
daniel-liu-bitio Feb 28, 2022
b22bd76
Merge branch 'master' into dliu/pg-browser
daniel-liu-bitio Feb 28, 2022
5346973
Fix yarn.lock
daniel-liu-bitio Feb 28, 2022
ab56adf
Modify pg tests
daniel-liu-bitio Mar 1, 2022
e0506b7
Update packages/pg-cursor/index.js
daniel-liu-bitio Mar 1, 2022
096c823
Comment clarifications
daniel-liu-bitio Mar 1, 2022
7fae74e
Remove yarn.loc
daniel-liu-bitio Mar 1, 2022
aa6fcf4
Fix pg test defaults and comment clarifications
daniel-liu-bitio Mar 1, 2022
e3adc69
Update packages/pg-cursor/index.js
daniel-liu-bitio Mar 2, 2022
db91f5b
Merge branch 'dliu/pg-browser' of https://github.com/daniel-liu-bitio…
daniel-liu-bitio Mar 2, 2022
70880de
Add comment to connection.end
daniel-liu-bitio Mar 2, 2022
7b6c17b
Add back original IP/hostname functionality
daniel-liu-bitio Mar 2, 2022
ff56d38
Add 130-tests.js back into test suite
daniel-liu-bitio Mar 2, 2022
42e05cc
Restore original integration/connection/test-helper
daniel-liu-bitio Mar 2, 2022
b58ec5c
Change some devDependencies back to dependencies
daniel-liu-bitio Mar 2, 2022
62dde3f
Remove status message logging
daniel-liu-bitio Mar 3, 2022
b55e00d
Fix stream placeholder logic
daniel-liu-bitio Mar 3, 2022
8462ab8
Send closing code + status on connection end
daniel-liu-bitio Mar 7, 2022
2f4a80d
Remove commented out original tests
daniel-liu-bitio Mar 9, 2022
f05b81c
Add simple performance test file
daniel-liu-bitio Mar 14, 2022
b7eae9d
Add cursor -> select example
daniel-liu-bitio Mar 14, 2022
d622ec7
Add yarn.lock
daniel-liu-bitio Mar 14, 2022
7b10504
Add messages.d.ts
daniel-liu-bitio Mar 14, 2022
e915f5d
recent
daniel-liu-bitio Mar 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Changes for websockets and cursors
  • Loading branch information
daniel-liu-bitio committed Feb 22, 2022
commit bc922a2e2e9d7ea936397570c770bc08b3edd6c8
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.4",
"lerna": "^3.19.0",
"lerna": "^4.0.0",
"prettier": "2.1.2",
"typescript": "^4.0.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/pg-connection-string/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"chai": "^4.1.1",
"coveralls": "^3.0.4",
"istanbul": "^0.4.5",
"mocha": "^7.1.2"
"mocha": "^9.2.0"
},
"files": [
"index.js",
Expand Down
56 changes: 53 additions & 3 deletions packages/pg-cursor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Cursor extends EventEmitter {
this._portal = null
this._ifNoData = this._ifNoData.bind(this)
this._rowDescription = this._rowDescription.bind(this)
this.moveAllAndClosing = false
}

_ifNoData() {
Expand All @@ -42,7 +43,8 @@ class Cursor extends EventEmitter {
submit(connection) {
this.state = 'submitted'
this.connection = connection
this._portal = 'C_' + nextUniqueID++
// the portal name must start with a lowercase c, for some reason
this._portal = 'c_' + nextUniqueID++

const con = connection

Expand Down Expand Up @@ -86,6 +88,8 @@ class Cursor extends EventEmitter {
}

_closePortal() {
if (this.state === 'done') return

// because we opened a named portal to stream results
// we need to close the same named portal. Leaving a named portal
// open can lock tables for modification if inside a transaction.
Expand All @@ -97,6 +101,8 @@ class Cursor extends EventEmitter {
if (this.state !== 'error') {
this.connection.sync()
}

this.state = 'done'
}

handleRowDescription(msg) {
Expand Down Expand Up @@ -129,7 +135,9 @@ class Cursor extends EventEmitter {

handleCommandComplete(msg) {
this._result.addCommandComplete(msg)
this._closePortal()
if (!this.moveAllAndClosing) {
this._closePortal()
}
}

handlePortalSuspended() {
Expand Down Expand Up @@ -198,6 +206,49 @@ class Cursor extends EventEmitter {
this.connection.end()
}

_promisifiedQuery(text) {
return new Promise((resolve, reject) => {
try {
var res = this.connection.query(text)
resolve(res)
} catch (e) {
reject(e)
}
})
}

moveAllAndClose(cb) {
this.moveAllAndClosing = true
if (this.state === 'done' || this.state == 'error') {
return this.close(cb)
}
return this._promisifiedQuery("MOVE ALL FROM " + this._portal).then(() => {
this._close_checkFinished(cb)
})
}

_close_checkFinished(cb) {
this._closePortal()
// try to delay the callback until portal is finished closing
// (this means a closeComplete followed by a readyForQuery)
// (it's possible to have a readyForQuery without a closeComplete if called from moveAllAndClose)
var finishedClosing = false
this.connection.once('closeComplete', function () {
finishedClosing = true
})

const _handleReadyForQueryInClose = () => {
if (finishedClosing) {
cb()
this.moveAllAndClosing = false
this.connection.removeListener('readyForQuery', _handleReadyForQueryInClose)
}
}

this.connection.on('readyForQuery', _handleReadyForQueryInClose)
return
}

close(cb) {
let promise

Expand All @@ -213,7 +264,6 @@ class Cursor extends EventEmitter {
}

this._closePortal()
this.state = 'done'
this.connection.once('readyForQuery', function () {
cb()
})
Expand Down
2 changes: 1 addition & 1 deletion packages/pg-cursor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Brian M. Carlson",
"license": "MIT",
"devDependencies": {
"mocha": "^7.1.2",
"mocha": "^9.2.0",
"pg": "^8.7.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/pg-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Pool extends EventEmitter {
this.options.maxUses = this.options.maxUses || Infinity
this.options.allowExitOnIdle = this.options.allowExitOnIdle || false
this.log = this.options.log || function () {}
this.Client = this.options.Client || Client || require('pg').Client
this.Client = this.options.Client || Client || require('../pg/lib/index.js').Client
this.Promise = this.options.Promise || global.Promise

if (typeof this.options.idleTimeoutMillis === 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion packages/pg-pool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"co": "4.6.0",
"expect.js": "0.3.1",
"lodash": "^4.17.11",
"mocha": "^7.1.2",
"mocha": "^9.2.0",
"pg-cursor": "^1.3.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/pg-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@types/node": "^12.12.21",
"chai": "^4.2.0",
"chunky": "^0.0.0",
"mocha": "^7.1.2",
"mocha": "^9.2.0",
"ts-node": "^8.5.4",
"typescript": "^4.0.3"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/pg-query-stream/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"@types/mocha": "^8.0.3",
"@types/node": "^14.0.0",
"@types/pg": "^7.14.5",
"JSONStream": "~0.7.1",
"concat-stream": "~1.0.1",
"eslint-plugin-promise": "^3.5.0",
"mocha": "^7.1.2",
"JSONStream": "~0.7.1",
"mocha": "^9.2.0",
"pg": "^8.7.1",
"stream-spec": "~0.3.5",
"stream-tester": "0.0.5",
Expand Down
23 changes: 23 additions & 0 deletions packages/pg/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ test-connection:
@echo "***Testing connection***"
@node script/create-test-tables.js $(params)

test-unit-connection: test-connection
@find test/unit/connection -name "*-tests.js" | $(node-command)

test-missing-native:
@echo "***Testing optional native install***"
@rm -rf node_modules/pg-native
Expand All @@ -53,6 +56,26 @@ test-integration: test-connection
@echo "***Testing Pure Javascript***"
@find test/integration -name "*-tests.js" | $(node-command)

test-integration-client: test-connection
@echo "***Testing integration for client***"
@find test/integration/client -name "*-tests.js" | $(node-command)

test-integration-connection: test-connection
@echo "***Testing integration for connection***"
@find test/integration/connection -name "*-tests.js" | $(node-command)

test-integration-connection-pool: test-connection
@echo "***Testing integration for connection***"
@find test/integration/connection-pool -name "*-tests.js" | $(node-command)

test-gh-issues: test-connection
@echo "***Testing gh-issues***"
@find test/integration/gh-issues -name "*-tests.js" | $(node-command)

test-unit-client: test-connection
@echo "***Testing integration for client***"
@find test/unit/client -name "*-tests.js" | $(node-command)

test-binary: test-connection
@echo "***Testing Pure Javascript (binary)***"
@find test/integration -name "*-tests.js" | $(node-command) binary
Expand Down
Empty file added packages/pg/bundle.js
Empty file.
Loading