On this page

C

SQLTagStore

History

This class represents a single LRU (Least Recently Used) cache for storing prepared statements.

Instances of this class are created via the database.createTagStore() method, not by using a constructor. The store caches prepared statements based on the provided SQL query string. When the same query is seen again, the store retrieves the cached statement and safely applies the new values through parameter binding, thereby preventing attacks like SQL injection.

The cache has a maxSize that defaults to 1000 statements, but a custom size can be provided (e.g., database.createTagStore(100)). All APIs exposed by this class execute synchronously.

sqlTagStore.all(stringElements, ...boundParameters?): Array
Attributes
stringElements:string[]
Template literal elements containing the SQL query.
Parameter values to be bound to placeholders in the template string.
Returns:Array
An array of objects representing the rows returned by the query.

Executes the given SQL query and returns all resulting rows as an array of objects.

This function is intended to be used as a template literal tag, not to be called directly.

sqlTagStore.get(stringElements, ...boundParameters?): Object | undefined
Attributes
stringElements:string[]
Template literal elements containing the SQL query.
Parameter values to be bound to placeholders in the template string.
Returns:Object | undefined
An object representing the first row returned by the query, or undefined if no rows are returned.

Executes the given SQL query and returns the first resulting row as an object.

This function is intended to be used as a template literal tag, not to be called directly.

sqlTagStore.iterate(stringElements, ...boundParameters?): Iterator
Attributes
stringElements:string[]
Template literal elements containing the SQL query.
Parameter values to be bound to placeholders in the template string.
Returns:Iterator
An iterator that yields objects representing the rows returned by the query.

Executes the given SQL query and returns an iterator over the resulting rows.

This function is intended to be used as a template literal tag, not to be called directly.

sqlTagStore.run(stringElements, ...boundParameters?): Object
Attributes
stringElements:string[]
Template literal elements containing the SQL query.
Parameter values to be bound to placeholders in the template string.
Returns:Object
An object containing information about the execution, including changes and lastInsertRowid.

Executes the given SQL query, which is expected to not return any rows (e.g., INSERT, UPDATE, DELETE).

This function is intended to be used as a template literal tag, not to be called directly.

Type:integer

A read-only property that returns the number of prepared statements currently in the cache.

P

sqlTagStore.capacity

History
Type:integer

A read-only property that returns the maximum number of prepared statements the cache can hold.

P

sqlTagStore.db

History

A read-only property that returns the DatabaseSync object associated with this SQLTagStore.

M

sqlTagStore.clear

History
sqlTagStore.clear(): void

Resets the LRU cache, clearing all stored prepared statements.