From d63c761be83fbfe18602b7aca9254a2e731cc7c3 Mon Sep 17 00:00:00 2001 From: Felix Rath Date: Mon, 1 May 2023 16:15:55 +0200 Subject: [PATCH] docs(api/result): clarify that `result.rowCount` can be `null` (#2967) `result.rowCount` is initialized to `null`, but only set to an `int`-value if the returned command tag consists of more than one word, which is not the case in general. For example, the `LOCK` command will return a command tag of simply the form `LOCK`, and thus `result.rowCount` will stay `null`. --- docs/pages/apis/result.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pages/apis/result.mdx b/docs/pages/apis/result.mdx index a0ef7ddb..8c130e88 100644 --- a/docs/pages/apis/result.mdx +++ b/docs/pages/apis/result.mdx @@ -37,9 +37,9 @@ await client.end() The command type last executed: `INSERT` `UPDATE` `CREATE` `SELECT` etc. -### `result.rowCount: int` +### `result.rowCount: int | null` -The number of rows processed by the last command. +The number of rows processed by the last command. Can be `null` for commands that never affect rows, such as the `LOCK`-command. More specifically, some commands, including `LOCK`, only return a command tag of the form `COMMAND`, without any `[ROWS]`-field to parse. For such commands `rowCount` will be `null`. _note: this does not reflect the number of rows __returned__ from a query. e.g. an update statement could update many rows (so high `result.rowCount` value) but `result.rows.length` would be zero. To check for an empty query reponse on a `SELECT` query use `result.rows.length === 0`_.