Options
All
  • Public
  • Public/Protected
  • All
Menu

SQL query result. Depending on the statement type it represents a stream of rows or an update count.

Iteration

The SqlResult is an async iterable of SqlRowType which is either an SqlRow or regular objects. By default it returns regular JavaScript objects, containing key and values. Keys represent column names, whereas values represent row values. The default object returning behavior can be changed via the option SqlStatementOptions.returnRawResult. If it is true, SqlRow objects are returned instead of regular objects.

Use close to release the resources associated with the result.

for-await... of

Refer to for-await... of page for more information.

for await (const row of result) {
    console.log(row);
}

Another approach to iterating rows is using next. Next returns an object with done and value properties. done is false when there are more rows to iterate, false otherwise. value holds the current row value. Refer to iterators for more information.

let row = await result.next();
while (!row.done) {
    console.log(row.value);
    row = await result.next();
}

Usage for update count

const updateCount = await result.getUpdateCount();

You don't need to call close in this case.

Hierarchy

  • AsyncIterable<SqlRowType>
    • SqlResult

Index

Methods

close

  • close(): Promise<void>
  • Releases the resources associated with the query result.

    The query engine delivers the rows asynchronously. The query may become inactive even before all rows are consumed. The invocation of this command will cancel the execution of the query on all members if the query is still active. Otherwise it is no-op. For a result with an update count it is always no-op.

    Returns Promise<void>

getRowMetadata

  • getRowMetadata(): Promise<SqlRowMetadata>
  • Returns row metadata of the result.

    Returns Promise<SqlRowMetadata>

    SQL row metadata if rows exist in the result; otherwise null.

getUpdateCount

  • getUpdateCount(): Promise<Long>
  • Returns the number of rows updated by the statement or -1 if this result is a row set.

    Returns Promise<Long>

    update count

isRowSet

  • isRowSet(): Promise<boolean>
  • Return whether this result has rows to iterate. False if update count is returned, true if rows are returned.

    Returns Promise<boolean>

    whether this result is a row set

next

  • next(): Promise<IteratorResult<SqlRowType, any>>
  • Returns next SqlRowType iteration result. You should not call this method when result does not contain rows.

    throws

    IllegalStateError if result does not contain rows, but update count.

    Returns Promise<IteratorResult<SqlRowType, any>>

    an object including value and done keys. The done key indicates if iteration is ended, i.e when there are no more results. value holds iteration values which are in SqlRowType type. value has undefined value if iteration has ended.

Generated using TypeDoc