Skip to main content

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

NameType
Sunknown

Constructors

constructor

new Statement<S>(config, sql, parameters?)

Type parameters

NameType
Sunknown

Parameters

NameType
configPartial<ReadConfig & SignerConfig> & Partial<AutoWaitConfig>
sqlstring
parameters?Parameters

Defined in

@tableland/sdk/src/statement.ts:52

Properties

config

Private Readonly config: Partial<ReadConfig & SignerConfig> & Partial<AutoWaitConfig>

Defined in

@tableland/sdk/src/statement.ts:48


parameters

Private Optional Readonly parameters: Parameters

Defined in

@tableland/sdk/src/statement.ts:50


sql

Private Readonly sql: string

Defined in

@tableland/sdk/src/statement.ts:49

Methods

#parseAndExtract

Private #parseAndExtract(): Promise<ExtractedStatement>

Returns

Promise<ExtractedStatement>

Defined in

@tableland/sdk/src/statement.ts:102


#waitExec

Private #waitExec(params): Promise<WaitableTransactionReceipt>

Parameters

NameType
paramsExtractedStatement

Returns

Promise<WaitableTransactionReceipt>

Defined in

@tableland/sdk/src/statement.ts:133


all

all<T, K>(colName?, opts?): Promise<Result<T>>

Executes a query and returns all rows and metadata.

Type parameters

NameType
TS
Kextends string | number | symbol = keyof T

Parameters

NameTypeDescription
colName?undefinedIf provided, filter results to the provided column.
opts?SignalAndIntervalAdditional options to control execution.

Returns

Promise<Result<T>>

Defined in

@tableland/sdk/src/statement.ts:145

all<T, K>(colName, opts?): Promise<Result<T[K]>>

Type parameters

NameType
TS
Kextends string | number | symbol = keyof T

Parameters

NameType
colNameK
opts?SignalAndInterval

Returns

Promise<Result<T[K]>>

Defined in

@tableland/sdk/src/statement.ts:149


bind

bind<T>(...values): Statement<T>

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

NameType
TS

Parameters

NameTypeDescription
...valuesValuesType[]A variadic list of values to bind. May include base types, and objects.

Returns

Statement<T>

A new bound Statement.

Defined in

@tableland/sdk/src/statement.ts:73


first

first<T, K>(): Promise<T>

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

NameType
TS
Kextends string | number | symbol = keyof T

Returns

Promise<T>

Defined in

@tableland/sdk/src/statement.ts:197

first<T, K>(colName, opts?): Promise<T>

Type parameters

NameType
TS
Kextends string | number | symbol = keyof T

Parameters

NameType
colNameundefined
opts?SignalAndInterval

Returns

Promise<T>

Defined in

@tableland/sdk/src/statement.ts:199

first<T, K>(colName, opts?): Promise<null | T[K]>

Type parameters

NameType
TS
Kextends string | number | symbol = keyof T

Parameters

NameType
colNameK
opts?SignalAndInterval

Returns

Promise<null | T[K]>

Defined in

@tableland/sdk/src/statement.ts:203


raw

raw<T>(opts?): Promise<ValueOf<T>[]>

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

Type parameters

NameType
TS

Parameters

NameTypeDescription
optsSignalAndIntervalAdditional options to control execution.

Returns

Promise<ValueOf<T>[]>

An array of raw query results.

Defined in

@tableland/sdk/src/statement.ts:279


run

run(opts?): Promise<Result<never>>

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

Parameters

NameTypeDescription
optsSignalAndIntervalAdditional options to control execution.

Returns

Promise<Result<never>>

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

Defined in

@tableland/sdk/src/statement.ts:248


toObject

toObject(): Object

Export a Statement's sql string and parameters.

Returns

Object

NameType
parameters?Parameters
sqlstring

Defined in

@tableland/sdk/src/statement.ts:95


toString

toString(): string

Resolve a bound statement to a SQL string.

Returns

string

A valid SQL string.

Defined in

@tableland/sdk/src/statement.ts:82