fix(plugins): report a plugin SQL call done once its last statement has run

The time budget for an exec script was read after every statement, the
last one included. A single statement without args, or a script whose
closing COMMIT crossed the budget, had already run and committed, yet the
call threw a time budget error. A plugin that retries on error then wrote
the same rows a second time.

The script now reads the clock before each statement after the first, so
it still stops before the next statement once the time is up and rolls
back a transaction it opened, but a script whose statements have all run
is reported as done. query() likewise reads the clock only once another
row has come back, so a result read to its end is returned.

The ctx.db doc in the SDK said a single statement was not timed, which
contradicted the query budget. It now names what is really untimed: an
exec with bound args and migrate. README and wiki describe the script
stopping before its next statement.
This commit is contained in:
Maurice
2026-10-08 18:11:34 +02:00
parent d3be6fb2b8
commit 465480630b
5 changed files with 79 additions and 23 deletions
+4 -2
View File
@@ -74,8 +74,10 @@ export interface PluginContext {
* path or connection to directly. Quota: 256 MB per plugin (writes past it fail);
* result sets are capped at 100,000 rows, and a `query`, a `tx` or an `exec` script
* without args gets 2 s of wall-clock time, checked between the rows it reads and
* the statements it runs (past it, it throws, a `tx` rolls back and a script stops).
* A single statement and `migrate` are not timed.
* the statements it runs (past it, it throws, a `tx` rolls back and a script stops
* before its next statement). An `exec` with bound args (one statement) and
* `migrate` are not timed, and no single statement can be stopped midway (a read
* only between its rows).
* See `tx()` below for the atomic-batch cap and README § Runtime limits. */
db: {
query<T = unknown>(sql: string, ...args: unknown[]): Promise<T[]>;