Class Statement<S>

Statement defines a single SQL statement. Both static and prepared statements are supported. In the current implementation, the prepared statements are prepared locally, and executed remotely (on-chain). Mutating transactions such as INSERTs, DELETEs, and UPDATEs produce a two-phase transaction. Firstly, the transaction is sent to the registry contract, and awaited. The returned txn information also contains a wait method than can be used to await finalization on the Tableland network. This method will also throw an exception if any runtime errors occur.

Type Parameters

  • S = unknown

Hierarchy

  • Statement

Constructors

Properties

config: Partial<ReadConfig & SignerConfig> & Partial<AutoWaitConfig>
parameters?: Parameters
sql: string

Methods

  • Returns Promise<ExtractedStatement>

  • Executes a query and returns all rows and metadata.

    Type Parameters

    • T = S

    • K extends string | number | symbol = keyof T

    Parameters

    • Optional colName: undefined

      If provided, filter results to the provided column.

    • Optional opts: SignalAndInterval

      Additional options to control execution.

    Returns Promise<Result<T>>

  • Type Parameters

    • T = S

    • K extends string | number | symbol = keyof T

    Parameters

    Returns Promise<Result<T[K]>>

  • Bind a set of values to the parameters of the prepared statement. We follow the SQLite convention for prepared statements parameter binding. We support Ordered (?NNNN), Anonymous (?), and Named (@name, :name, $name) parameters.

    Type Parameters

    • T = S

    Parameters

    • Rest ...values: ValuesType[]

      A variadic list of values to bind. May include base types, and objects.

    Returns Statement<T>

    A new bound Statement.

  • Executes a query and returns the first row of the results. This does not return metadata like the other methods. Instead it returns the object directly. If the query returns no rows, then first() will return null.

    Type Parameters

    • T = S

    • K extends string | number | symbol = keyof T

    Returns Promise<T>

  • Type Parameters

    • T = S

    • K extends string | number | symbol = keyof T

    Parameters

    Returns Promise<T>

  • Type Parameters

    • T = S

    • K extends string | number | symbol = keyof T

    Parameters

    Returns Promise<null | T[K]>

  • Same as stmt.all(), but returns an array of rows instead of objects.

    Type Parameters

    • T = S

    Parameters

    Returns Promise<ValueOf<T>[]>

    An array of raw query results.

  • Runs the query/queries, but returns no results. Instead, run() returns the metrics only. Useful for write operations like UPDATE, DELETE or INSERT.

    Parameters

    Returns Promise<Result<never>>

    A results object with metadata only (results are null or an empty array).

  • Export a Statement's sql string and parameters.

    Returns {
        parameters?: Parameters;
        sql: string;
    }

  • Resolve a bound statement to a SQL string.

    Returns string

    A valid SQL string.

Generated using TypeDoc