Skip to content

Commit 9908e0b

Browse files
committed
sqlite: update doc
1 parent 24f6ea0 commit 9908e0b

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

doc/api/sqlite.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,27 +1295,33 @@ are no subscribers.
12951295

12961296
### Channel `sqlite.db.query`
12971297

1298-
The message published to this channel is a {string} containing the expanded
1299-
SQL with bound parameter values substituted. If expansion fails, the source
1300-
SQL with unsubstituted placeholders is used instead.
1298+
The message published to this channel is an {Object} with the following
1299+
properties:
1300+
1301+
* `sql` {string} The expanded SQL with bound parameter values substituted.
1302+
If expansion fails, the source SQL with unsubstituted placeholders is used
1303+
instead.
1304+
* `database` {DatabaseSync} The `DatabaseSync` instance that executed the
1305+
statement.
1306+
* `duration` {number} The estimated statement run time in nanoseconds.
13011307

13021308
```cjs
13031309
const dc = require('node:diagnostics_channel');
13041310
const { DatabaseSync } = require('node:sqlite');
13051311

1306-
function onQuery(sql) {
1307-
console.log(sql);
1312+
function onQuery({ sql, database, duration }) {
1313+
console.log(sql, duration);
13081314
}
13091315

13101316
dc.subscribe('sqlite.db.query', onQuery);
13111317

13121318
const db = new DatabaseSync(':memory:');
13131319
db.exec('CREATE TABLE t (x INTEGER)');
1314-
// Logs: CREATE TABLE t (x INTEGER)
1320+
// Logs: CREATE TABLE t (x INTEGER) <duration>
13151321

13161322
const stmt = db.prepare('INSERT INTO t VALUES (?)');
13171323
stmt.run(42);
1318-
// Logs: INSERT INTO t VALUES (42.0)
1324+
// Logs: INSERT INTO t VALUES (42.0) <duration>
13191325

13201326
dc.unsubscribe('sqlite.db.query', onQuery);
13211327
```
@@ -1324,19 +1330,19 @@ dc.unsubscribe('sqlite.db.query', onQuery);
13241330
import dc from 'node:diagnostics_channel';
13251331
import { DatabaseSync } from 'node:sqlite';
13261332

1327-
function onQuery(sql) {
1328-
console.log(sql);
1333+
function onQuery({ sql, database, duration }) {
1334+
console.log(sql, duration);
13291335
}
13301336

13311337
dc.subscribe('sqlite.db.query', onQuery);
13321338

13331339
const db = new DatabaseSync(':memory:');
13341340
db.exec('CREATE TABLE t (x INTEGER)');
1335-
// Logs: CREATE TABLE t (x INTEGER)
1341+
// Logs: CREATE TABLE t (x INTEGER) <duration>
13361342

13371343
const stmt = db.prepare('INSERT INTO t VALUES (?)');
13381344
stmt.run(42);
1339-
// Logs: INSERT INTO t VALUES (42.0)
1345+
// Logs: INSERT INTO t VALUES (42.0) <duration>
13401346

13411347
dc.unsubscribe('sqlite.db.query', onQuery);
13421348
```

0 commit comments

Comments
 (0)