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 all commits
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
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@
"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"
"typescript": "^4.0.3",
"webpack-cli": "^4.9.2"
},
"prettier": {
"semi": false,
"printWidth": 120,
"arrowParens": "always",
"trailingComma": "es5",
"singleQuote": true
},
"dependencies": {
"is-ip": "^4.0.0",
"pg": "^8.7.3",
"websocket-stream": "^5.5.2"
}
}
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
51 changes: 49 additions & 2 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 @@ -133,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 @@ -202,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()
// delay the callback until portal is finished closing
// (this means a closeComplete followed by a readyForQuery)
// (when moveAllAndClose calls closePortal, client will receive a readyForQuery generated by "MOVE ALL" simple query before receiving a closeComplete and a subsequent readyForQuery)
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 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.1",
"pg": "^8.7.3"
},
"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 @@ -86,7 +86,7 @@ class Pool extends EventEmitter {
this.options.allowExitOnIdle = this.options.allowExitOnIdle || false
this.options.maxLifetimeSeconds = this.options.maxLifetimeSeconds || 0
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
162 changes: 162 additions & 0 deletions packages/pg-protocol/dist/messages.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/// <reference types="node" />
export declare type Mode = 'text' | 'binary';
export declare type MessageName = 'parseComplete' | 'bindComplete' | 'closeComplete' | 'noData' | 'portalSuspended' | 'replicationStart' | 'emptyQuery' | 'copyDone' | 'copyData' | 'rowDescription' | 'parameterDescription' | 'parameterStatus' | 'backendKeyData' | 'notification' | 'readyForQuery' | 'commandComplete' | 'dataRow' | 'copyInResponse' | 'copyOutResponse' | 'authenticationOk' | 'authenticationMD5Password' | 'authenticationCleartextPassword' | 'authenticationSASL' | 'authenticationSASLContinue' | 'authenticationSASLFinal' | 'error' | 'notice';
export interface BackendMessage {
name: MessageName;
length: number;
}
export declare const parseComplete: BackendMessage;
export declare const bindComplete: BackendMessage;
export declare const closeComplete: BackendMessage;
export declare const noData: BackendMessage;
export declare const portalSuspended: BackendMessage;
export declare const replicationStart: BackendMessage;
export declare const emptyQuery: BackendMessage;
export declare const copyDone: BackendMessage;
interface NoticeOrError {
message: string | undefined;
severity: string | undefined;
code: string | undefined;
detail: string | undefined;
hint: string | undefined;
position: string | undefined;
internalPosition: string | undefined;
internalQuery: string | undefined;
where: string | undefined;
schema: string | undefined;
table: string | undefined;
column: string | undefined;
dataType: string | undefined;
constraint: string | undefined;
file: string | undefined;
line: string | undefined;
routine: string | undefined;
}
export declare class DatabaseError extends Error implements NoticeOrError {
readonly length: number;
readonly name: MessageName;
severity: string | undefined;
code: string | undefined;
detail: string | undefined;
hint: string | undefined;
position: string | undefined;
internalPosition: string | undefined;
internalQuery: string | undefined;
where: string | undefined;
schema: string | undefined;
table: string | undefined;
column: string | undefined;
dataType: string | undefined;
constraint: string | undefined;
file: string | undefined;
line: string | undefined;
routine: string | undefined;
constructor(message: string, length: number, name: MessageName);
}
export declare class CopyDataMessage {
readonly length: number;
readonly chunk: Buffer;
readonly name = "copyData";
constructor(length: number, chunk: Buffer);
}
export declare class CopyResponse {
readonly length: number;
readonly name: MessageName;
readonly binary: boolean;
readonly columnTypes: number[];
constructor(length: number, name: MessageName, binary: boolean, columnCount: number);
}
export declare class Field {
readonly name: string;
readonly tableID: number;
readonly columnID: number;
readonly dataTypeID: number;
readonly dataTypeSize: number;
readonly dataTypeModifier: number;
readonly format: Mode;
constructor(name: string, tableID: number, columnID: number, dataTypeID: number, dataTypeSize: number, dataTypeModifier: number, format: Mode);
}
export declare class RowDescriptionMessage {
readonly length: number;
readonly fieldCount: number;
readonly name: MessageName;
readonly fields: Field[];
constructor(length: number, fieldCount: number);
}
export declare class ParameterDescriptionMessage {
readonly length: number;
readonly parameterCount: number;
readonly name: MessageName;
readonly dataTypeIDs: number[];
constructor(length: number, parameterCount: number);
}
export declare class ParameterStatusMessage {
readonly length: number;
readonly parameterName: string;
readonly parameterValue: string;
readonly name: MessageName;
constructor(length: number, parameterName: string, parameterValue: string);
}
export declare class AuthenticationMD5Password implements BackendMessage {
readonly length: number;
readonly salt: Buffer;
readonly name: MessageName;
constructor(length: number, salt: Buffer);
}
export declare class BackendKeyDataMessage {
readonly length: number;
readonly processID: number;
readonly secretKey: number;
readonly name: MessageName;
constructor(length: number, processID: number, secretKey: number);
}
export declare class NotificationResponseMessage {
readonly length: number;
readonly processId: number;
readonly channel: string;
readonly payload: string;
readonly name: MessageName;
constructor(length: number, processId: number, channel: string, payload: string);
}
export declare class ReadyForQueryMessage {
readonly length: number;
readonly status: string;
readonly name: MessageName;
constructor(length: number, status: string);
}
export declare class CommandCompleteMessage {
readonly length: number;
readonly text: string;
readonly name: MessageName;
constructor(length: number, text: string);
}
export declare class DataRowMessage {
length: number;
fields: any[];
readonly fieldCount: number;
readonly name: MessageName;
constructor(length: number, fields: any[]);
}
export declare class NoticeMessage implements BackendMessage, NoticeOrError {
readonly length: number;
readonly message: string | undefined;
constructor(length: number, message: string | undefined);
readonly name = "notice";
severity: string | undefined;
code: string | undefined;
detail: string | undefined;
hint: string | undefined;
position: string | undefined;
internalPosition: string | undefined;
internalQuery: string | undefined;
where: string | undefined;
schema: string | undefined;
table: string | undefined;
column: string | undefined;
dataType: string | undefined;
constraint: string | undefined;
file: string | undefined;
line: string | undefined;
routine: string | undefined;
}
export {};
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
3 changes: 3 additions & 0 deletions packages/pg-protocol/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
},
"include": [
"src/**/*"
],
"exclude": [
"dist"
]
}
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.3",
"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