Skip to content

Commit b42e601

Browse files
committed
sqlite: add tagged template support
Adding tagged template and LRU cache for prepared statements in SQLite.
1 parent 5f7dbf4 commit b42e601

File tree

4 files changed

+578
-1
lines changed

4 files changed

+578
-1
lines changed

doc/api/sqlite.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,31 @@ added: v22.5.0
347347
Compiles a SQL statement into a [prepared statement][]. This method is a wrapper
348348
around [`sqlite3_prepare_v2()`][].
349349

350+
### `database.createTagStore(max_size)`
351+
352+
<!-- YAML
353+
added: v24.3.0
354+
-->
355+
356+
* `max_size` {integer} The maximum number of prepared statements to cache.
357+
**Default:** `1000`.
358+
* Returns: {SqlTagStore} A new tag store for caching prepared statements.
359+
360+
Creates a new `SqlTagStore` instance, which can be used with tagged template
361+
literals to execute prepared statements. The `max_size` parameter controls the
362+
size of the LRU cache used to store prepared statements.
363+
364+
```mjs
365+
import { DatabaseSync } from 'node:sqlite';
366+
367+
const db = new DatabaseSync(':memory:');
368+
const sql = db.createTagStore();
369+
370+
db.exec('CREATE TABLE users (id INT, name TEXT)');
371+
const user = sql.get`INSERT INTO users VALUES (1, 'Alice')`;
372+
console.log(user); // { id: 1, name: 'Alice' }
373+
```
374+
350375
### `database.createSession([options])`
351376

352377
<!-- YAML

0 commit comments

Comments
 (0)