13#ifndef PQXX_H_STREAM_FROM
14#define PQXX_H_STREAM_FROM
16#if !defined(PQXX_HEADER_PRE)
17# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
23#include "pqxx/connection.hxx"
24#include "pqxx/except.hxx"
25#include "pqxx/internal/concat.hxx"
26#include "pqxx/internal/encoding_group.hxx"
27#include "pqxx/internal/stream_iterator.hxx"
28#include "pqxx/separated_list.hxx"
29#include "pqxx/transaction_focus.hxx"
34class transaction_base;
82 std::pair<std::unique_ptr<char, void (*)(
void const *)>, std::size_t>;
84 stream_from(stream_from &&) =
delete;
85 stream_from &operator=(stream_from &&) =
delete;
97 [[deprecated(
"Use transaction_base::stream instead.")]]
static stream_from
98 query(transaction_base &tx, std::string_view q)
100#include "pqxx/internal/ignore-deprecated-pre.hxx"
102#include "pqxx/internal/ignore-deprecated-post.hxx"
133 [[deprecated(
"Use transaction_base::stream instead.")]]
static stream_from
135 transaction_base &tx, std::string_view path,
136 std::string_view columns =
""sv);
141 [[deprecated(
"Use transaction_base::stream instead.")]]
static stream_from
144 std::initializer_list<std::string_view> columns = {});
150 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
151 transaction_base &,
from_query_t, std::string_view query);
156 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
157 transaction_base &,
from_table_t, std::string_view table);
162 template<
typename Iter>
163 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
164 transaction_base &,
from_table_t, std::string_view table,
165 Iter columns_begin, Iter columns_end);
170 template<
typename Columns>
171 [[deprecated(
"Use transaction_base::stream() instead.")]] stream_from(
172 transaction_base &tx,
from_table_t, std::string_view table,
173 Columns
const &columns);
175#include "pqxx/internal/ignore-deprecated-pre.hxx"
177 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
178 transaction_base &tx, std::string_view table) :
181#include "pqxx/internal/ignore-deprecated-post.hxx"
184 template<
typename Columns>
185 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
186 transaction_base &tx, std::string_view table, Columns
const &columns) :
191 template<
typename Iter>
192 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
193 transaction_base &, std::string_view table, Iter columns_begin,
196 ~stream_from()
noexcept;
199 [[nodiscard]]
constexpr operator bool()
const noexcept
201 return not m_finished;
204 [[nodiscard]]
constexpr bool operator!()
const noexcept
226 template<
typename Tuple> stream_from &operator>>(Tuple &);
229 template<
typename... Vs>
230 stream_from &operator>>(std::variant<Vs...> &) =
delete;
237 template<
typename... TYPE> [[nodiscard]]
auto iter() &
259 std::vector<zview>
const *read_row() &;
263 raw_line get_raw_line();
269 transaction_base &tx, std::string_view table, std::string_view columns,
275 transaction_base &, std::string_view unquoted_table,
278 template<
typename Tuple, std::size_t... indexes>
279 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const
281 (extract_value<Tuple, indexes>(t), ...);
290 std::vector<zview> m_fields;
292 bool m_finished =
false;
296 template<
typename Tuple, std::
size_t index>
297 void extract_value(Tuple &)
const;
304template<
typename Columns>
305inline stream_from::stream_from(
306 transaction_base &
tx, from_table_t, std::string_view
table_name,
313template<
typename Iter>
314inline stream_from::stream_from(
315 transaction_base &tx, from_table_t, std::string_view table,
316 Iter columns_begin, Iter columns_end) :
323template<
typename Tuple>
inline stream_from &stream_from::operator>>(Tuple &t)
326 PQXX_UNLIKELY
return *
this;
327 static constexpr auto tup_size{std::tuple_size_v<Tuple>};
328 m_fields.reserve(tup_size);
331 PQXX_UNLIKELY
return *
this;
333 if (std::size(m_fields) != tup_size)
334 throw usage_error{internal::concat(
335 "Tried to extract ", tup_size,
" field(s) from a stream of ",
336 std::size(m_fields),
".")};
338 extract_fields(t, std::make_index_sequence<tup_size>{});
343template<
typename Tuple, std::
size_t index>
344inline void stream_from::extract_value(Tuple &t)
const
346 using field_type = strip_t<decltype(std::get<index>(t))>;
347 using nullity = nullness<field_type>;
348 assert(index < std::size(m_fields));
349 if constexpr (nullity::always_null)
351 if (std::data(m_fields[index]) !=
nullptr)
352 throw conversion_error{
"Streaming non-null value into null field."};
354 else if (std::data(m_fields[index]) ==
nullptr)
356 if constexpr (nullity::has_null)
357 std::get<index>(t) = nullity::null();
359 internal::throw_null_conversion(type_name<field_type>);
364 std::get<index>(t) = from_string<field_type>(m_fields[index]);
Base class for things that monopolise a transaction's attention.
Definition transaction_focus.hxx:29
std::size_t(std::string_view haystack, std::size_t start) char_finder_func
Function type: "find first occurrence of specific any of ASCII characters.".
Definition encoding_group.hxx:70
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
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:46
constexpr from_query_t from_query
Pass this to a stream_from constructor to stream query results.
Definition stream_from.hxx:44
constexpr char array_separator
Element separator between SQL array elements of this type.
Definition strconv.hxx:559
constexpr from_table_t from_table
Pass this to a stream_from constructor to stream table contents.
Definition stream_from.hxx:40
std::initializer_list< std::string_view > table_path
Representation of a PostgreSQL table path.
Definition connection.hxx:231
Marker for stream_from constructors: "stream from query.".
Definition types.hxx:171
Marker for stream_from constructors: "stream from table.".
Definition types.hxx:165