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

Description

Query-related functions.

Functions

template<typename BinaryQueryConvertible , typename OidMap , typename Allocator = std::allocator<char>>
binary_query ozo::to_binary_query (const BinaryQueryConvertible &query, const OidMap &oid_map, const Allocator &allocator=Allocator{})
 Convert a query object to the binary representation. More...
 
template<typename T >
constexpr auto ozo::to_const_char (const T &text) noexcept
 Convert QueryText to const char*. More...
 
template<typename Query >
constexpr auto ozo::get_query_text (Query &&query)
 Get the query text object. More...
 
template<typename T >
constexpr auto ozo::get_query_params (Query &&query)
 Get the query parameters. More...
 
template<class QueryText , class ... Params>
constexpr auto ozo::make_query (QueryText &&text, Params &&...params)
 Construct built-in Query implementation object. More...
 

Function Documentation

◆ get_query_params()

template<typename T >
constexpr auto ozo::get_query_params ( Query &&  query)
constexpr

Get the query parameters.

Provides read-only access to query parameters. This function invokes ozo::get_query_params_impl::apply() and should be customized via ozo::get_query_params_impl specialization.

Customization point

This is one of two points (see also ozo::get_query_text()) which should be used to support your own query type in the library. E.g.:

namespace ozo {
template <>
struct get_query_params_impl<my_ns::my_query> {
static decltype(auto) apply(const my_ns::my_query& q) {
return boost::hana::make_tuple(q.param1, q.param2, q.param3);
}
};
} // namespace ozo
Parameters
query— query object
Returns
#HanaSequence — tuple with query parameters
See also
ozo::get_query_text

◆ get_query_text()

template<typename Query >
constexpr auto ozo::get_query_text ( Query &&  query)
constexpr

Get the query text object.

Provides read-only access to a query text with SQL statement. This function invokes ozo::get_query_text_impl::apply() and should be customized via ozo::get_query_text_impl specialization.

Customization point

This is one of two points (see also ozo::get_query_params()) which should be used to support your own query type in the library. E.g.:

namespace ozo {
template <>
struct get_query_text_impl<my_ns::my_query> {
static decltype(auto) apply(const my_ns::my_query& q) {
return q.get_text();
}
};
} // namespace ozo
Parameters
query— query object
Returns
QueryText — query text with single SQL statement
See also
ozo::get_query_params

◆ make_query()

template<class QueryText , class ... Params>
constexpr auto ozo::make_query ( QueryText &&  text,
Params &&...  params 
)
constexpr

Construct built-in Query implementation object.

Construct built-in Query implementation object from specified text and variadic parameters.

Note
Currently no compile-time parameters validation provided by this function, the validation would be made in run-time only.

Example

auto query = ozo::make_query(
"SELECT id, name FROM users WHERE credit > $1 AND rating > $2;",
min_credit, min_rating);
Parameters
text— query text implementation with PostgreSQL native markup with variable place holder format is $n, there n - parameter position in the params begining from 1.
params— query parameters
Returns
Query object

◆ to_binary_query()

template<typename BinaryQueryConvertible , typename OidMap , typename Allocator = std::allocator<char>>
binary_query ozo::to_binary_query ( const BinaryQueryConvertible query,
const OidMap &  oid_map,
const Allocator &  allocator = Allocator{} 
)

Convert a query object to the binary representation.

This function provides an ability to convert a query object to the protocol compatible binary representation to send it to the PostgreSQL database. A user may call this function to reuse the binary_query and eliminate unnecessarily conversion of the query object to its binary representation each operation. E.g., this may be useful with the failover micro-framework.

Parameters
query— a query object to convert to the binary representation.
oid_mapOidMap to type OIDs for the binary representation.
allocator— allocator to use for the data of ozo::binary_query.
Returns
ozo::binary_query — the binary representation.

◆ to_const_char()

template<typename T >
constexpr auto ozo::to_const_char ( const T &  text)
constexprnoexcept

Convert QueryText to const char*.

Convert QueryText to const char* for futher transfer to a database. This function invokes ozo::to_const_char_impl::apply() and should be customized via ozo::to_const_char_impl specialization. Built-in support for types:

  • const char*,
  • std::string,
  • std::string_view,
  • boost::hana::string.

Customization point

This point should be used to add support for your own query text type. E.g.:

namespace ozo {
template <>
struct to_const_char_impl<my_ns::my_string> {
static decltype(auto) apply(const my_ns::my_string& text) noexcept {
return text.get_data();
}
};
} // namespace ozo
Note
ozo::to_const_char_impl::apply() should be noexcept.
Parameters
text— query text to transform to const char*
Returns
const char*
ozo::make_query
constexpr auto make_query(QueryText &&text, Params &&...params)
Construct built-in Query implementation object.