Skip to content

Commit ee1b482

Browse files
committed
README.md: Document fieldReader meta fields (_fieldIndex, _fieldCount, _fieldLength)
1 parent 74c74cd commit ee1b482

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

README.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,23 @@ the Parser will push rows with the corresponding keys.
5555

5656
When `mapping` is not given, the Parser will push rows as arrays of Buffers.
5757

58+
Check test directory for examples.
59+
5860
## fieldReader
5961

60-
A fieldReader is a Transform stream that takes a copyOut stream as input and outputs a sequence of fields.
61-
The fields are decoded according to the `options.mapping` definition
62+
A fieldReader is a Transform stream that takes a copyOut stream as input and outputs an objectMode stream that is a sequence of fields.
63+
The fields are decoded according to the `options.mapping` definition and each field has the following keys :
64+
- _fieldIndex: zero-based index of the field within a row
65+
- _fieldCount: total number of fields within a row
66+
- _fieldLength: byte-length of the field in binary representation (for bytea = number of bytes)
67+
- name: name of the field, equal to the key of the field in the mapping definition
68+
- value: value of the field. When mode is 'sync', this is the decoded value. When mode is 'async', this is a stream of _fieldLength bytes
6269

6370
Note that in fieldReader, each field can define a `mode = sync / async` attribute. When `mode = async`, the field output will be a Readable Stream.
6471
This can help in scenarios when you do not want to gather a big field in memory but you will need to make sure that you read the field stream because if you do not read it, backpressure will kick in and you will not receive more fields.
6572

73+
Check test directory for examples.
74+
6675
### options.mapping
6776

6877
default: false
@@ -75,10 +84,13 @@ the Parser will push fields with the corresponding keys.
7584

7685
When `mapping` is not given, the Parser will push fields as arrays of Buffers.
7786

87+
7888
## rawReader
7989

8090
A rawReader is a Transform stream that takes a copyOut stream as input and outputs raw field bytes.
8191

92+
Check test directory for examples.
93+
8294
## rowWriter
8395

8496
the deparser is usually used without arguments. It is a Transform Stream (always in object mode) that receives a stream of arrays, and outputs their PostgreSQL binary representation.
@@ -89,6 +101,8 @@ Currently, make sure sure value is not the javascript `undefined` because this c
89101

90102
Usually, you would want to use a through2 stream to prepare the arrays, and pipe this into the deparser.
91103

104+
Check test directory for examples.
105+
92106
### options.COPY_sendHeader
93107

94108
default: true
@@ -318,7 +332,7 @@ Use it at your own risks !
318332

319333
- [COPY documentation, including binary format](https://www.postgresql.org/docs/current/static/sql-copy.html)
320334
- [send/recv implementations for types in PostgreSQL](https://github.com/postgres/postgres/tree/master/src/backend/utils/adt)
321-
- [default type OIDs in PostgreSQL catalog](https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.h)
335+
- [default type OIDs in PostgreSQL catalog](https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat)
322336

323337
## Acknowledgments
324338

0 commit comments

Comments
 (0)