stream_to.hxx
#ifndef PQXX_H_STREAM_TO
#define PQXX_H_STREAM_TO
#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"
#include "pqxx/transaction_base.hxx"
#include "pqxx/stream_base.hxx"
#include "pqxx/stream_from.hxx"
#include "pqxx/internal/type_utils.hxx"
#include <string>
namespace pqxx
{
class PQXX_LIBEXPORT stream_to : public stream_base
{
public:
stream_to(transaction_base &, const std::string &table_name);
template<typename Columns> stream_to(
transaction_base &,
const std::string &table_name,
const Columns& columns
);
template<typename Iter> stream_to(
transaction_base &,
const std::string &table_name,
Iter columns_begin,
Iter columns_end
);
~stream_to() noexcept;
void complete() override;
template<typename Tuple> stream_to & operator<<(const Tuple &);
stream_to &operator<<(stream_from &);
private:
void write_raw_line(const std::string &);
void set_up(transaction_base &, const std::string &table_name);
void set_up(
transaction_base &,
const std::string &table_name,
const std::string &columns
);
void close() override;
};
template<typename Columns> inline stream_to::stream_to(
transaction_base &tb,
const std::string &table_name,
const Columns& columns
) : stream_to{
tb,
table_name,
std::begin(columns),
std::end(columns)
}
{}
template<typename Iter> inline stream_to::stream_to(
transaction_base &tb,
const std::string &table_name,
Iter columns_begin,
Iter columns_end
) :
namedclass{"stream_from", table_name},
stream_base{tb}
{
set_up(
tb,
table_name,
columnlist(columns_begin, columns_end)
);
}
namespace internal
{
class PQXX_LIBEXPORT TypedCopyEscaper
{
static std::string escape(const std::string &);
public:
template<typename T> std::string operator()(const T* t) const
{
return string_traits<T>::is_null(*t) ? "\\N" : escape(to_string(*t));
}
};
// Explicit specialization so we don't need a string_traits<> for nullptr_t
template<> inline std::string TypedCopyEscaper::operator()<std::nullptr_t>(
const std::nullptr_t*
) const
{ return "\\N"; }
} // namespace pqxx::internal
template<typename Tuple> stream_to & stream_to::operator<<(const Tuple &t)
{
write_raw_line(separated_list("\t", t, internal::TypedCopyEscaper()));
return *this;
}
} // namespace pqxx
#include "pqxx/compiler-internal-post.hxx"
#endif
pqxx::internal::TypedCopyEscaper::operator()
std::string operator()(const T *t) const
Definition: stream_to.hxx:167
pqxx::stream_to::stream_to
stream_to(transaction_base &, const std::string &table_name)
Create a stream, without specifying columns.
Definition: stream_to.cxx:18
pqxx::operator<<
std::basic_ostream< CHAR > & operator<<(std::basic_ostream< CHAR > &S, const field &F)
Write a result field to any type of stream.
Definition: field.hxx:355
pqxx::stream_base::close
virtual void close()
Definition: stream_base.cxx:36
pqxx::stream_to
Efficiently write data directly to a database table.
Definition: stream_to.hxx:59
pqxx::stream_from::get_raw_line
bool get_raw_line(std::string &)
Definition: stream_from.cxx:72
pqxx::stream_from
Efficiently pull data directly out of a table.
Definition: stream_from.hxx:29
pqxx::separated_list
std::string separated_list(const std::string &sep, ITER begin, ITER end, ACCESS access)
Represent sequence of values as a string, joined by a given separator.
Definition: util.hxx:95
pqxx::internal::TypedCopyEscaper
Definition: stream_to.hxx:163
pqxx::internal::number_to_digit
constexpr char number_to_digit(int i) noexcept
Definition: strconv.hxx:324
pqxx::internal::escape
std::string escape(const std::string &s, const std::string &null)
Definition: tablewriter.cxx:131
pqxx::stream_to::complete
void complete() override
Complete the operation, and check for errors.
Definition: stream_to.cxx:42
pqxx::stream_to::operator<<
stream_to & operator<<(const Tuple &)
Insert a row of data.
Definition: stream_to.hxx:182
pqxx::to_string
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:451
pqxx::string_traits
Traits class for use in string conversions.
Definition: strconv.hxx:51
pqxx::transaction_base
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:136
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
pqxx::stream_to::~stream_to
~stream_to() noexcept
Definition: stream_to.cxx:29
pqxx::stream_base
Definition: stream_base.hxx:27