13 #ifndef PQXX_H_STREAM_FROM 14 #define PQXX_H_STREAM_FROM 20 #include "pqxx/connection.hxx" 21 #include "pqxx/except.hxx" 22 #include "pqxx/internal/concat.hxx" 23 #include "pqxx/internal/encoding_group.hxx" 24 #include "pqxx/internal/stream_iterator.hxx" 25 #include "pqxx/separated_list.hxx" 26 #include "pqxx/transaction_focus.hxx" 75 std::pair<std::unique_ptr<char, std::function<void(char *)>>, std::size_t>;
89 #include "pqxx/internal/ignore-deprecated-pre.hxx" 91 #include "pqxx/internal/ignore-deprecated-post.hxx" 124 std::string_view columns =
""sv);
131 std::initializer_list<std::string_view> columns = {});
137 [[deprecated(
"Use query() factory instead.")]] stream_from(
138 transaction_base &, from_query_t, std::string_view query);
143 [[deprecated(
"Use table() or raw_table() factory instead.")]] stream_from(
144 transaction_base &, from_table_t, std::string_view table);
149 template<
typename Iter>
150 [[deprecated(
"Use table() or raw_table() factory instead.")]] stream_from(
151 transaction_base &, from_table_t, std::string_view table,
152 Iter columns_begin, Iter columns_end);
157 template<
typename Columns>
158 [[deprecated(
"Use table() or raw_table() factory instead.")]] stream_from(
159 transaction_base &tx, from_table_t, std::string_view table,
160 Columns
const &columns);
162 #include "pqxx/internal/ignore-deprecated-pre.hxx" 164 [[deprecated(
"Use the from_table_t overload instead.")]]
stream_from(
168 #include "pqxx/internal/ignore-deprecated-post.hxx" 171 template<
typename Columns>
172 [[deprecated(
"Use the from_table_t overload instead.")]]
stream_from(
178 template<
typename Iter>
179 [[deprecated(
"Use the from_table_t overload instead.")]] stream_from(
180 transaction_base &, std::string_view table, Iter columns_begin,
183 ~stream_from() noexcept;
186 [[nodiscard]] operator
bool() const noexcept {
return not m_finished; }
188 [[nodiscard]]
bool operator!() const noexcept {
return m_finished; }
207 template<
typename Tuple>
stream_from &operator>>(Tuple &);
210 template<
typename... Vs>
211 stream_from &operator>>(std::variant<Vs...> &) =
delete;
218 template<
typename... TYPE> [[nodiscard]]
auto iter() &
220 return pqxx::internal::stream_input_iteration<TYPE...>{*
this};
240 std::vector<zview>
const *read_row() &;
244 raw_line get_raw_line();
259 template<
typename Tuple, std::size_t... indexes>
260 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const 262 (extract_value<Tuple, indexes>(t), ...);
265 pqxx::internal::glyph_scanner_func *m_glyph_scanner;
271 std::vector<zview> m_fields;
273 bool m_finished =
false;
277 template<
typename Tuple, std::
size_t index>
278 void extract_value(Tuple &)
const;
285 template<
typename Columns>
288 Columns
const &columns) :
290 tx,
from_table, table_name, std::begin(columns), std::end(columns)}
294 template<
typename Iter>
297 Iter columns_begin, Iter columns_end) :
309 constexpr
auto tup_size{std::tuple_size_v<Tuple>};
310 m_fields.reserve(tup_size);
315 if (std::size(m_fields) != tup_size)
317 "Tried to extract ", tup_size,
" field(s) from a stream of ",
318 std::size(m_fields),
".")};
320 extract_fields(t, std::make_index_sequence<tup_size>{});
325 template<
typename Tuple, std::
size_t index>
326 inline void stream_from::extract_value(Tuple &t)
const 330 assert(index < std::size(m_fields));
331 if constexpr (nullity::always_null)
333 if (std::data(m_fields[index]) !=
nullptr)
336 else if (std::data(m_fields[index]) ==
nullptr)
338 if constexpr (nullity::has_null)
339 std::get<index>(t) = nullity::null();
346 std::get<index>(t) = from_string<field_type>(m_fields[index]);
constexpr from_table_t from_table
Pass this to a stream_from constructor to stream table contents.
Definition: stream_from.hxx:31
Stream data from the database.
Definition: stream_from.hxx:71
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:161
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:72
bool operator!() const noexcept
Has this stream produced all the data it is going to produce?
Definition: stream_from.hxx:188
void PQXX_COLD throw_null_conversion(std::string const &type)
Definition: strconv.cxx:252
stream_from & operator>>(Tuple &)
Read one row into a tuple.
Definition: stream_from.hxx:304
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:175
Marker for stream_from constructors: "stream from table.".
Definition: types.hxx:63
std::initializer_list< std::string_view > table_path
Representation of a PostgreSQL table path.
Definition: connection.hxx:119
stream_from(transaction_base &tx, std::string_view table, Columns const &columns)
End a code block started by "ignore-deprecated-pre.hxx".
Definition: stream_from.hxx:172
static stream_from query(transaction_base &tx, std::string_view q)
Factory: Execute query, and stream the results.
Definition: stream_from.hxx:87
Base class for things that monopolise a transaction's attention.
Definition: transaction_focus.hxx:24
static stream_from table(transaction_base &tx, table_path path, std::initializer_list< std::string_view > columns={})
Factory: Stream data from a given table.
Definition: stream_from.cxx:86
constexpr from_query_t from_query
Pass this to a stream_from constructor to stream query results.
Definition: stream_from.hxx:43
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: types.hxx:87
Marker for stream_from constructors: "stream from query.".
Definition: types.hxx:69
stream_from(transaction_base &, from_query_t, std::string_view query)
Execute query, and stream over the results.
Definition: stream_from.cxx:37
std::string separated_list(std::string_view sep, ITER begin, ITER end, ACCESS access)
Represent sequence of values as a string, joined by a given separator.
Definition: separated_list.hxx:39
auto iter() &
Iterate over this stream. Supports range-based "for" loops.
Definition: stream_from.hxx:218
stream_from(transaction_base &tx, std::string_view table)
Definition: stream_from.hxx:164
std::pair< std::unique_ptr< char, std::function< void(char *)> >, std::size_t > raw_line
Definition: stream_from.hxx:75
Traits describing a type's "null value," if any.
Definition: strconv.hxx:88