relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
Loading...
Searching...
No Matches
relx::connection::AsyncStreamingResultSet< DataSource > Class Template Reference

Async streaming result set that yields rows asynchronously. More...

#include <relx/connection/postgresql_async_streaming_source.hpp>

Classes

class  async_streaming_iterator
 Iterator that reads data on demand asynchronously. More...
 

Public Member Functions

 AsyncStreamingResultSet (DataSource source)
 
 ~AsyncStreamingResultSet ()
 Destructor that ensures cleanup when result set goes out of scope.
 
 AsyncStreamingResultSet (const AsyncStreamingResultSet &)=delete
 
AsyncStreamingResultSetoperator= (const AsyncStreamingResultSet &)=delete
 
 AsyncStreamingResultSet (AsyncStreamingResultSet &&other) noexcept
 
AsyncStreamingResultSetoperator= (AsyncStreamingResultSet &&other) noexcept
 
async_streaming_iterator begin ()
 Begin async iteration.
 
async_streaming_iterator end ()
 End marker for async iteration.
 
template<typename Func >
boost::asio::awaitable< void > for_each (Func &&func)
 Process all rows with an async callback.
 
boost::asio::awaitable< void > cleanup ()
 Explicitly cleanup the streaming source.
 
boost::asio::awaitable< void > auto_reset_connection_state ()
 Internal method to automatically reset connection state (called only once)
 

Detailed Description

template<typename DataSource>
class relx::connection::AsyncStreamingResultSet< DataSource >

Async streaming result set that yields rows asynchronously.

Definition at line 126 of file postgresql_async_streaming_source.hpp.

Constructor & Destructor Documentation

◆ AsyncStreamingResultSet() [1/3]

template<typename DataSource >
relx::connection::AsyncStreamingResultSet< DataSource >::AsyncStreamingResultSet ( DataSource  source)
inline

Definition at line 163 of file postgresql_async_streaming_source.hpp.

◆ ~AsyncStreamingResultSet()

template<typename DataSource >
relx::connection::AsyncStreamingResultSet< DataSource >::~AsyncStreamingResultSet ( )
inline

Destructor that ensures cleanup when result set goes out of scope.

Definition at line 166 of file postgresql_async_streaming_source.hpp.

◆ AsyncStreamingResultSet() [2/3]

template<typename DataSource >
relx::connection::AsyncStreamingResultSet< DataSource >::AsyncStreamingResultSet ( const AsyncStreamingResultSet< DataSource > &  )
delete

◆ AsyncStreamingResultSet() [3/3]

template<typename DataSource >
relx::connection::AsyncStreamingResultSet< DataSource >::AsyncStreamingResultSet ( AsyncStreamingResultSet< DataSource > &&  other)
inlinenoexcept

Definition at line 182 of file postgresql_async_streaming_source.hpp.

Member Function Documentation

◆ auto_reset_connection_state()

template<typename DataSource >
boost::asio::awaitable< void > relx::connection::AsyncStreamingResultSet< DataSource >::auto_reset_connection_state ( )
inline

Internal method to automatically reset connection state (called only once)

Returns
Awaitable that resolves when reset is complete

Definition at line 344 of file postgresql_async_streaming_source.hpp.

◆ begin()

template<typename DataSource >
async_streaming_iterator relx::connection::AsyncStreamingResultSet< DataSource >::begin ( )
inline

Begin async iteration.

Definition at line 205 of file postgresql_async_streaming_source.hpp.

◆ cleanup()

template<typename DataSource >
boost::asio::awaitable< void > relx::connection::AsyncStreamingResultSet< DataSource >::cleanup ( )
inline

Explicitly cleanup the streaming source.

Returns
Awaitable that resolves when cleanup is complete

Definition at line 337 of file postgresql_async_streaming_source.hpp.

◆ end()

template<typename DataSource >
async_streaming_iterator relx::connection::AsyncStreamingResultSet< DataSource >::end ( )
inline

End marker for async iteration.

Definition at line 208 of file postgresql_async_streaming_source.hpp.

◆ for_each()

template<typename DataSource >
template<typename Func >
boost::asio::awaitable< void > relx::connection::AsyncStreamingResultSet< DataSource >::for_each ( Func &&  func)
inline

Process all rows with an async callback.

This method is the recommended way to iterate over async streaming results.

Why for_each is needed instead of range-based for loops:

Async streaming cannot use standard C++ range-based for loops because:

  1. Each row fetch is an async operation that must be awaited
  2. Range-based for loops expect synchronous iterators with immediate operator++()
  3. The async advance() method returns boost::asio::awaitable<void>

Usage Examples:

// Basic processing (void return):
co_await result.for_each([](const auto& row) {
auto id = row.get<int>("id");
std::cout << "Processing ID: " << id << std::endl;
});
// Early termination (bool return - true breaks):
co_await result.for_each([](const auto& row) -> bool {
auto id = row.get<int>("id");
std::cout << "Processing ID: " << id << std::endl;
return id > 1000; // Break when ID exceeds 1000
});
// Async processing:
co_await result.for_each([](const auto& row) -> boost::asio::awaitable<void> {
auto id = row.get<int>("id");
co_await some_async_operation(id);
});
// Async processing with early termination:
co_await result.for_each([](const auto& row) -> boost::asio::awaitable<bool> {
auto id = row.get<int>("id");
co_await some_async_operation(id);
return should_stop_processing(id); // Return true to break
});

Manual Iteration (for finer-grained control):

If you need more control over the iteration process, you can use manual iteration:

auto it = result.begin();
co_await it.advance(); // Get first row
while (!it.is_at_end()) {
const auto& row = *it;
// Your custom processing logic here
auto id = row.get<int>("id");
// Custom break conditions
if (some_complex_condition(row)) {
break;
}
// Custom error handling
try {
co_await it.advance();
} catch (const std::exception& e) {
// Handle iteration errors
break;
}
}
Template Parameters
FuncFunction type - can be sync/async, void/bool return
Parameters
funcCallback function to process each row
  • Signature: void(const LazyRow&) - Process each row
  • Signature: bool(const LazyRow&) - Process each row, return true to break
  • Signature: boost::asio::awaitable<void>(const LazyRow&) - Async processing
  • Signature: boost::asio::awaitable<bool>(const LazyRow&) - Async processing with early termination
Returns
Awaitable that resolves when all rows are processed or early termination occurs

Definition at line 286 of file postgresql_async_streaming_source.hpp.

◆ operator=() [1/2]

template<typename DataSource >
AsyncStreamingResultSet & relx::connection::AsyncStreamingResultSet< DataSource >::operator= ( AsyncStreamingResultSet< DataSource > &&  other)
inlinenoexcept

Definition at line 187 of file postgresql_async_streaming_source.hpp.

◆ operator=() [2/2]

template<typename DataSource >
AsyncStreamingResultSet & relx::connection::AsyncStreamingResultSet< DataSource >::operator= ( const AsyncStreamingResultSet< DataSource > &  )
delete

The documentation for this class was generated from the following file: