13 #ifndef PQXX_H_STREAM_FROM
14 #define PQXX_H_STREAM_FROM
16 #include "pqxx/compiler-public.hxx"
17 #include "pqxx/internal/compiler-internal-pre.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"
34 class transaction_base;
76 std::pair<std::unique_ptr<char, std::function<void(
char *)>>, std::size_t>;
90 #include "pqxx/internal/ignore-deprecated-pre.hxx"
92 #include "pqxx/internal/ignore-deprecated-post.hxx"
125 std::string_view columns =
""sv);
132 std::initializer_list<std::string_view> columns = {});
138 PQXX_DEPRECATED(
"Use query() factory instead.")
144 PQXX_DEPRECATED("Use table() or raw_table() factory instead.")
150 template<typename Iter>
151 PQXX_DEPRECATED("Use table() or raw_table() factory instead.")
154 Iter columns_begin, Iter columns_end);
159 template<typename Columns>
160 PQXX_DEPRECATED("Use table() or raw_table() factory instead.")
163 Columns const &columns);
165 #include "pqxx/internal/ignore-deprecated-pre.hxx"
167 PQXX_DEPRECATED(
"Use the from_table_t overload instead.")
171 #include "pqxx/internal/ignore-deprecated-post.hxx"
174 template<
typename Columns>
175 PQXX_DEPRECATED(
"Use the from_table_t overload instead.")
182 template<
typename Iter>
183 PQXX_DEPRECATED(
"Use the from_table_t overload instead.")
191 [[nodiscard]] operator
bool() const noexcept {
return not m_finished; }
193 [[nodiscard]]
bool operator!() const noexcept {
return m_finished; }
212 template<
typename Tuple>
stream_from &operator>>(Tuple &);
215 template<
typename... Vs>
223 template<
typename... TYPE> [[nodiscard]]
auto iter()
225 return pqxx::internal::stream_input_iteration<TYPE...>{*
this};
245 std::vector<zview>
const *read_row();
249 raw_line get_raw_line();
264 template<
typename Tuple, std::size_t... indexes>
265 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const
267 (extract_value<Tuple, indexes>(t), ...);
270 pqxx::internal::glyph_scanner_func *m_glyph_scanner;
276 std::vector<zview> m_fields;
278 bool m_finished =
false;
282 template<
typename Tuple, std::
size_t index>
283 void extract_value(Tuple &)
const;
290 template<
typename Columns>
293 Columns
const &columns) :
295 tx,
from_table, table_name, std::begin(columns), std::end(columns)}
299 template<
typename Iter>
302 Iter columns_begin, Iter columns_end) :
313 constexpr
auto tup_size{std::tuple_size_v<Tuple>};
314 m_fields.reserve(tup_size);
319 if (std::size(m_fields) != tup_size)
321 "Tried to extract ", tup_size,
" field(s) from a stream of ",
322 std::size(m_fields),
".")};
324 extract_fields(t, std::make_index_sequence<tup_size>{});
329 template<
typename Tuple, std::
size_t index>
330 inline void stream_from::extract_value(Tuple &t)
const
334 assert(index < std::size(m_fields));
335 if constexpr (nullity::always_null)
337 if (m_fields[index].data() !=
nullptr)
340 else if (m_fields[index].data() ==
nullptr)
342 if constexpr (nullity::has_null)
343 std::get<index>(t) = nullity::null();
350 std::get<index>(t) = from_string<field_type>(m_fields[index]);
355 #include "pqxx/internal/compiler-internal-post.hxx"
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
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:42
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: util.hxx:147
constexpr from_query_t from_query
Pass this to a stream_from constructor to stream query results.
Definition: stream_from.hxx:44
constexpr from_table_t from_table
Pass this to a stream_from constructor to stream table contents.
Definition: stream_from.hxx:34
std::initializer_list< std::string_view > table_path
Representation of a PostgreSQL table path.
Definition: connection.hxx:122
void throw_null_conversion(std::string const &type)
Definition: strconv.cxx:242
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:165
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:179
Traits describing a type's "null value," if any.
Definition: strconv.hxx:87
Stream data from the database.
Definition: stream_from.hxx:73
static stream_from query(transaction_base &tx, std::string_view q)
Factory: Execute query, and stream the results.
Definition: stream_from.hxx:88
std::pair< std::unique_ptr< char, std::function< void(char *)> >, std::size_t > raw_line
Definition: stream_from.hxx:76
stream_from & operator>>(Tuple &)
Read one row into a tuple.
Definition: stream_from.hxx:309
stream_from & operator>>(std::variant< Vs... > &)=delete
Doing this with a std::variant is going to be horrifically borked.
bool operator!() const noexcept
Has this stream produced all the data it is going to produce?
Definition: stream_from.hxx:193
auto iter()
Iterate over this stream. Supports range-based "for" loops.
Definition: stream_from.hxx:223
Use the from_table_t overload instead stream_from(transaction_base &tx, std::string_view table)
Definition: stream_from.hxx:168
static stream_from table(transaction_base &tx, table_path path, std::initializer_list< std::string_view > columns={})
Factory: Stream data from a given table.
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:75
Base class for things that monopolise a transaction's attention.
Definition: transaction_focus.hxx:28
Marker for stream_from constructors: "stream from table.".
Definition: types.hxx:58
Marker for stream_from constructors: "stream from query.".
Definition: types.hxx:64