Skip to content

StatementSync

[<Interface>]
type StatementSync =
    abstract member expandedSQL: string
    abstract member sourceSQL: string
    abstract member all (namedParameters: Record<string,SQLInputValue>, anonymousParameters: SQLInputValue array) : Record<string,SQLOutputValue> array
    abstract member all (anonymousParameters: SQLInputValue array) : Record<string,SQLOutputValue> array
    abstract member columns () : StatementColumnMetadata array
    abstract member get (namedParameters: Record<string,SQLInputValue>, anonymousParameters: SQLInputValue array) : Record<string,SQLOutputValue> option
    abstract member get (anonymousParameters: SQLInputValue array) : Record<string,SQLOutputValue> option
    abstract member iterate (namedParameters: Record<string,SQLInputValue>, anonymousParameters: SQLInputValue array) : Iterator<Record<string,SQLOutputValue>,obj,obj>
    abstract member iterate (anonymousParameters: SQLInputValue array) : Iterator<Record<string,SQLOutputValue>,obj,obj>
    abstract member run (namedParameters: Record<string,SQLInputValue>, anonymousParameters: SQLInputValue array) : StatementResultingChanges
    abstract member run (anonymousParameters: SQLInputValue array) : StatementResultingChanges
    abstract member setAllowBareNamedParameters (enabled: bool) : unit
    abstract member setAllowUnknownNamedParameters (enabled: bool) : unit
    abstract member setReadBigInts (enabled: bool) : unit
    abstract member setReturnArrays (enabled: bool) : unit
AssemblyXantham.Fable.Node

This class represents a single prepared statement. This class cannot be instantiated via its constructor. Instead, instances are created via thedatabase.prepare() method. All APIs exposed by this class execute synchronously.

A prepared statement is an efficient binary representation of the SQL used to create it. Prepared statements are parameterizable, and can be invoked multiple times with different bound values. Parameters also offer protection against SQL injection attacks. For these reasons, prepared statements are preferred over hand-crafted SQL strings when handling user input.

@since v22.5.0

Properties

abstract member expandedSQL: string

The source SQL text of the prepared statement with parameter placeholders replaced by the values that were used during the most recent execution of this prepared statement. This property is a wrapper around sqlite3_expanded_sql().

@since v22.5.0

abstract member sourceSQL: string

The source SQL text of the prepared statement. This property is a wrapper around sqlite3_sql().

@since v22.5.0

Methods

abstract member all (namedParameters: Record<string,SQLInputValue>, anonymousParameters: SQLInputValue array) : Record<string,SQLOutputValue> array

This method executes a prepared statement and returns all results as an array of objects. If the prepared statement does not return any results, this method returns an empty array. The prepared statement parameters are bound using the values in namedParameters and anonymousParameters.

@since v22.5.0

Parameter
namedParametersAn optional object used to bind named parameters. The keys of this object are used to configure the mapping.
anonymousParametersZero or more values to bind to anonymous parameters.

Returns. An array of objects. Each object corresponds to a row returned by executing the prepared statement. The keys and values of each object correspond to the column names and values of the row.

abstract member all (anonymousParameters: SQLInputValue array) : Record<string,SQLOutputValue> array

This method executes a prepared statement and returns all results as an array of objects. If the prepared statement does not return any results, this method returns an empty array. The prepared statement parameters are bound using the values in namedParameters and anonymousParameters.

@since v22.5.0

Parameter
namedParametersAn optional object used to bind named parameters. The keys of this object are used to configure the mapping.
anonymousParametersZero or more values to bind to anonymous parameters.

Returns. An array of objects. Each object corresponds to a row returned by executing the prepared statement. The keys and values of each object correspond to the column names and values of the row.

abstract member columns () : StatementColumnMetadata array

This method is used to retrieve information about the columns returned by the prepared statement.

@since v22.16.0

Returns. An array of objects. Each object corresponds to a column in the prepared statement, and contains the following properties:

abstract member get (namedParameters: Record<string,SQLInputValue>, anonymousParameters: SQLInputValue array) : Record<string,SQLOutputValue> option

This method executes a prepared statement and returns the first result as an object. If the prepared statement does not return any results, this method returns undefined. The prepared statement parameters are bound using the values in namedParameters and anonymousParameters.

@since v22.5.0

Parameter
namedParametersAn optional object used to bind named parameters. The keys of this object are used to configure the mapping.
anonymousParametersZero or more values to bind to anonymous parameters.

Returns. An object corresponding to the first row returned by executing the prepared statement. The keys and values of the object correspond to the column names and values of the row. If no rows were returned from the database then this method returns undefined.

abstract member get (anonymousParameters: SQLInputValue array) : Record<string,SQLOutputValue> option

This method executes a prepared statement and returns the first result as an object. If the prepared statement does not return any results, this method returns undefined. The prepared statement parameters are bound using the values in namedParameters and anonymousParameters.

@since v22.5.0

Parameter
namedParametersAn optional object used to bind named parameters. The keys of this object are used to configure the mapping.
anonymousParametersZero or more values to bind to anonymous parameters.

Returns. An object corresponding to the first row returned by executing the prepared statement. The keys and values of the object correspond to the column names and values of the row. If no rows were returned from the database then this method returns undefined.

abstract member iterate (namedParameters: Record<string,SQLInputValue>, anonymousParameters: SQLInputValue array) : Iterator<Record<string,SQLOutputValue>,obj,obj>

This method executes a prepared statement and returns an iterator of objects. If the prepared statement does not return any results, this method returns an empty iterator. The prepared statement parameters are bound using the values in namedParameters and anonymousParameters.

@since v22.13.0

Parameter
namedParametersAn optional object used to bind named parameters. The keys of this object are used to configure the mapping.
anonymousParametersZero or more values to bind to anonymous parameters.

Returns. An iterable iterator of objects. Each object corresponds to a row returned by executing the prepared statement. The keys and values of each object correspond to the column names and values of the row.

abstract member iterate (anonymousParameters: SQLInputValue array) : Iterator<Record<string,SQLOutputValue>,obj,obj>

This method executes a prepared statement and returns an iterator of objects. If the prepared statement does not return any results, this method returns an empty iterator. The prepared statement parameters are bound using the values in namedParameters and anonymousParameters.

@since v22.13.0

Parameter
namedParametersAn optional object used to bind named parameters. The keys of this object are used to configure the mapping.
anonymousParametersZero or more values to bind to anonymous parameters.

Returns. An iterable iterator of objects. Each object corresponds to a row returned by executing the prepared statement. The keys and values of each object correspond to the column names and values of the row.

abstract member run (namedParameters: Record<string,SQLInputValue>, anonymousParameters: SQLInputValue array) : StatementResultingChanges

This method executes a prepared statement and returns an object summarizing the resulting changes. The prepared statement parameters are bound using the values in namedParameters and anonymousParameters.

@since v22.5.0

Parameter
namedParametersAn optional object used to bind named parameters. The keys of this object are used to configure the mapping.
anonymousParametersZero or more values to bind to anonymous parameters.
abstract member run (anonymousParameters: SQLInputValue array) : StatementResultingChanges

This method executes a prepared statement and returns an object summarizing the resulting changes. The prepared statement parameters are bound using the values in namedParameters and anonymousParameters.

@since v22.5.0

Parameter
namedParametersAn optional object used to bind named parameters. The keys of this object are used to configure the mapping.
anonymousParametersZero or more values to bind to anonymous parameters.
abstract member setAllowBareNamedParameters (enabled: bool) : unit

The names of SQLite parameters begin with a prefix character. By default,node:sqlite requires that this prefix character is present when binding parameters. However, with the exception of dollar sign character, these prefix characters also require extra quoting when used in object keys.

To improve ergonomics, this method can be used to also allow bare named parameters, which do not require the prefix character in JavaScript code. There are several caveats to be aware of when enabling bare named parameters:

  • The prefix character is still required in SQL.
  • The prefix character is still allowed in JavaScript. In fact, prefixed names will have slightly better binding performance.
  • Using ambiguous named parameters, such as $k and @k, in the same prepared statement will result in an exception as it cannot be determined how to bind a bare name.

@since v22.5.0

Parameter
enabledEnables or disables support for binding named parameters without the prefix character.
abstract member setAllowUnknownNamedParameters (enabled: bool) : unit

By default, if an unknown name is encountered while binding parameters, an exception is thrown. This method allows unknown named parameters to be ignored.

@since v22.15.0

Parameter
enabledEnables or disables support for unknown named parameters.
abstract member setReadBigInts (enabled: bool) : unit

When reading from the database, SQLite INTEGERs are mapped to JavaScript numbers by default. However, SQLite INTEGERs can store values larger than JavaScript numbers are capable of representing. In such cases, this method can be used to read INTEGER data using JavaScript BigInts. This method has no impact on database write operations where numbers and BigInts are both supported at all times.

@since v22.5.0

Parameter
enabledEnables or disables the use of BigInts when reading INTEGER fields from the database.
abstract member setReturnArrays (enabled: bool) : unit

When enabled, query results returned by the all(), get(), and iterate() methods will be returned as arrays instead of objects.

@since v22.16.0

Parameter
enabledEnables or disables the return of query results as arrays.