Skip to main content
Module

x/sqlite3/mod.ts>Statement

The fastest and correct module for SQLite3 in Deno.
Latest
class Statement
import { Statement } from "https://deno.land/x/sqlite3@0.11.1/mod.ts";

Represents a prepared statement.

See Database#prepare for more information.

Constructors

new
Statement(db: Database, sql: string)

Properties

readonly
bindParameterCount: number

Number of parameters (to be) bound

callback: boolean

Whether the query might call into JavaScript or not.

Must enable if the query makes use of user defined functions, otherwise there can be V8 crashes.

Off by default. Causes performance degradation.

readonly
expandedSql: string

SQL string including bindings

readonly
readonly: boolean

Whether this statement doesn't make any direct changes to the DB

readonly
sql: string

The SQL string that we passed when creating statement

readonly
unsafeHandle: Deno.PointerValue

Unsafe Raw (pointer) to the sqlite object

Methods

all<T extends Record<string, unknown> = Record<string, any>>(...args: RestBindParameters): T[]

Run the query and return the resulting rows where rows are objects mapping column name to their corresponding values.

bind(...params: RestBindParameters): this

Bind parameters to the statement. This method can only be called once to set the parameters to be same throughout the statement. You cannot change the parameters after this method is called.

This method is merely just for optimization to avoid binding parameters each time in prepared statement.

bindParameterIndex(name: string): number

Get bind parameter index by name

bindParameterName(i: number): string

Get bind parameter name by index

columnNames(): string[]

Shorthand for this.callback = true. Enables calling user defined functions.

finalize(): void

Free up the statement object.

get<T extends Record<string, unknown>>(...params: RestBindParameters): T | undefined

Fetch only first row as an object, if any.

run(...args: RestBindParameters): number

Simply run the query without retrieving any output there may be.

toString(): string

Coerces the statement to a string, which in this case is expanded SQL.

value<T extends Array<unknown>>(...params: RestBindParameters): T | undefined

Fetch only first row as an array, if any.

values<T extends unknown[] = any[]>(...args: RestBindParameters): T[]

Run the query and return the resulting rows where rows are array of columns.

[Symbol.iterator](): IterableIterator<any>

Iterate over resultant rows from query.