MySQL 9.3.0
Source Code Documentation
json_template.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2025, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_REST_MRS_SRC_MRS_ITEMS_FORMATTER_H_
27#define ROUTER_SRC_REST_MRS_SRC_MRS_ITEMS_FORMATTER_H_
28
29#include <optional>
30#include <string>
31#include <vector>
32
33#include "helper/mysql_column.h"
35
36namespace mrs {
37namespace database {
38
40 public:
42 using CustomMetadata = std::map<std::string, std::string>;
43 virtual ~JsonTemplate() = default;
44
45 public:
46 virtual void begin_resultset(const std::string &url,
47 const std::string &items_name,
48 const std::vector<helper::Column> &columns) = 0;
50 uint64_t offset, uint64_t limit, bool is_default_limit,
51 const std::string &url, const std::vector<helper::Column> &columns) = 0;
52 virtual bool push_json_document(const char *document) = 0;
53 virtual bool push_row(const ResultRow &values,
54 const char *ignore_column = nullptr) = 0;
55 virtual void end_resultset(const std::optional<bool> &has_more = {}) = 0;
56
57 virtual void begin() = 0;
58 virtual void finish(const CustomMetadata &custom_metadata = {}) = 0;
59
60 virtual void flush() = 0;
61 virtual std::string get_result() = 0;
62
63 protected:
65 switch (field_type) {
70 return true;
71 default:
72 return false;
73 }
74
75 return false;
76 }
77};
78
79enum class JsonTemplateType {
84};
86 public:
87 virtual ~JsonTemplateFactory() = default;
88 virtual std::shared_ptr<JsonTemplate> create_template(
90 const bool encode_bigints_as_strings = false,
91 const bool include_links = true) const = 0;
92};
93
94} // namespace database
95} // namespace mrs
96
97#endif // ROUTER_SRC_REST_MRS_SRC_MRS_ITEMS_FORMATTER_H_
Definition: json_template.h:85
virtual std::shared_ptr< JsonTemplate > create_template(const JsonTemplateType type=JsonTemplateType::kStandard, const bool encode_bigints_as_strings=false, const bool include_links=true) const =0
virtual ~JsonTemplateFactory()=default
Definition: json_template.h:39
std::map< std::string, std::string > CustomMetadata
Definition: json_template.h:42
virtual ~JsonTemplate()=default
static bool should_encode_numeric_as_string(enum_field_types field_type)
Definition: json_template.h:64
virtual bool push_json_document(const char *document)=0
virtual std::string get_result()=0
virtual void begin_resultset(const std::string &url, const std::string &items_name, const std::vector< helper::Column > &columns)=0
virtual void end_resultset(const std::optional< bool > &has_more={})=0
virtual void finish(const CustomMetadata &custom_metadata={})=0
virtual void begin_resultset_with_limits(uint64_t offset, uint64_t limit, bool is_default_limit, const std::string &url, const std::vector< helper::Column > &columns)=0
virtual bool push_row(const ResultRow &values, const char *ignore_column=nullptr)=0
Definition: mysql_session.h:310
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
@ MYSQL_TYPE_LONGLONG
Definition: field_types.h:64
@ MYSQL_TYPE_DECIMAL
Definition: field_types.h:56
@ MYSQL_TYPE_DOUBLE
Definition: field_types.h:61
@ MYSQL_TYPE_FLOAT
Definition: field_types.h:60
JsonTemplateType
Definition: json_template.h:79
Definition: authorize_manager.h:48
required string type
Definition: replication_group_member_actions.proto:34