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

An SqlResult is an async iterable of SqlRowType which is either an SqlRow or regular JavaScript 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.

Values in SQL rows are deserialized lazily. While iterating you will get a HazelcastSqlException if a value in SQL row cannot be deserialized.

Use close to release the resources associated with the result.

An SqlResult can be iterated only once.

for-await... of

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

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

Another approach of iterating rows is using the next method. Every call to next returns an object with done and value properties. done is false when there are more rows to iterate, true otherwise. value holds the current row value. Refer to iterators for more information about iteration in JavaScript.

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

Usage for update count

const updateCount = result.updateCount; // A Long object

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

Hierarchy

Index

Properties

rowMetadata: SqlRowMetadata

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

updateCount: Long

The number of rows updated by the statement or -1 if this result is a row set.

Methods

  • 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>

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

    Returns boolean

    whether this result is a row set

  • 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.

    throws

    HazelcastSqlException if a value in current row cannot be deserialized.

    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