Skip to content

Commit abfd152

Browse files
committed
sqlite: update doc
1 parent 0867538 commit abfd152

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

doc/api/sqlite.md

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

13791379
### Channel `sqlite.db.query`
13801380

1381-
The message published to this channel is a {string} containing the expanded
1382-
SQL with bound parameter values substituted. If expansion fails, the source
1383-
SQL with unsubstituted placeholders is used instead.
1381+
The message published to this channel is an {Object} with the following
1382+
properties:
1383+
1384+
* `sql` {string} The expanded SQL with bound parameter values substituted.
1385+
If expansion fails, the source SQL with unsubstituted placeholders is used
1386+
instead.
1387+
* `database` {DatabaseSync} The `DatabaseSync` instance that executed the
1388+
statement.
1389+
* `duration` {number} The estimated statement run time in nanoseconds.
13841390

13851391
```cjs
13861392
const dc = require('node:diagnostics_channel');
13871393
const { DatabaseSync } = require('node:sqlite');
13881394

1389-
function onQuery(sql) {
1390-
console.log(sql);
1395+
function onQuery({ sql, database, duration }) {
1396+
console.log(sql, duration);
13911397
}
13921398

13931399
dc.subscribe('sqlite.db.query', onQuery);
13941400

13951401
const db = new DatabaseSync(':memory:');
13961402
db.exec('CREATE TABLE t (x INTEGER)');
1397-
// Logs: CREATE TABLE t (x INTEGER)
1403+
// Logs: CREATE TABLE t (x INTEGER) <duration>
13981404

13991405
const stmt = db.prepare('INSERT INTO t VALUES (?)');
14001406
stmt.run(42);
1401-
// Logs: INSERT INTO t VALUES (42.0)
1407+
// Logs: INSERT INTO t VALUES (42.0) <duration>
14021408

14031409
dc.unsubscribe('sqlite.db.query', onQuery);
14041410
```
@@ -1407,19 +1413,19 @@ dc.unsubscribe('sqlite.db.query', onQuery);
14071413
import dc from 'node:diagnostics_channel';
14081414
import { DatabaseSync } from 'node:sqlite';
14091415

1410-
function onQuery(sql) {
1411-
console.log(sql);
1416+
function onQuery({ sql, database, duration }) {
1417+
console.log(sql, duration);
14121418
}
14131419

14141420
dc.subscribe('sqlite.db.query', onQuery);
14151421

14161422
const db = new DatabaseSync(':memory:');
14171423
db.exec('CREATE TABLE t (x INTEGER)');
1418-
// Logs: CREATE TABLE t (x INTEGER)
1424+
// Logs: CREATE TABLE t (x INTEGER) <duration>
14191425

14201426
const stmt = db.prepare('INSERT INTO t VALUES (?)');
14211427
stmt.run(42);
1422-
// Logs: INSERT INTO t VALUES (42.0)
1428+
// Logs: INSERT INTO t VALUES (42.0) <duration>
14231429

14241430
dc.unsubscribe('sqlite.db.query', onQuery);
14251431
```

0 commit comments

Comments
 (0)