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>."
35class transaction_base;
83 std::pair<std::unique_ptr<char, void (*)(
void const *)>, std::size_t>;
85 stream_from(stream_from &&) =
delete;
86 stream_from &operator=(stream_from &&) =
delete;
98 [[deprecated(
"Use transaction_base::stream instead.")]]
static stream_from
99 query(transaction_base &tx, std::string_view q)
134 [[deprecated(
"Use transaction_base::stream instead.")]]
static stream_from
136 transaction_base &tx, std::string_view path,
137 std::string_view columns =
""sv);
142 [[deprecated(
"Use transaction_base::stream instead.")]]
static stream_from
145 std::initializer_list<std::string_view> columns = {});
151 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
152 transaction_base &,
from_query_t, std::string_view query);
157 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
158 transaction_base &,
from_table_t, std::string_view table);
163 template<
typename Iter>
164 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
165 transaction_base &,
from_table_t, std::string_view table,
166 Iter columns_begin, Iter columns_end);
171 template<
typename Columns>
172 [[deprecated(
"Use transaction_base::stream() instead.")]] stream_from(
173 transaction_base &tx,
from_table_t, std::string_view table,
174 Columns
const &columns);
178 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
179 transaction_base &tx, std::string_view table) :
185 template<
typename Columns>
186 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
187 transaction_base &tx, std::string_view table, Columns
const &columns) :
192 template<
typename Iter>
193 [[deprecated(
"Use transaction_base::stream instead.")]] stream_from(
194 transaction_base &, std::string_view table, Iter columns_begin,
197 ~stream_from()
noexcept;
200 [[nodiscard]]
constexpr operator bool()
const noexcept
202 return not m_finished;
205 [[nodiscard]]
constexpr bool operator!()
const noexcept
227 template<
typename Tuple> stream_from &operator>>(Tuple &);
230 template<
typename... Vs>
231 stream_from &operator>>(std::variant<Vs...> &) =
delete;
238 template<
typename... TYPE> [[nodiscard]]
auto iter() &
260 std::vector<zview>
const *read_row() &;
264 raw_line get_raw_line();
270 transaction_base &tx, std::string_view table, std::string_view columns,
276 transaction_base &, std::string_view unquoted_table,
279 template<
typename Tuple, std::size_t... indexes>
280 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const
282 (extract_value<Tuple, indexes>(t), ...);
291 std::vector<zview> m_fields;
293 bool m_finished =
false;
297 template<
typename Tuple, std::
size_t index>
298 void extract_value(Tuple &)
const;
305template<
typename Columns>
306inline stream_from::stream_from(
307 transaction_base &tx, from_table_t, std::string_view table_name,
308 Columns
const &columns) :
310 tx,
from_table, table_name, std::begin(columns), std::end(columns)}
314template<
typename Iter>
315inline stream_from::stream_from(
316 transaction_base &tx, from_table_t, std::string_view table,
317 Iter columns_begin, Iter columns_end) :
324template<
typename Tuple>
inline stream_from &stream_from::operator>>(Tuple &t)
328 static constexpr auto tup_size{std::tuple_size_v<Tuple>};
329 m_fields.reserve(tup_size);
334 if (std::size(m_fields) != tup_size)
335 throw usage_error{internal::concat(
336 "Tried to extract ", tup_size,
" field(s) from a stream of ",
337 std::size(m_fields),
".")};
339 extract_fields(t, std::make_index_sequence<tup_size>{});
344template<
typename Tuple, std::
size_t index>
345inline void stream_from::extract_value(Tuple &t)
const
347 using field_type = strip_t<decltype(std::get<index>(t))>;
348 using nullity = nullness<field_type>;
349 assert(index < std::size(m_fields));
350 if constexpr (nullity::always_null)
352 if (std::data(m_fields[index]) !=
nullptr)
353 throw conversion_error{
"Streaming non-null value into null field."};
355 else if (std::data(m_fields[index]) ==
nullptr)
357 if constexpr (nullity::has_null)
358 std::get<index>(t) = nullity::null();
360 internal::throw_null_conversion(type_name<field_type>);
365 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:45
constexpr from_table_t from_table
Pass this to a stream_from constructor to stream table contents.
Definition stream_from.hxx:41
std::initializer_list< std::string_view > table_path
Representation of a PostgreSQL table path.
Definition connection.hxx:232
Marker for stream_from constructors: "stream from query.".
Definition types.hxx:171
Marker for stream_from constructors: "stream from table.".
Definition types.hxx:165