Skip to content

Commit 880a98f

Browse files
committed
doc fixes
1 parent 76e1396 commit 880a98f

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

README.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,11 @@ Using a file for a query is also supported with optional parameters to use if th
426426
const result = await sql.file('query.sql', ['Murray', 68])
427427
```
428428
429-
### Rows as Streams
429+
### Copy to/from as Streams
430430
431-
Postgres.js supports [`copy ...`](https://www.postgresql.org/docs/14/sql-copy.html) queries, which are exposed as [Node.js streams](https://nodejs.org/api/stream.html).
431+
Postgres.js supports [`COPY ...`](https://www.postgresql.org/docs/14/sql-copy.html) queries, which are exposed as [Node.js streams](https://nodejs.org/api/stream.html).
432432
433-
> **NOTE** This is a low-level API which does not provide any type safety. To make this work, you must match your [`copy query` parameters](https://www.postgresql.org/docs/14/sql-copy.html) correctly to your [Node.js stream read or write](https://nodejs.org/api/stream.html) code. Ensure [Node.js stream backpressure](https://nodejs.org/en/docs/guides/backpressuring-in-streams/) is handled correctly to avoid memory exhaustion.
434-
435-
#### ```await sql`copy ... from stdin` -> Writable```
433+
#### ```await sql`copy ... from stdin`.writable() -> Writable```
436434
437435
```js
438436
const { pipeline } = require('stream/promises')
@@ -447,32 +445,33 @@ const query = await sql`copy users (name, age) from stdin`.writable()
447445
await pipeline(userStream, query);
448446
```
449447
450-
#### ```await sql`copy ... to stdin` -> Readable```
448+
#### ```await sql`copy ... to stdout`.readable() -> Readable```
451449
452-
##### stream pipeline
450+
##### Using Stream Pipeline
453451
```js
454452
const { pipeline } = require('stream/promises')
455453
const { createWriteStream } = require('fs')
456454

457-
const readableStream = await sql`copy users (name, age) to stdin`.readable()
455+
const readableStream = await sql`copy users (name, age) to stdout`.readable()
458456
await pipeline(readableStream, createWriteStream('output.tsv'))
459457
// output.tsv content: `Murray\t68\nWalter\t80\n`
460458
```
461459
462-
##### for await...of
460+
##### Using `for await...of`
463461
```js
464462
const readableStream = await sql`
465463
copy (
466464
select name, age
467465
from users
468466
where age = 68
469-
) to stdin
467+
) to stdout
470468
`.readable()
471469
for await (const chunk of readableStream) {
472470
// chunk.toString() === `Murray\t68\n`
473471
}
474472
```
475473
474+
> **NOTE** This is a low-level API which does not provide any type safety. To make this work, you must match your [`copy query` parameters](https://www.postgresql.org/docs/14/sql-copy.html) correctly to your [Node.js stream read or write](https://nodejs.org/api/stream.html) code. Ensure [Node.js stream backpressure](https://nodejs.org/en/docs/guides/backpressuring-in-streams/) is handled correctly to avoid memory exhaustion.
476475
477476
### Canceling Queries in Progress
478477

src/subscribe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function parse(x, state, parsers, handle) {
212212
old && (i = tuples(x, old, key ? relation.keys : relation.columns, i += 3))
213213

214214
const row = {}
215-
i = tuples(x, row, relation.columns, i + 3)
215+
tuples(x, row, relation.columns, i + 3)
216216

217217
handle(row, {
218218
command: 'update',

0 commit comments

Comments
 (0)