aboutsummaryrefslogtreecommitdiff
path: root/src/include/utils/jsonfuncs.h
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2020-01-24 09:58:37 -0800
committerRobert Haas <rhaas@postgresql.org>2020-01-24 09:58:37 -0800
commitce0425b162d0a8c168e1fbab5324fb1cbca4b6b7 (patch)
treefcd8aa4030cc4b0b8b460a1f41c0aa7282d7e4c4 /src/include/utils/jsonfuncs.h
parentd694e0bb793ebd6b392e6ef6a3b0a59ae66cbc95 (diff)
downloadpostgresql-ce0425b162d0a8c168e1fbab5324fb1cbca4b6b7.tar.gz
postgresql-ce0425b162d0a8c168e1fbab5324fb1cbca4b6b7.zip
Adjust src/include/utils/jsonapi.h so it's not backend-only.
The major change here is that we no longer include jsonb.h into jsonapi.h. The reason that was necessary is that jsonapi.h included several prototypes functions in jsonfuncs.c that depend on the Jsonb type. Move those prototypes to a new header, jsonfuncs.h, and include it where needed. The other change is that JsonEncodeDateTime is now declared in json.h rather than jsonapi.h. Taken together, these steps eliminate all dependencies of jsonapi.h on backend-only data types and header files, so that it can potentially be included in frontend code.
Diffstat (limited to 'src/include/utils/jsonfuncs.h')
-rw-r--r--src/include/utils/jsonfuncs.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/include/utils/jsonfuncs.h b/src/include/utils/jsonfuncs.h
new file mode 100644
index 00000000000..19f087ccae9
--- /dev/null
+++ b/src/include/utils/jsonfuncs.h
@@ -0,0 +1,49 @@
+/*-------------------------------------------------------------------------
+ *
+ * jsonfuncs.h
+ * Functions to process JSON data types.
+ *
+ * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/utils/jsonapi.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#ifndef JSONFUNCS_H
+#define JSONFUNCS_H
+
+#include "utils/jsonapi.h"
+#include "utils/jsonb.h"
+
+/*
+ * Flag types for iterate_json(b)_values to specify what elements from a
+ * json(b) document we want to iterate.
+ */
+typedef enum JsonToIndex
+{
+ jtiKey = 0x01,
+ jtiString = 0x02,
+ jtiNumeric = 0x04,
+ jtiBool = 0x08,
+ jtiAll = jtiKey | jtiString | jtiNumeric | jtiBool
+} JsonToIndex;
+
+/* an action that will be applied to each value in iterate_json(b)_values functions */
+typedef void (*JsonIterateStringValuesAction) (void *state, char *elem_value, int elem_len);
+
+/* an action that will be applied to each value in transform_json(b)_values functions */
+typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, int elem_len);
+
+extern uint32 parse_jsonb_index_flags(Jsonb *jb);
+extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state,
+ JsonIterateStringValuesAction action);
+extern void iterate_json_values(text *json, uint32 flags, void *action_state,
+ JsonIterateStringValuesAction action);
+extern Jsonb *transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
+ JsonTransformStringValuesAction transform_action);
+extern text *transform_json_string_values(text *json, void *action_state,
+ JsonTransformStringValuesAction transform_action);
+
+#endif