Skip to content

Commit

Permalink
Streamline stream_to constructors.
Browse files Browse the repository at this point in the history
Retires a `TODO`: Fold `set_up` into the basic "raw table" constructor,
and have the other constructors delegate to it.
  • Loading branch information
jtv committed Feb 12, 2021
1 parent eac1052 commit 5148d9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
4 changes: 2 additions & 2 deletions include/pqxx/stream_from.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ private:

template<typename Columns>
inline stream_from::stream_from(
transaction_base &tb, from_table_t, std::string_view table_name,
transaction_base &tx, from_table_t, std::string_view table_name,
Columns const &columns) :
stream_from{
tb, from_table, table_name, std::begin(columns), std::end(columns)}
tx, from_table, table_name, std::begin(columns), std::end(columns)}
{}


Expand Down
36 changes: 15 additions & 21 deletions include/pqxx/stream_to.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ public:
* in an "implicit contract" between your code and your schema.
*/
PQXX_DEPRECATED("Use table() or raw_table() factory.")
stream_to(transaction_base &, std::string_view table_name);
stream_to(transaction_base &tx, std::string_view table_name) :
stream_to{tx, table_name, ""sv}
{}

/// Create a stream, specifying column names as a container of strings.
/** @deprecated Use @c table() or @c raw_table() as a factory.
Expand Down Expand Up @@ -218,12 +220,9 @@ public:
}

private:
/// Stream a pre-quoted table name and columns list.
stream_to(
transaction_base &tx, std::string_view path, std::string_view columns) :
transaction_focus{tx, s_classname, path}
{
set_up(tx, path, columns);
}
transaction_base &tx, std::string_view path, std::string_view columns);

bool m_finished = false;

Expand Down Expand Up @@ -371,11 +370,6 @@ private:
append_tuple(t, indexes{});
}

// TODO: Fold into raw_table().
void set_up(
transaction_base &, std::string_view table_name,
std::string_view columns = ""sv);

/// Write raw COPY line into @c m_buffer, based on varargs fields.
template<typename... Ts> void fill_buffer(const Ts &...fields)
{
Expand All @@ -388,23 +382,23 @@ private:

template<typename Columns>
inline stream_to::stream_to(
transaction_base &tb, std::string_view table_name, Columns const &columns) :
stream_to{tb, table_name, std::begin(columns), std::end(columns)}
transaction_base &tx, std::string_view table_name, Columns const &columns) :
stream_to{tx, table_name, std::begin(columns), std::end(columns)}
{}


template<typename Iter>
inline stream_to::stream_to(
transaction_base &tx, std::string_view table_name, Iter columns_begin,
Iter columns_end) :
transaction_focus{tx, s_classname, table_name}
{
set_up(
tx, tx.quote_name(table_name),
separated_list(",", columns_begin, columns_end, [&tx](auto col) {
return tx.quote_name(*col);
}));
}
stream_to{
tx,
tx.quote_name(
table_name,
separated_list(",", columns_begin, columns_end, [&tx](auto col) {
return tx.quote_name(*col);
}))}
{}
} // namespace pqxx

#include "pqxx/internal/compiler-internal-post.hxx"
Expand Down
14 changes: 4 additions & 10 deletions src/stream_to.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ void begin_copy(
} // namespace


pqxx::stream_to::stream_to(transaction_base &tb, std::string_view table_name) :
transaction_focus{tb, s_classname, table_name}
{
set_up(tb, table_name);
}


pqxx::stream_to::~stream_to() noexcept
{
try
Expand Down Expand Up @@ -85,10 +78,11 @@ pqxx::stream_to &pqxx::stream_to::operator<<(stream_from &tr)
}


void pqxx::stream_to::set_up(
transaction_base &tb, std::string_view table_name, std::string_view columns)
pqxx::stream_to::stream_to(
transaction_base &tx, std::string_view path, std::string_view columns) :
transaction_focus{tx, s_classname, path}
{
begin_copy(tb, table_name, columns);
begin_copy(tx, path, columns);
register_me();
}

Expand Down

0 comments on commit 5148d9e

Please sign in to comment.