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
32inline constexpr char kJsonbVersion = 1;
34struct JsonParser : BufferParserBase<formats::json::Value> {
35 using BaseType = BufferParserBase<
formats::
json::Value>;
36 using BaseType::BaseType;
41void JsonValueToBuffer(
const formats::
json::Value& value, 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(
static_cast<
const formats::json::Value&>(
this->value), buffer);
86struct CppToSystemPg<
formats::
json::Value> : PredefinedOid<PredefinedOids::kJsonb> {};
89struct CppToSystemPg<PlainJson> : PredefinedOid<PredefinedOids::kJson> {};