Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into dont-close-cursor…
Browse files Browse the repository at this point in the history
…-twice
  • Loading branch information
alxndrsn committed Mar 14, 2024
2 parents 0867aad + 1190782 commit 59b1e07
Show file tree
Hide file tree
Showing 13 changed files with 559 additions and 522 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
- run: yarn install
- run: yarn lint
build:
needs: lint
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11
Expand All @@ -35,9 +34,16 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
matrix:
node: ['10', '12', '14', '16', '18']
os: [ubuntu-latest, windows-latest, macos-latest]
node:
- '10'
- '12'
- '14'
- '16'
- '18'
os:
- ubuntu-latest
name: Node.js ${{ matrix.node }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
env:
PGUSER: postgres
PGHOST: localhost
Expand All @@ -47,15 +53,18 @@ jobs:
SCRAM_TEST_PGUSER: scram_test
SCRAM_TEST_PGPASSWORD: test4scram
steps:
- name: Show OS
run: |
uname -a
- run: |
psql \
-c "SET password_encryption = 'scram-sha-256'" \
-c "CREATE ROLE scram_test LOGIN PASSWORD 'test4scram'"
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: yarn
Expand Down
100 changes: 0 additions & 100 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/pages/apis/client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ console.log('client has disconnected')
client.on('error', (err: Error) => void) => void
```

When the client is in the process of connecting, dispatching a query, or disconnecting it will catch and foward errors from the PostgreSQL server to the respective `client.connect` `client.query` or `client.end` promise; however, the client maintains a long-lived connection to the PostgreSQL back-end and due to network partitions, back-end crashes, fail-overs, etc the client can (and over a long enough time period _will_) eventually be disconnected while it is idle. To handle this you may want to attach an error listener to a client to catch errors. Here's a contrived example:
When the client is in the process of connecting, dispatching a query, or disconnecting it will catch and forward errors from the PostgreSQL server to the respective `client.connect` `client.query` or `client.end` promise; however, the client maintains a long-lived connection to the PostgreSQL back-end and due to network partitions, back-end crashes, fail-overs, etc the client can (and over a long enough time period _will_) eventually be disconnected while it is idle. To handle this you may want to attach an error listener to a client to catch errors. Here's a contrived example:

```js
const client = new pg.Client()
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/features/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Data Types

import { Alert } from '/components/alert.tsx'

PostgreSQL has a rich system of supported [data types](https://www.postgresql.org/docs/9.5/static/datatype.html). node-postgres does its best to support the most common data types out of the box and supplies an extensible type parser to allow for custom type serialization and parsing.
PostgreSQL has a rich system of supported [data types](https://www.postgresql.org/docs/current/datatype.html). node-postgres does its best to support the most common data types out of the box and supplies an extensible type parser to allow for custom type serialization and parsing.

## strings by default

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/guides/project-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ That's it. But now everywhere else in my application instead of requiring `pg` d
```js
// notice here I'm requiring my database adapter file
// and not requiring node-postgres directly
import * as db from '../db.js'
import * as db from '../db/index.js'

app.get('/:id', async (req, res, next) => {
const result = await db.query('SELECT * FROM users WHERE id = $1', [req.params.id])
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ If you or your company would like to sponsor node-postgres stop by [GitHub Spons

# Version compatibility

node-postgres strives to be compatible with all recent lts versions of node & the most recent "stable" version. At the time of this writing node-postgres is compatible with node 8.x, 10.x, 12.x and 14.x To use node >= 14.x you will need to install `pg@8.2.x` or later due to some internal stream changes on the node 14 branch. Dropping support for an old node lts version will always be considered a breaking change in node-postgres and will be done on _major_ version number changes only, and we will try to keep support for 8.x for as long as reasonably possible.
node-postgres strives to be compatible with all recent LTS versions of node & the most recent "stable" version. At the time of this writing node-postgres is compatible with node 8.x, 10.x, 12.x and 14.x To use node >= 14.x you will need to install `pg@8.2.x` or later due to some internal stream changes on the node 14 branch. Dropping support for an old node lts version will always be considered a breaking change in node-postgres and will be done on _major_ version number changes only, and we will try to keep support for 8.x for as long as reasonably possible.

## Getting started

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
"lint": "eslint '*/**/*.{js,ts,tsx}'"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.4.0",
"@typescript-eslint/parser": "^4.4.0",
"eslint": "^7.11.0",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-prettier": "^5.1.2",
"lerna": "^3.19.0",
"prettier": "2.8.8",
"prettier": "3.0.3",
"typescript": "^4.0.3"
},
"prettier": {
Expand Down
6 changes: 0 additions & 6 deletions packages/pg-connection-string/.travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion packages/pg-pool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pool.connect((err, client, done) => {
client.query('SELECT $1::text as name', ['pg-pool'], (err, res) => {
done()
if (err) {
return console.error('query error', e.message, e.stack)
return console.error('query error', err.message, err.stack)
}
console.log('hello from', res.rows[0].name)
})
Expand Down
52 changes: 42 additions & 10 deletions packages/pg-protocol/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,21 @@ export class DatabaseError extends Error implements NoticeOrError {
public file: string | undefined
public line: string | undefined
public routine: string | undefined
constructor(message: string, public readonly length: number, public readonly name: MessageName) {
constructor(
message: string,
public readonly length: number,
public readonly name: MessageName
) {
super(message)
}
}

export class CopyDataMessage {
public readonly name = 'copyData'
constructor(public readonly length: number, public readonly chunk: Buffer) {}
constructor(
public readonly length: number,
public readonly chunk: Buffer
) {}
}

export class CopyResponse {
Expand Down Expand Up @@ -148,15 +155,21 @@ export class Field {
export class RowDescriptionMessage {
public readonly name: MessageName = 'rowDescription'
public readonly fields: Field[]
constructor(public readonly length: number, public readonly fieldCount: number) {
constructor(
public readonly length: number,
public readonly fieldCount: number
) {
this.fields = new Array(this.fieldCount)
}
}

export class ParameterDescriptionMessage {
public readonly name: MessageName = 'parameterDescription'
public readonly dataTypeIDs: number[]
constructor(public readonly length: number, public readonly parameterCount: number) {
constructor(
public readonly length: number,
public readonly parameterCount: number
) {
this.dataTypeIDs = new Array(this.parameterCount)
}
}
Expand All @@ -172,12 +185,19 @@ export class ParameterStatusMessage {

export class AuthenticationMD5Password implements BackendMessage {
public readonly name: MessageName = 'authenticationMD5Password'
constructor(public readonly length: number, public readonly salt: Buffer) {}
constructor(
public readonly length: number,
public readonly salt: Buffer
) {}
}

export class BackendKeyDataMessage {
public readonly name: MessageName = 'backendKeyData'
constructor(public readonly length: number, public readonly processID: number, public readonly secretKey: number) {}
constructor(
public readonly length: number,
public readonly processID: number,
public readonly secretKey: number
) {}
}

export class NotificationResponseMessage {
Expand All @@ -192,24 +212,36 @@ export class NotificationResponseMessage {

export class ReadyForQueryMessage {
public readonly name: MessageName = 'readyForQuery'
constructor(public readonly length: number, public readonly status: string) {}
constructor(
public readonly length: number,
public readonly status: string
) {}
}

export class CommandCompleteMessage {
public readonly name: MessageName = 'commandComplete'
constructor(public readonly length: number, public readonly text: string) {}
constructor(
public readonly length: number,
public readonly text: string
) {}
}

export class DataRowMessage {
public readonly fieldCount: number
public readonly name: MessageName = 'dataRow'
constructor(public length: number, public fields: any[]) {
constructor(
public length: number,
public fields: any[]
) {
this.fieldCount = fields.length
}
}

export class NoticeMessage implements BackendMessage, NoticeOrError {
constructor(public readonly length: number, public readonly message: string | undefined) {}
constructor(
public readonly length: number,
public readonly message: string | undefined
) {}
public readonly name = 'notice'
public severity: string | undefined
public code: string | undefined
Expand Down
13 changes: 11 additions & 2 deletions packages/pg/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ function arrayString(val) {
result = result + 'NULL'
} else if (Array.isArray(val[i])) {
result = result + arrayString(val[i])
} else if (val[i] instanceof Buffer) {
result += '\\\\x' + val[i].toString('hex')
} else if (ArrayBuffer.isView(val[i])) {
var item = val[i]
if (!(item instanceof Buffer)) {
var buf = Buffer.from(item.buffer, item.byteOffset, item.byteLength)
if (buf.length === item.byteLength) {
item = buf
} else {
item = buf.slice(item.byteOffset, item.byteOffset + item.byteLength)
}
}
result += '\\\\x' + item.toString('hex')
} else {
result += escapeElement(prepareValue(val[i]))
}
Expand Down
7 changes: 7 additions & 0 deletions packages/pg/test/unit/utils-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ test('prepareValue: buffer array prepared properly', function () {
assert.strictEqual(out, '{\\\\xdead,\\\\xbeef}')
})

test('prepareValue: Uint8Array array prepared properly', function () {
var buffer1 = Uint8Array.from(Buffer.from('dead', 'hex'))
var buffer2 = Uint8Array.from(Buffer.from('beef', 'hex'))
var out = utils.prepareValue([buffer1, buffer2])
assert.strictEqual(out, '{\\\\xdead,\\\\xbeef}')
})

test('prepareValue: objects with complex toPostgres prepared properly', function () {
var buf = Buffer.from('zomgcustom!')
var customType = {
Expand Down
Loading

0 comments on commit 59b1e07

Please sign in to comment.