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
Name | Type |
---|---|
S | unknown |
Constructors
constructor
• new Statement<S
>(config
, sql
, parameters?
)
Type parameters
Name | Type |
---|---|
S | unknown |
Parameters
Name | Type |
---|---|
config | Partial <ReadConfig & SignerConfig > & Partial <AutoWaitConfig > |
sql | string |
parameters? | Parameters |
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
▸ Private
#checkIsValidOpts(opts
): opts is Options
Parameters
Name | Type |
---|---|
opts | any |
Returns
opts is Options
Defined in
@tableland/sdk/src/statement.ts:185
#parseAndExtract
▸ Private
#parseAndExtract(): Promise
<ExtractedStatement
>
Returns
Promise
<ExtractedStatement
>
Defined in
@tableland/sdk/src/statement.ts:112
#waitExec
▸ Private
#waitExec(params
, controller?
): Promise
<WaitableTransactionReceipt
>
Parameters
Name | Type |
---|---|
params | ExtractedStatement |
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
Name | Type |
---|---|
T | Record <string , S > |
Parameters
Name | Type | Description |
---|---|---|
opts | Options | An 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
Name | Type |
---|---|
T | S |
Parameters
Name | Type | Description |
---|---|---|
...values | ValuesType [] | 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
Name | Type |
---|---|
T | Record <string , S > |
Parameters
Name | Type | Description |
---|---|---|
opts? | Options | An 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
Name | Type |
---|---|
T | S |
K | extends string = keyof T & string |
Parameters
Name | Type |
---|---|
colName | undefined |
opts? | Options |
Returns
Promise
<T
>
Defined in
@tableland/sdk/src/statement.ts:199
▸ first<T
, K
>(colName
, opts?
): Promise
<null
| T
[K
]>
Type parameters
Name | Type |
---|---|
T | S |
K | extends string = keyof T & string |
Parameters
Name | Type |
---|---|
colName | K |
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
Name | Type |
---|---|
T | S |
Parameters
Name | Type | Description |
---|---|---|
opts | Options | An 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
Name | Type |
---|---|
T | Record <string , S > |
Parameters
Name | Type | Description |
---|---|---|
opts | Options | An 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
Name | Type |
---|---|
parameters? | Parameters |
sql | string |
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