OZO 「お象」
Boost.Asio and libpq based asynchronous PostgreSQL unofficial header-only C++17 client library.
BinaryQueryConvertible Interface Reference

#include <ozo/io/binary_query.h>

Description

Concept of a type that is convertible to ozo::binary_query

To be convertible to the ozo::binary_query type should model Query concept or should have a valid ozo::to_binary_query_impl<T> overload.

Customization

A particular query object type may become BinaryQueryConvertible via the specialization of ozo::to_binary_query_impl<T>::apply() template function. By default, it handles any Query model object or binary_query object.

template <typename T>
struct to_binary_query_impl<T> {
template <typename OidMap, typename Allocator>
static binary_query apply(const T&, const OidMap&, const Allocator&);
};

Example

E.g., a custom library contains type-erasure interface for its queries.

namespace demo {
constexpr auto oidMap = ozo::register_types<...>();
using OidMap = decltype(oidMap);
struct Query {
virtual ozo::binary_query toBinaryQuery(const OidMap&, const std::allocator<char>&) const = 0;
virtual ~Query() = 0;
};
} // namespace demo

Then the adaptation should look like this:

namespace ozo {
template <>
struct to_binary_query_impl<demo::Query> {
template <typename OidMap, typename Alloc>
static binary_query apply(const demo::Query& query, const demo::OidMap& oid_map, const std::allocator<char>& alloc) {
return query.toBinaryQuery(oid_map, alloc);
}
};
} // namespace ozo
ozo::OidMap
constexpr auto OidMap
Map of C++ types to corresponding PostgreSQL types OIDs.
Definition: type_traits.h:534
Query
Query concept
ozo::register_types
constexpr oid_map_t< Ts... > register_types() noexcept
Provides #OidMap implementation for user-defined types.
Definition: type_traits.h:562
ozo::binary_query
Binary protocol query representation.
Definition: binary_query.h:37