libpqxx  7.1.1
pqxx::stream_from Class Reference

Stream data from the database. More...

#include <stream_from.hxx>

Inheritance diagram for pqxx::stream_from:

Public Types

using raw_line = std::pair< std::unique_ptr< char, std::function< void(char *)> >, std::size_t >
 

Public Member Functions

 stream_from (transaction_base &, from_query_t, std::string_view query)
 Execute query, and stream over the results. More...
 
 stream_from (transaction_base &, from_table_t, std::string_view table)
 Stream all rows in table, all columns. More...
 
template<typename Iter >
 stream_from (transaction_base &, from_table_t, std::string_view table, Iter columns_begin, Iter columns_end)
 Stream given columns from all rows in table. More...
 
template<typename Columns >
 stream_from (transaction_base &tx, from_table_t, std::string_view table, Columns const &columns)
 Stream given columns from all rows in table. More...
 
 stream_from (transaction_base &tx, std::string_view table)
 
template<typename Columns >
 stream_from (transaction_base &tx, std::string_view table, Columns const &columns)
 
template<typename Iter >
 stream_from (transaction_base &, std::string_view table, Iter columns_begin, Iter columns_end)
 
 ~stream_from () noexcept
 
 operator bool () const noexcept
 
bool operator! () const noexcept
 
void complete ()
 Finish this stream. Call this before continuing to use the connection. More...
 
raw_line get_raw_line ()
 Read one row into a tuple. More...
 
template<typename Tuple >
stream_fromoperator>> (Tuple &)
 
template<typename... Vs>
stream_fromoperator>> (std::variant< Vs... > &)=delete
 Doing this with a std::variant is going to be horrifically borked. More...
 
template<typename... TYPE>
auto iter ()
 Iterate over this stream. Supports range-based "for" loops. More...
 

Detailed Description

Stream data from the database.

Retrieving data this way is likely to be faster than executing a query and then iterating and converting the rows fields. You will also be able to start processing before all of the data has come in.

There are also downsides. If there's an error, it may leave the entire connection in an unusable state, so you'll have to give the whole thing up. Also, your connection to the database may break before you've received all the data, so you may end up processing only part of the data. Finally, opening a stream puts the connection in a special state, so you won't be able to do many other things with the connection or the transaction while the stream is open.

There are two ways of starting a stream: you stream either all rows in a table (in which case, use a constructor which accepts pqxx::from_table), or the results of a query (in which case, use a concstructor which accepts pqxx::from_query).

Usually you'll want the stream convenience wrapper in transaction_base, so you don't need to deal with this class directly.

Member Typedef Documentation

◆ raw_line

using pqxx::stream_from::raw_line = std::pair<std::unique_ptr<char, std::function<void(char *)> >, std::size_t>

Constructor & Destructor Documentation

◆ stream_from() [1/7]

pqxx::stream_from::stream_from ( transaction_base tx,
from_query_t  ,
std::string_view  query 
)

Execute query, and stream over the results.

The query can be a SELECT query or a VALUES query; or it can be an UPDATE, INSERT, or DELETE with a RETURNING clause.

The query is executed as part of a COPY statement, so there are additional restrictions on what kind of query you can use here. See the PostgreSQL documentation for the COPY command:

https://www.postgresql.org/docs/current/sql-copy.html

References pqxx::transaction_base::exec0().

Referenced by stream_from().

◆ stream_from() [2/7]

pqxx::stream_from::stream_from ( transaction_base tx,
from_table_t  ,
std::string_view  table 
)

Stream all rows in table, all columns.

References pqxx::transaction_base::exec0(), and stream_from().

◆ stream_from() [3/7]

template<typename Iter >
pqxx::stream_from::stream_from ( transaction_base tx,
from_table_t  ,
std::string_view  table,
Iter  columns_begin,
Iter  columns_end 
)

Stream given columns from all rows in table.

References pqxx::separated_list().

◆ stream_from() [4/7]

template<typename Columns >
pqxx::stream_from::stream_from ( transaction_base tx,
from_table_t  ,
std::string_view  table,
Columns const &  columns 
)

Stream given columns from all rows in table.

References pqxx::from_table.

◆ stream_from() [5/7]

pqxx::stream_from::stream_from ( transaction_base tx,
std::string_view  table 
)
Deprecated:
Use the from_table_t overload instead.

References pqxx::from_table.

◆ stream_from() [6/7]

template<typename Columns >
pqxx::stream_from::stream_from ( transaction_base tx,
std::string_view  table,
Columns const &  columns 
)
Deprecated:
Use the from_table_t overload instead.

References pqxx::from_table.

◆ stream_from() [7/7]

template<typename Iter >
pqxx::stream_from::stream_from ( transaction_base ,
std::string_view  table,
Iter  columns_begin,
Iter  columns_end 
)
Deprecated:
Use the from_table_t overload instead.

◆ ~stream_from()

pqxx::stream_from::~stream_from ( )
noexcept

Member Function Documentation

◆ complete()

void pqxx::stream_from::complete ( )

Finish this stream. Call this before continuing to use the connection.

Consumes all remaining lines, and closes the stream.

This may take a while if you're abandoning the stream before it's done, so skip it in error scenarios where you're not planning to use the connection again afterwards.

References get_raw_line(), and pqxx::ignore_unused().

◆ get_raw_line()

pqxx::stream_from::raw_line pqxx::stream_from::get_raw_line ( )

Read one row into a tuple.

Converts the row's fields into the fields making up the tuple.

For a column which can contain nulls, be sure to give the corresponding tuple field a type which can be null. For example, to read a field as int when it may contain nulls, read it as std::optional<int>. Using std::shared_ptr or std::unique_ptr will also work.

Referenced by complete(), and pqxx::stream_to::operator<<().

◆ iter()

template<typename... TYPE>
auto pqxx::stream_from::iter ( )

Iterate over this stream. Supports range-based "for" loops.

Produces an input iterator over the stream.

Do not call this yourself. Use it like "for (auto data : stream.iter())".

◆ operator bool()

pqxx::stream_from::operator bool ( ) const
noexcept

◆ operator!()

bool pqxx::stream_from::operator! ( ) const
noexcept

◆ operator>>() [1/2]

template<typename Tuple >
stream_from & pqxx::stream_from::operator>> ( Tuple &  t)

◆ operator>>() [2/2]

template<typename... Vs>
stream_from& pqxx::stream_from::operator>> ( std::variant< Vs... > &  )
delete

Doing this with a std::variant is going to be horrifically borked.


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