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?): Statement<S>

Type parameters

NameType
Sunknown

Parameters

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

Returns

Statement<S>

Defined in

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

Properties

config

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

Defined in

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


parameters

Private Optional Readonly parameters: Parameters

Defined in

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


sql

Private Readonly sql: string

Defined in

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

Methods

#checkIsValidOpts

#checkIsValidOpts(opts): opts is Options

Parameters

NameType
optsany

Returns

opts is Options

Defined in

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


#parseAndExtract

#parseAndExtract(): Promise<ExtractedStatement>

Returns

Promise<ExtractedStatement>

Defined in

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


#waitExec

#waitExec(params, controller?): Promise<WaitableTransactionReceipt>

Parameters

NameType
paramsExtractedStatement
controller?PollingController

Returns

Promise<WaitableTransactionReceipt>

Defined in

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


all

all<T>(opts?): Promise<Result<T>>

Executes a query and returns all rows and metadata.

Type parameters

NameType
TRecord<string, S>

Parameters

NameTypeDescription
optsOptionsAn optional object used to control behavior, see Options

Returns

Promise<Result<T>>

Defined in

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


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:83


first

first<T>(opts?): Promise<null | 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
TRecord<string, S>

Parameters

NameTypeDescription
opts?OptionsAn optional object used to control behavior, see Options

Returns

Promise<null | T>

Defined in

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

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

Type parameters

NameType
TS
Kextends string = keyof T & string

Parameters

NameType
colNameundefined
opts?Options

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 = keyof T & string

Parameters

NameType
colNameK
opts?Options

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
optsOptionsAn optional object used to control behavior, see Options

Returns

Promise<ValueOf<T>[]>

An array of raw query results.

Defined in

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


run

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

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

Type parameters

NameType
TRecord<string, S>

Parameters

NameTypeDescription
optsOptionsAn optional object used to control behavior, see Options

Returns

Promise<Result<T>>

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

Defined in

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


toObject

toObject(): Object

Export a Statement's sql string and parameters.

Returns

Object

NameType
parameters?Parameters
sqlstring

Defined in

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


toString

toString(): string

Resolve a bound statement to a SQL string.

Returns

string

A valid SQL string.

Defined in

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