|
Couchbase C++ SDK 1.4.0 (rev. 59aa900)
|
A streaming result handle for N1QL queries. More...
#include <couchbase/query_stream_result.hxx>
Classes | |
| struct | end_sentinel |
| Sentinel returned by end(). More... | |
| class | iterator |
| A single-pass input iterator that synchronously fetches rows one at a time. More... | |
Public Member Functions | |
| query_stream_result ()=default | |
| Constructs an empty (no-op) result handle. | |
| query_stream_result (std::shared_ptr< internal_query_stream_result > internal) | |
| Constructs a query stream result from an internal result. | |
| void | next (query_row_handler &&handler) const |
| Fetches the next row asynchronously, invoking the handler when ready. | |
| auto | next () const -> std::future< std::pair< error, std::optional< query_row > > > |
| Fetches the next row, returning a future. | |
| auto | signature () const -> std::optional< codec::binary > |
| Returns the query signature captured from the response metadata, if present. | |
| auto | meta_data () const -> std::future< std::pair< error, query_meta_data > > |
| Returns the query metadata. | |
| void | cancel () const |
| Cancels the stream and closes the underlying HTTP connection. | |
| auto | begin () const -> iterator |
| Returns an iterator to the beginning. | |
| auto | end () const -> end_sentinel |
| Returns the end sentinel. | |
A streaming result handle for N1QL queries.
Rows are fetched one at a time via next(). The stream must be fully drained (or cancel() called) before meta_data() resolves. Only a single next() call may be outstanding at a time.
|
default |
|
explicit |
Constructs a query stream result from an internal result.
| internal | the internal result handle |
|
nodiscard |
Returns an iterator to the beginning.
| void cancel | ( | ) | const |
Cancels the stream and closes the underlying HTTP connection.
Simply dropping the last handle before the stream is fully drained also tears the stream down, but if a pull is in flight the underlying connection is not released until that pull settles (up to the inter-read idle timeout). Call cancel() explicitly for prompt, deterministic teardown of the connection and its timers.
Part [2] of the example below consumes only a prefix of a large result and then cancels. The rows that were never pulled are never transferred, so the cost of a prefix read is proportional to the prefix rather than to the full result:
After cancel(), next() reports request_canceled — a terminal that has to be told apart from a genuine failure. Rows consumed before the cancel remain valid:
|
nodiscard |
|
nodiscard |
Returns the query metadata.
The returned future resolves only after the stream has been fully drained (all rows consumed or the stream cancelled). May be called more than once; each call returns its own future and all of them resolve together once the metadata becomes available.
If the stream ended with an error, or was torn down by cancel() before reaching a natural terminal, the returned future resolves with that error instead of waiting for a trailer that will never arrive:
Fetches the next row, returning a future.
Only one outstanding call is allowed at a time.
A failure reaches the caller through one of two channels — the error returned by the originating query_stream() (the request never started) or the stream's terminal delivered here. Which one fires is not fixed, so both have to be handled. Once a terminal has been reached it is re-delivered on every further call rather than blocking on a drained stream:
| void next | ( | query_row_handler && | handler | ) | const |
Fetches the next row asynchronously, invoking the handler when ready.
The handler receives ({}, row) for a real row, ({}, {}) at clean end-of-stream, or (error, {}) if the stream ended with an error.
Only one outstanding call is allowed at a time.
This is the overload to use from a completion handler: issuing the following pull from inside the handler drains the stream without ever blocking a thread.
| handler | callable that implements query_row_handler |
|
nodiscard |
Returns the query signature captured from the response metadata, if present.
The signature is part of the response preamble, so — unlike meta_data() — it is available as soon as the stream has started, without draining it first: