SQLTagStore

sealed external interface SQLTagStore(source)

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

Instances of this class are created via the database.createSQLTagStore() 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.createSQLTagStore(100)). All APIs exposed by this class execute synchronously.

Since

v24.9.0

Properties

Link copied to clipboard
abstract val capacity: Double

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

Link copied to clipboard
abstract val db: DatabaseSync

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

Functions

Link copied to clipboard
abstract fun all(stringElements: TemplateStringsArray, vararg boundParameters: SQLInputValue): ReadonlyArray<ReadonlyRecord<String, SQLOutputValue>>

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

Link copied to clipboard
abstract fun clear()

Resets the LRU cache, clearing all stored prepared statements.

Link copied to clipboard
abstract fun get(stringElements: TemplateStringsArray, vararg boundParameters: SQLInputValue): ReadonlyRecord<String, SQLOutputValue>?

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

Link copied to clipboard
abstract fun iterate(stringElements: TemplateStringsArray, vararg boundParameters: SQLInputValue): JsIterator<ReadonlyRecord<String, SQLOutputValue>>

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

Link copied to clipboard
abstract fun run(stringElements: TemplateStringsArray, vararg boundParameters: SQLInputValue): StatementResultingChanges

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

Link copied to clipboard
abstract fun size(): Double

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