Skip to content

Commit 12cab63

Browse files
committed
doc: add CJS documentation for sqlite's createTagStore
Fixes: #60394
1 parent 2bda7cb commit 12cab63

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

doc/api/sqlite.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,33 @@ console.log(allUsers);
483483
// ]
484484
```
485485

486+
```cjs
487+
const { DatabaseSync } = require('node:sqlite');
488+
489+
const db = new DatabaseSync(':memory:');
490+
const sql = db.createTagStore();
491+
492+
db.exec('CREATE TABLE users (id INT, name TEXT)');
493+
494+
// Using the 'run' method to insert data.
495+
// The tagged literal is used to identify the prepared statement.
496+
sql.run`INSERT INTO users VALUES (1, 'Alice')`;
497+
sql.run`INSERT INTO users VALUES (2, 'Bob')`;
498+
499+
// Using the 'get' method to retrieve a single row.
500+
const id = 1;
501+
const user = sql.get`SELECT * FROM users WHERE id = ${id}`;
502+
console.log(user); // { id: 1, name: 'Alice' }
503+
504+
// Using the 'all' method to retrieve all rows.
505+
const allUsers = sql.all`SELECT * FROM users ORDER BY id`;
506+
console.log(allUsers);
507+
// [
508+
// { id: 1, name: 'Alice' },
509+
// { id: 2, name: 'Bob' }
510+
// ]
511+
```
512+
486513
### `database.createSession([options])`
487514

488515
<!-- YAML

0 commit comments

Comments
 (0)