MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / jsonify

Function jsonify

src/common/json_utils.cpp:65–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65yyjson_mut_val* jsonify(JsonMutWrapper& wrapper, const common::ValueVector& vec, uint64_t pos) {
66 // creates a mutable value linked to wrapper.ptr, but the responsibility to integrate it into
67 // wrapper is placed upon the caller
68 yyjson_mut_val* result = nullptr;
69 if (vec.isNull(pos)) {
70 result = yyjson_mut_null(wrapper.ptr);
71 } else if (JsonType::isJson(vec.dataType)) {
72 auto strVal = vec.getValue<string_t>(pos);
73 auto strContent = strVal.getAsStringView();
74
75 // Convert JSON string to an immutable JSON document using stringToJson
76 JsonWrapper immutable_json_wrapper = stringToJson(std::string(strContent));
77 yyjson_doc* immutable_doc = immutable_json_wrapper.ptr;
78 if (!immutable_doc) {
79 // Handle error if parsing fails
80 return yyjson_mut_null(wrapper.ptr);
81 }
82
83 // Create a new mutable document in the wrapper and copy the root from the immutable
84 // document
85 yyjson_mut_val* mut_root =
86 yyjson_val_mut_copy(wrapper.ptr, yyjson_doc_get_root(immutable_doc));
87
88 return mut_root;
89 } else {
90 switch (vec.dataType.getLogicalTypeID()) {
91 case LogicalTypeID::BOOL:
92 result = yyjson_mut_bool(wrapper.ptr, vec.getValue<bool>(pos));
93 break;
94 case LogicalTypeID::SERIAL:
95 case LogicalTypeID::INT64:
96 result = yyjson_mut_sint(wrapper.ptr, vec.getValue<int64_t>(pos));
97 break;
98 case LogicalTypeID::INT32:
99 result = yyjson_mut_sint(wrapper.ptr, vec.getValue<int32_t>(pos));
100 break;
101 case LogicalTypeID::INT16:
102 result = yyjson_mut_sint(wrapper.ptr, vec.getValue<int16_t>(pos));
103 break;
104 case LogicalTypeID::INT8:
105 result = yyjson_mut_sint(wrapper.ptr, vec.getValue<int8_t>(pos));
106 break;
107 case LogicalTypeID::UINT64:
108 result = yyjson_mut_uint(wrapper.ptr, vec.getValue<uint64_t>(pos));
109 break;
110 case LogicalTypeID::UINT32:
111 result = yyjson_mut_uint(wrapper.ptr, vec.getValue<uint32_t>(pos));
112 break;
113 case LogicalTypeID::UINT16:
114 result = yyjson_mut_uint(wrapper.ptr, vec.getValue<uint16_t>(pos));
115 break;
116 case LogicalTypeID::UINT8:
117 result = yyjson_mut_uint(wrapper.ptr, vec.getValue<uint8_t>(pos));
118 break;
119 case LogicalTypeID::DOUBLE:
120 result = yyjson_mut_real(wrapper.ptr, vec.getValue<double>(pos));
121 break;
122 case LogicalTypeID::FLOAT:

Callers 3

jsonifyQueryResultFunction · 0.85
bindInsertNodeMethod · 0.85
bindInsertRelMethod · 0.85

Calls 13

stringToJsonFunction · 0.85
getValueVectorFunction · 0.85
jsonifyAsStringFunction · 0.85
getFieldVectorsFunction · 0.85
JsonWrapperFunction · 0.85
getValue<string_t>Method · 0.80
getAsStringViewMethod · 0.80
getLogicalTypeIDMethod · 0.80
toStringFunction · 0.50
getDataVectorFunction · 0.50
isNullMethod · 0.45
getDataMethod · 0.45

Tested by

no test coverage detected