3#include "../results/streaming_result.hpp"
28 std::vector<std::string> params = {});
36 std::vector<std::string> params, std::vector<bool> is_binary);
73 std::vector<std::string> params_;
74 std::vector<bool> is_binary_;
77 std::vector<std::string> column_names_;
78 std::vector<bool> is_bytea_column_;
87 std::optional<std::string> first_row_cached_;
94 void process_column_metadata(
struct pg_result* pg_result);
99 std::optional<std::string> format_row(
struct pg_result* pg_result);
104 std::string convert_pg_bytea_to_binary(
const std::string& hex_value)
const;
115template <
typename... Args>
119 std::vector<std::string> param_strings;
120 if constexpr (
sizeof...(Args) > 0) {
121 param_strings.reserve(
sizeof...(Args));
123 auto add_param = [¶m_strings](
auto&& param) {
124 using ParamType = std::remove_cvref_t<
decltype(param)>;
126 if constexpr (std::is_same_v<ParamType, std::nullptr_t>) {
127 param_strings.push_back(
"NULL");
128 }
else if constexpr (std::is_same_v<ParamType, std::string> ||
129 std::is_same_v<ParamType, const char*> ||
130 std::is_same_v<ParamType, std::string_view>) {
131 param_strings.push_back(std::string(param));
132 }
else if constexpr (std::is_arithmetic_v<ParamType>) {
133 param_strings.push_back(std::to_string(param));
134 }
else if constexpr (std::is_same_v<ParamType, bool>) {
135 param_strings.push_back(param ?
"t" :
"f");
137 std::ostringstream ss;
139 param_strings.push_back(ss.str());
143 (add_param(std::forward<Args>(args)), ...);
PostgreSQL implementation of the Connection interface.
PostgreSQL streaming data source for processing large result sets.
PostgreSQLStreamingSource(PostgreSQLConnection &connection, std::string sql, std::vector< std::string > params={})
Constructor with connection and query parameters.
bool has_more_rows() const
Check if there are more rows available.
const std::vector< std::string > & get_column_names() const
Get the column names for the result set.
PostgreSQLStreamingSource & operator=(const PostgreSQLStreamingSource &)=delete
PostgreSQLStreamingSource(PostgreSQLStreamingSource &&other) noexcept
std::optional< std::string > get_next_row()
Get the next row from the result set.
~PostgreSQLStreamingSource()
Destructor that cleans up any active query.
ConnectionResult< void > initialize()
Initialize the streaming query.
PostgreSQLStreamingSource & operator=(PostgreSQLStreamingSource &&other) noexcept
PostgreSQLStreamingSource(const PostgreSQLStreamingSource &)=delete
bool is_initialized() const
Check if the streaming source has been initialized.
PostgreSQLStreamingSource(PostgreSQLConnection &connection, std::string sql, std::vector< std::string > params, std::vector< bool > is_binary)
Constructor with connection and binary query parameters.
Streaming result set for very large datasets.
result::StreamingResultSet< PostgreSQLStreamingSource > create_streaming_result(PostgreSQLConnection &connection, const std::string &sql, Args &&... args)
Create a streaming result set from a PostgreSQL connection and query.
std::expected< T, ConnectionError > ConnectionResult
Type alias for result of connection operations.