File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments