Skip to content

Commit 3f7ebb4

Browse files
committed
Add missing Result array documentation - fixes porsager#345
1 parent c2eb7c9 commit 3f7ebb4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async function insertUser({ name, age }) {
7272
* [Listen & notify](#listen--notify)
7373
* [Realtime subscribe](#realtime-subscribe)
7474
* [Numbers, bigint, numeric](#numbers-bigint-numeric)
75+
* [Result Array](#result-array)
7576
* [Connection details](#connection-details)
7677
* [Custom Types](#custom-types)
7778
* [Teardown / Cleanup](#teardown--cleanup)
@@ -661,6 +662,46 @@ const sql = postgres({
661662
662663
There is currently no guaranteed way to handle `numeric` / `decimal` types in native Javascript. **These [and similar] types will be returned as a `string`**. The best way in this case is to use [custom types](#custom-types).
663664
665+
## Result Array
666+
667+
The `Result` Array returned from queries is a custom array allowing for easy destructuring or passing on directly to JSON.stringify or general Array usage. It includes the following properties.
668+
669+
### .count
670+
671+
The `count` property is the number of affected rows returned by the database. This is usefull for insert, update and delete operations to know the number of rows since .length will be 0 in these cases if not using `RETURNING ...`.
672+
673+
### .command
674+
675+
The `command` run by the query - eg. one of `SELECT`, `UPDATE`, `INSERT`, `DELETE`
676+
677+
### .columns
678+
679+
The `columns` returned by the query useful to determine types, or map to the result values when using `.values()`
680+
681+
```js
682+
{
683+
name : String, // Column name,
684+
type : oid, // PostgreSQL oid column type
685+
parser: Function // The function used by Postgres.js for parsing
686+
}
687+
```
688+
689+
### .statement
690+
691+
The `statement` contains information about the statement implicitly created by Postgres.js.
692+
693+
```js
694+
{
695+
name : String, // The auto generated statement name
696+
string : String, // The actual query string executed
697+
types : [oid], // An array of oid expected as input parameters
698+
columns : [Column] // Array of columns - same as Result.columns
699+
}
700+
```
701+
702+
### .state
703+
704+
This is the state `{ pid, secret }` of the connection that executed the query.
664705
665706
## Connection details
666707

0 commit comments

Comments
 (0)