9#include <userver/storages/postgres/exceptions.hpp>
10#include <userver/storages/postgres/io/buffer_io_base.hpp>
11#include <userver/storages/postgres/io/field_buffer.hpp>
12#include <userver/storages/postgres/io/traits.hpp>
13#include <userver/storages/postgres/io/type_mapping.hpp>
14#include <userver/storages/postgres/io/type_traits.hpp>
15#include <userver/storages/postgres/io/user_types.hpp>
17#include <userver/formats/json.hpp>
18#include <userver/utils/strong_typedef.hpp>
20USERVER_NAMESPACE_BEGIN
31inline constexpr char kJsonbVersion = 1;
33struct JsonParser : BufferParserBase<formats::json::Value> {
34 using BaseType = BufferParserBase<formats::
json::Value>;
35 using BaseType::BaseType;
40void JsonValueToBuffer(
const formats::
json::Value& value,
41 std::vector<
char>& buffer);
43void JsonValueToBuffer(
const formats::
json::Value& value, std::string& buffer);
45template <
typename JsonValue>
46struct JsonFormatter : BufferFormatterBase<JsonValue> {
47 using BaseType = BufferFormatterBase<JsonValue>;
48 using BaseType::BaseType;
50 template <
typename Buffer>
51 void operator()(
const UserTypes&, Buffer& buffer)
const {
52 if constexpr (!std::is_same_v<PlainJson, JsonValue>) {
53 buffer.push_back(kJsonbVersion);
56 detail::JsonValueToBuffer(
57 static_cast<
const formats::json::Value&>(
this->value), buffer);
87struct CppToSystemPg<formats::
json::Value>
88 : PredefinedOid<PredefinedOids::kJsonb> {};