7#include <userver/utils/time_of_day.hpp>
9#include <userver/storages/postgres/exceptions.hpp>
10#include <userver/storages/postgres/io/buffer_io.hpp>
11#include <userver/storages/postgres/io/buffer_io_base.hpp>
12#include <userver/storages/postgres/io/type_mapping.hpp>
14USERVER_NAMESPACE_BEGIN
22template <
typename Duration>
23struct BufferFormatter<USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>>
24 : detail::BufferFormatterBase<USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>> {
25 using BaseType = detail::BufferFormatterBase<USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>>;
26 using BaseType::BaseType;
28 template <
typename Buffer>
29 void operator()(
const UserTypes& types, Buffer& buffer)
const {
30 Bigint usec = std::chrono::duration_cast<std::chrono::microseconds>(
this->value.SinceMidnight()).count();
31 io::WriteBuffer(types, buffer, usec);
36template <
typename Duration>
37struct BufferParser<USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>>
38 : detail::BufferParserBase<USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>> {
39 using BaseType = detail::BufferParserBase<USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>>;
40 using ValueType =
typename BaseType::ValueType;
41 using BaseType::BaseType;
43 void operator()(
const FieldBuffer& buffer) {
45 io::ReadBuffer(buffer, usec);
46 this->value = ValueType{std::chrono::duration_cast<Duration>(std::chrono::microseconds{usec})};
50template <
typename Duration>
51struct CppToSystemPg<USERVER_NAMESPACE::
utils::
datetime::TimeOfDay<Duration>> : PredefinedOid<PredefinedOids::kTime> {};