Data processing methods, apparatus, electronic devices and storage media

By extending JSON schema attributes and callback function parsing, the problem of low efficiency in converting JSON requests to SQL statements in C language backend systems was solved, and a highly efficient data processing flow was achieved.

CN115905287BActive Publication Date: 2026-04-03QI-ANXIN LEGENDSEC INFORMATION TECH (BEIJING) INC +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-30
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

In existing technologies, C language backend systems cannot directly convert JSON requests into SQL statements using reflection technology, resulting in large amounts of code, low efficiency, and difficulty in maintenance.

Method used

By extending the attributes in the JSON schema, SQL statements are generated, and callback functions are used to parse and correct the internal data structure, thereby improving conversion efficiency.

Benefits of technology

It improves the efficiency of converting JSON data requests to SQL statements, simplifies the amount of code, and enhances the development and operational stability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115905287B_ABST
    Figure CN115905287B_ABST
Patent Text Reader

Abstract

This application provides a data processing method, apparatus, electronic device, and storage medium. The method includes: parsing a received JSON-formatted data request to obtain a function name; determining a target JSON pattern based on the function name, the target JSON pattern including fields in the data request and corresponding JSON attributes, the JSON attributes including extended attributes; generating an SQL statement based on the extended attributes in the JSON pattern and the data request; and performing operations on a database based on the SQL statement. This application's embodiments improve the efficiency of SQL statement generation by extending the attributes in the target JSON pattern, thereby enabling the parsing of the JSON-formatted data request based on the extended attributes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to a data processing method, apparatus, electronic device, and storage medium. Background Technology

[0002] Front-end / back-end separation technology refers to a process where front-end and back-end developers pre-define interfaces, develop independently, and then integrate them later. This technology decouples front-end and back-end applications, improving development efficiency.

[0003] JSON is a lightweight data interchange format that uses a language-independent text format to store and represent data. It is easy to read and write, and also easy for machines to parse and generate, making it a widely used front-end and back-end communication format in the industry.

[0004] For systems where the front-end uses JSON and the back-end uses C, since C is not a dynamic language, it's impossible to directly map JSON to database queries using reflection. Currently, most systems manually convert JSON requests into SQL statements to manipulate the database. In practice, converting JSON requests into database CRUD operations in the back-end code consumes a significant amount of code, is labor-intensive, and has low conversion efficiency. Summary of the Invention

[0005] The purpose of this application is to provide a data processing method, apparatus, electronic device, and storage medium to improve the efficiency of converting JSON requests into SQL statements.

[0006] In a first aspect, embodiments of this application provide a data processing method, including:

[0007] Parse the received JSON data request to obtain the function name;

[0008] The target JSON schema is determined based on the function name. The target JSON schema includes the fields in the data request and the corresponding JSON attributes of the fields. The JSON attributes include extended attributes.

[0009] Generate SQL statements based on the extended attributes and data requests in the target JSON schema;

[0010] Perform database operations based on SQL statements.

[0011] This application embodiment extends the attributes in the target JSON pattern, thereby enabling the parsing of JSON format data requests based on the extended attributes, and thus generating SQL statements, thereby improving the efficiency of SQL statement generation.

[0012] In any embodiment, generating SQL statements based on extended attributes and data requests in the target JSON schema includes:

[0013] Transform the data request into an internal data structure based on the target JSON schema;

[0014] The corresponding callback function is called based on the function name to access the internal data structure and obtain the callback return value;

[0015] If the callback returns a successful result, an SQL statement is generated based on the extended attributes and data request in the target JSON schema.

[0016] Before generating the SQL statement, this embodiment converts the data request into an internal data structure using the target JSON pattern. The callback function can improve the accuracy and efficiency of verifying the parameters in the internal data structure by directly accessing the internal data structure.

[0017] In any embodiment, the data request is converted into an internal data structure according to the target JSON schema, including:

[0018] Allocate memory space according to the total memory occupied by each field in the target JSON schema;

[0019] The starting address of the memory space occupied by each field is determined based on the order of the fields in the target JSON schema;

[0020] According to the starting address of each field, the corresponding fields are stored in the memory space to obtain the internal data structure.

[0021] This application embodiment converts JSON formatted data requests into internal data structures by utilizing the field order in the target JSON schema, allowing callback functions to directly parse the internal data structures and improving the efficiency of data request processing.

[0022] In any embodiment, determining the starting address of the memory space occupied by each field according to the order of the fields in the target JSON schema includes:

[0023] The starting address of the memory space occupied by each field is determined according to the starting address calculation formula, which includes:

[0024]

[0025] Where n represents the nth field defined in the target JSON schema; Offset nThe `typeof(n-1)` method represents the starting address of the nth field, `typeof(n-1)` represents the data type of the (n-1)th field, `sizeof(typeof(n-1))` represents the memory size occupied by the (n-1)th field, and `aligned()` represents the starting address of the corresponding field.

[0026] Since C language does not support reflection and cannot determine the type of data structure at runtime, in this embodiment of the application, a contiguous block of memory is allocated according to the target JSON pattern to store the parameters in the data request, so that the callback function can parse the parameters in the memory.

[0027] In any embodiment, calling the corresponding callback function based on the function name to access the internal data structure includes:

[0028] Generate a struct based on the target JSON schema, and the order of the member variables in the struct is consistent with the order of the attributes in the target JSON schema;

[0029] Retrieve the internal data structure in memory space using a pointer to the structure;

[0030] The corresponding callback function is called based on the function name, and the callback function is used to access the internal data structure.

[0031] In this embodiment, since the field order in the structure is the same as the field order in the internal data structure, the parameters in the internal data structure can be accessed quickly and accurately through the pointer of the structure.

[0032] In any embodiment, accessing the internal data structure using a callback function includes:

[0033] The callback function is used to modify fields in the internal data structure that do not meet the requirements, and the modified internal data structure is obtained.

[0034] Generate SQL statements based on extended attributes and data requests in the JSON schema, including:

[0035] Convert the modified internal data structure into a new data request in JSON format;

[0036] Generate SQL statements based on the extended attributes in the JSON schema and the new data request.

[0037] In this embodiment, one of the functions of the callback function is to correct parameters in the internal data structure that do not meet the requirements, then convert the modified internal data structure into a new data request in JSON format, and then generate an SQL statement based on the new data request, so that the obtained SQL statement can correctly operate on the database.

[0038] In any embodiment, the extended attributes include whether to store database attributes and whether to use them as key-value attributes; generating SQL statements based on the extended attributes and data requests in the target JSON schema includes:

[0039] The target field is determined from the data request based on whether it is stored as a database attribute and whether it is used as a key-value attribute;

[0040] Generate SQL statements based on the target fields and according to the preset SQL template.

[0041] This application embodiment improves the efficiency of converting JSON format data requests into SQL statements by extending the options of whether to store database attributes and whether to use them as key-value attributes, and generating SQL statements according to a preset SQL template.

[0042] In any embodiment, before parsing the received JSON-formatted data request, the method further includes:

[0043] The system is initialized, which includes registering function names and entry addresses, registering JSON patterns, and generating a JSON pattern knowledge base.

[0044] This application embodiment provides a basis for internal data structure and SQL statement conversion of JSON format data requests by pre-registering function names, entry addresses, JSON patterns, and JSON pattern knowledge bases in the system.

[0045] In any embodiment, the JSON schema knowledge base includes at least one JSON schema;

[0046] A corresponding data table is generated in the database for each JSON pattern; the fields in the data table include all fields whose attributes in the JSON pattern are stored in the database.

[0047] In this embodiment of the application, by creating a data table in the database corresponding to the JSON pattern, and the data table containing all the fields whose attributes in the JSON pattern are stored in the database, the data foundation for subsequent operations on the various data tables in the database is provided.

[0048] In any embodiment, after obtaining the callback return value, the method further includes:

[0049] Convert the callback return value into the target return value in JSON format;

[0050] Send the target return value to the front-end interface.

[0051] In this embodiment, the callback return value is converted into a target return value in JSON format, and the target return value is fed back to the front-end interface so that the user can know whether the database operation was successful through the front-end interface.

[0052] Secondly, embodiments of this application provide a data processing apparatus, including:

[0053] The parsing module is used to parse the received JSON data request and obtain the function name;

[0054] The JSON pattern determination module is used to determine the target JSON pattern based on the function name. The target JSON pattern includes the fields in the data request and the corresponding JSON attributes of the fields. The JSON attributes include extended attributes.

[0055] The SQL statement generation module is used to generate SQL statements based on extended attributes and data requests in the JSON schema.

[0056] The database operation module is used to perform operations on the database based on SQL statements.

[0057] Thirdly, embodiments of this application provide an electronic device, including: a processor, a memory, and a bus, wherein,

[0058] The processor and memory communicate with each other via a bus;

[0059] The memory stores program instructions that can be executed by the processor, and the processor can execute the method of the first aspect by calling the program instructions.

[0060] Fourthly, embodiments of this application provide a non-transitory computer-readable storage medium, comprising:

[0061] A non-transitory computer-readable storage medium stores computer instructions that cause the computer to perform the method of the first aspect.

[0062] Other features and advantages of this application will be set forth in the following description and will be apparent in part from the description or may be learned by practicing embodiments of this application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description and the accompanying drawings. Attached Figure Description

[0063] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0064] Figure 1 A schematic diagram of a data processing flow provided in an embodiment of this application;

[0065] Figure 2 This is a schematic diagram of another data processing method provided in an embodiment of this application;

[0066] Figure 3 This is a schematic diagram of a data processing device structure provided in an embodiment of this application;

[0067] Figure 4 This is a schematic diagram of the physical structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0068] The embodiments of the technical solution of this application will now be described in detail with reference to the accompanying drawings. These embodiments are only used to more clearly illustrate the technical solution of this application and are therefore merely examples, and should not be used to limit the scope of protection of this application.

[0069] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit this application; the terms “comprising” and “having”, and any variations thereof, in the specification and the foregoing description of the drawings are intended to cover non-exclusive inclusion.

[0070] In the description of the embodiments of this application, technical terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or implicitly specifying the number, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly defined.

[0071] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0072] In the description of the embodiments in this application, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following related objects have an "or" relationship.

[0073] In the description of the embodiments of this application, the term "multiple" refers to two or more (including two), similarly, "multiple sets" refers to two or more (including two sets), and "multiple pieces" refers to two or more (including two pieces).

[0074] In the description of the embodiments of this application, the technical terms "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," "outer," "clockwise," "counterclockwise," "axial," "radial," and "circumferential" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing the embodiments of this application and simplifying the description, and are not intended to indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the embodiments of this application.

[0075] In the description of the embodiments of this application, unless otherwise expressly specified and limited, technical terms such as "installation," "connection," "joining," and "fixing" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral part; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication of two components or the interaction between two components. For those skilled in the art, the specific meaning of the above terms in the embodiments of this application can be understood according to the specific circumstances.

[0076] The front-end / back-end separation technology decouples front-end and back-end applications, improving development efficiency. Therefore, its application is becoming increasingly widespread. Taking embedded systems as an example, with the increasing complexity of embedded system functions in recent years, front-end / back-end separation technology is mainly used for sending configuration messages. Embedded systems have relatively poor CPU processing performance, so C language is generally used for back-end development. C is not a dynamic language and cannot achieve direct mapping between JSON, internal data structures, and the database through reflection. Therefore, currently, embedded programmers manually write C code to parse front-end requests based on JSON format and manually write SQL statements to save the JSON requests in the system configuration database. In real-world scenarios, the back-end code for parsing JSON and performing database operations (CRUD operations) consumes a large amount of code. This workload is very large, the code is difficult to maintain, easily introduces defects, and cannot guarantee system stability.

[0077] To address the aforementioned technical problems, the inventors of this application propose a data processing method. This method extends the attributes in the JSON schema by adding database-related attributes, thereby automatically converting JSON into SQL statements for database operations. This improves the efficiency of data conversion and, consequently, development efficiency.

[0078] It is understood that the method provided in this application is not limited to the backend of an embedded system, i.e., the server of an embedded system, and can be any backend of a system written in C language. This application does not make any specific limitations on this.

[0079] Figure 1 This application provides a schematic diagram of a data processing flow, such as... Figure 1 As shown, the method includes:

[0080] Step 101: Parse the received JSON data request to obtain the function name.

[0081] In this context, JSON data requests can be sent from the front-end client to the server, and these requests are used to perform database operations. The message body of a JSON data request consists of two parts: a header and a body. The header specifies the entry point for the request processing and includes a function that specifies the specific business logic. The body is used to transmit the request data.

[0082] For ease of understanding, this application provides some data requests in JSON format:

[0083]

[0084] By parsing the above data request, we can obtain that the function name of this data request is add_ezmgd_example. The data structure type of the body is ezmgd_example_cfg, which should conform to the JSON format specification defined by the JSON pattern corresponding to ezmgd_example_cfg.

[0085] In another embodiment, the format validity of the above data structure can be checked first according to JSON mode. If it is invalid, an error is reported; otherwise, it is converted into an internal data structure suitable for C language parsing.

[0086] Step 102: Determine the target JSON schema based on the function name. The target JSON schema includes the fields in the data request and the corresponding JSON attributes of the fields. The JSON attributes include extended attributes.

[0087] In the specific implementation process, after the server obtains the function name in the data request, it can determine the callback function based on the function name. The callback function contains the corresponding function name, JSON pattern, and database operation method. Therefore, after determining the callback function, the target JSON pattern corresponding to the data request can be determined.

[0088] JSON schema, also known as json_schema, is a data structure that clearly describes the structure of JSON data. This application extends the properties defined in the properties object based on the existing JSON schema; these newly added properties are called extended properties. It should be noted that extended properties provide the function of converting JSON formatted data requests into SQL, and are mainly used to describe the relationship between fields in the data request and the database.

[0089] Step 103: Generate SQL statements based on the extended attributes and data requests in the target JSON schema.

[0090] In the specific implementation process, the extended attributes in the target JSON schema determine which fields in the data request need to be stored in the database. Therefore, the fields that need to be stored in the database can be extracted from the data request based on the extended attributes of the target JSON schema. It should be noted that storing in the database here refers to performing operations on the database, such as inserting, deleting, modifying, and querying. The specific database operation can be determined by the database operation parameter passed to the callback function corresponding to the function. Therefore, after extracting the fields from the data request, SQL statements are generated based on the extracted fields.

[0091] Step 104: Perform operations on the database based on the SQL statements.

[0092] After generating the SQL statement, the server executes the corresponding operation on the database based on the SQL statement.

[0093] This application embodiment extends the attributes in the target JSON pattern, thereby enabling the parsing of JSON format data requests based on the extended attributes, and thus generating SQL statements, thereby improving the efficiency of SQL statement generation.

[0094] Based on the above embodiments, SQL statements are generated according to the extended attributes and data requests in the JSON schema, including:

[0095] Transform the data request into an internal data structure based on the target JSON schema;

[0096] The corresponding callback function is called based on the function name to access the internal data structure and obtain the callback return value;

[0097] If the callback returns a successful result, an SQL statement is generated based on the extended attributes and data request in the JSON schema.

[0098] Figure 2 This is a schematic diagram of another data processing method provided in an embodiment of this application, such as... Figure 2 As shown, the method includes:

[0099] Step 201: Parse the JSON data request;

[0100] Step 202: Determine the target JSON schema based on the function name;

[0101] It is understood that the specific implementation methods of steps 201 and 202 are as described in the above embodiments, and will not be repeated here.

[0102] Step 203: Convert the data request into an internal data structure according to the target JSON pattern; Since C language does not support reflection, it is impossible to determine the data structure type corresponding to the data request at runtime. Therefore, in this application, the data request is converted into an internal data structure suitable for C language parsing according to the target JSON pattern. That is, a contiguous block of memory is allocated for the data request, the fields in the data request are converted into binary numbers, and the binary numbers are stored in memory to obtain the internal data structure.

[0103] Step 204: Call the corresponding callback function based on the function name. The function name allows you to call a pre-registered callback function, which parses the internal data structure to process business logic, such as correcting incomplete or unreliable fields in the internal data structure. For example, if the internal data structure contains the data request's delivery time, this delivery time is the client's time; the server needs to change this delivery time to the server's time.

[0104] Step 205: Determine if the return value of the callback function is 0. When the callback function executes the corresponding business processing logic according to the internal data structure, if the execution is successful, it can return a return value indicating success, such as 0; if it fails, it can return a non-zero value indicating failure. It is understood that other symbols can also be used to represent the return value of success or failure, and this application embodiment does not specifically limit this. If the return value is 0, proceed to step 206; otherwise, proceed to step 208.

[0105] Step 206: Convert the internal data structure to JSON. After successful business processing, database operations can be performed. In step 204, the callback function may modify fields in the internal data structure. Therefore, to ensure the correctness of the fields stored in the database, the modified internal data structure is converted back into a JSON request, i.e., a new data request is obtained. It can be understood that the process of converting the internal data structure to a JSON request is the reverse process of converting the data request to the internal data structure in step 203. If the callback function does not modify the fields in the internal data structure, after converting the internal data structure back into a new data request, the new data request will be the same as the data request in step 201. In this case, step 206 can be skipped, and step 207 can be executed directly.

[0106] Step 207: Generate SQL statements and execute corresponding database operations; extract key fields from the data request, generate SQL statements based on the key fields, and execute corresponding database operations based on the SQL statements.

[0107] Step 208: Return the execution result to the front end.

[0108] Before generating SQL statements, this application's embodiments convert data requests into internal data structures using the target JSON pattern. The callback function directly accesses the internal data structure and uses a business interface to separate the business logic from the logic of JSON parsing and database operations, which can improve the accuracy and efficiency of verifying parameters in the internal data structure.

[0109] Based on the above embodiments, the data request is converted into an internal data structure according to the target JSON schema, including:

[0110] Allocate memory space according to the total memory occupied by each field in the target JSON schema;

[0111] The starting address of the memory space occupied by each field is determined according to the order of the fields in the target JSON schema;

[0112] Based on the starting address of each field, the corresponding fields are stored in the memory space to obtain the internal data structure.

[0113] In the specific implementation process, the target JSON schema contains attribute information for each field, such as the data type of the field, which includes integer, character, etc. Based on the data type, the memory size occupied by each field can be determined. Therefore, the total memory size required for each field in the data request can be determined based on the target JSON schema. A contiguous block of memory is then allocated for this data request based on the calculated total memory size. It can be understood that the size of the allocated memory space can be equal to or greater than the total memory size.

[0114] Before storing each field from the data request into memory, the starting address of each field in memory can be determined based on the order and data type of the fields in the target JSON schema. Understandably, the starting address can be an integer multiple of the field size. For example, if the field is of type integer, its starting address must be 4-byte aligned, meaning it must be divisible by 4. If the field is of type string, its starting address must be divisible by 1.

[0115] After determining the starting address of each field, the corresponding fields in the data request are converted into binary data according to the order of each field in the target JSON pattern, and the binary data is stored in the memory space starting from the determined starting address.

[0116] The starting address can be calculated using the following formula:

[0117]

[0118] Where n represents the nth field defined in the target JSON schema; Offset n This represents the starting address of the nth field, `typeof(n-1)` represents the data type of the (n-1)th field, and `sizeof(typeof(n-1))` represents the memory size occupied by the (n-1)th field. `aligned()` represents the starting address of the corresponding field. It can be understood that the starting address is determined based on the data type of the corresponding field; that is, the starting address should be aligned to an integer multiple of the data type size of the corresponding field. For example: according to the formula Offset... n-1 The starting address of the nth field calculated by +sizeof(typeof(n-1)) is 9, and the memory size occupied by the data type of the nth field is 4. After the calculation by aligned(), the starting address of the nth field should be greater than 9 and a multiple of 4, that is, the starting address is 12.

[0119] This application embodiment converts JSON formatted data requests into internal data structures by utilizing the field order in the target JSON schema, allowing callback functions to directly parse the internal data structures and improving the efficiency of data request processing.

[0120] Based on the above embodiments, the corresponding callback function is called according to the function name to access the internal data structure, including:

[0121] Generate a struct based on the target JSON schema, and the order of the member variables in the struct is consistent with the order of the fields in the target JSON schema;

[0122] Retrieve the internal data structure in memory space using a pointer to the structure;

[0123] The corresponding callback function is called based on the function name, and the internal data structure is accessed through the callback function.

[0124] In the specific implementation process, when the callback function parses the internal data structure, it can access it using a struct. The specific method is as follows: construct the member variables in the struct according to the order of the fields in the target JSON schema. The correspondence between the data types of each field in the target JSON schema and the types in the member variables of the struct is shown in the table below:

[0125]

[0126]

[0127] The target JSON format corresponding to the data request described in the above embodiments can be:

[0128]

[0129] The callback function can use the pointer in the structure to point to the starting address in the memory space, and obtain the parameter values ​​corresponding to each field stored in the memory space to access the internal data structure.

[0130] In this embodiment, since the field order in the structure is the same as the field order in the internal data structure, the parameters in the internal data structure can be accessed quickly and accurately through the pointer of the structure.

[0131] Based on the above embodiments, accessing the internal data structure using callback functions includes:

[0132] The callback function is used to modify fields in the internal data structure that do not meet the requirements, and the modified internal data structure is obtained.

[0133] Generate SQL statements based on extended attributes and data requests in the JSON schema, including:

[0134] Convert the modified internal data structure into a new data request in JSON format;

[0135] Generate SQL statements based on the extended attributes in the JSON schema and the new data request.

[0136] In practice, callback functions serve several purposes: validating parameters within the internal data structure, supplementing and correcting certain fields, and executing business logic. Different callback functions correspond to different business logics, which can be registered on the server according to specific needs. For example, if a user sends a JSON request to set the air conditioner temperature to 25 degrees Celsius, the callback function first validates the 25-degree data, then adjusts the temperature to 25 degrees, and finally adds the sending time to the time field. Only then can it generate an SQL statement to save the configuration setting of the air conditioner temperature to 25 degrees.

[0137] In cases where partial field corrections are needed, such as when the internal data structure includes the data request's delivery time (which is the client's time and does not conform to regulations), the callback function can modify the delivery time to reflect the server's time. In cases where the validity of the data request needs to be verified, such as when the internal data structure contains facial image data, the callback function can validate the facial image data to determine if the user sending the data request is legitimate.

[0138] When a callback function modifies fields in the internal data structure, the modified internal data structure needs to be converted back into a new data request in JSON format when generating the SQL statement. Key fields are extracted from the new data request based on the extended attributes in the target JSON schema, and the SQL statement is generated based on these key fields.

[0139] In the specific implementation process, please refer to the following table for extended attributes:

[0140]

[0141]

[0142] The code segment corresponding to the target JSON pattern in the above embodiment describes a JSON data structure ezmgd_example_cfg. ezmgd_example_cfg includes three fields: the mode field is of type integer, which is stored in the database as a key-value pair; the status field is of type string, which is stored in the database but is not a key-value pair; and the connect_log field is of type integer, which is not stored in the database and is not a key-value pair.

[0143] Therefore, the fields that need to be stored in the database can be determined by the target JSON pattern. That is, the field containing persist is 1 is used as the target field. For data requests that modify or delete fields in the database, the field with iskey is also used as the target field.

[0144] (1) For insert statements, the following SQL template can be generated in advance:

[0145] INSERT INTO table_name(column_name) VALUES(%s);

[0146] The table name is the title name corresponding to the target JSON pattern; the column name is the set of all fields defined in the target JSON pattern where the persist field is 1.

[0147] For the target JSON pattern in the above embodiments, the generated SQL template for the insert statement is as follows:

[0148] INSERT INTO ezmgd_example_cfg(mode, status)VALUES(%s);

[0149] (2) For the delete statement, the following SQL template is generated:

[0150] DELETE FROM table_name WHERE key_value = %s;

[0151] Understandably, if there are multiple key-value pairs, the following SQL template will be generated:

[0152] DELETE FROM table_name WHERE key1 = %s AND key2 = %s ... AND keyn = %s;

[0153] Here, the table name is the title name corresponding to the target JSON pattern, and the key-value pair x is the attribute name defined as the xth key-value column in the target JSON pattern.

[0154] For the target JSON pattern in the above embodiments, the generated SQL statement template is as follows:

[0155] DELETE FROM ezmgd_example_cfg WHERE mode=%s.

[0156] (3) For the query statement, the following SQL template is generated:

[0157] (a) Unconditional query template:

[0158] SELECT (column_name) FROM table_name;

[0159] SELECT (column_name) FROM table_name WHERE key_value = %s;

[0160] If there are multiple key values, the following SQL template will be generated:

[0161] SELECT (column_name) FROM table_name WHERE key_value1 = %s AND key_value2 = %s ... AND key_valuen = %s;

[0162] The table name is the title name corresponding to the target JSON pattern, and the key-value pair x is the attribute name defined as the xth key-value column in the target JSON pattern.

[0163] (4) For modification statements, the following SQL template is generated:

[0164] UPDATE table_name SET attribute1 = %s, attribute2 = %s ... attributen = %s WHERE key1 = %s AND key2 = %s ... AND keyn = %s;

[0165] (5) For the clear statement, the following SQL template is generated:

[0166] DELETE FROM table_name;

[0167] After extracting the target fields, the corresponding SQL statements can be generated based on the preset SQL template mentioned above. It should be noted that since the function name, target JSON pattern, and database operation in the callback function correspond, the specific database operation to be performed can be determined once the function name is determined.

[0168] This application embodiment improves the efficiency of converting JSON format data requests into SQL statements by extending the options of whether to store database attributes and whether to use them as key-value attributes, and generating SQL statements according to a preset SQL template.

[0169] Based on the above embodiments, before parsing the received JSON format data request, the method further includes:

[0170] The system is initialized, which includes registering function names and entry addresses, registering JSON patterns, and generating a JSON pattern knowledge base.

[0171] In the specific implementation process, the system running on the server needs to be initialized before processing the front-end data requests. The specific initialization items include: each business processing logic registers its function name and entry address into the system; each business processing logic registers its corresponding JSON pattern into the system; and the pre-built JSON pattern knowledge base is stored in the system memory.

[0172] The system provides the following interface to the outside world: EZMGD_REGISTER_ENTRY(func,JSON_schema,action);

[0173] The meanings of the three parameters in this interface are as follows:

[0174] @func: Registers a handler function that calls a C function with the same name based on the function name provided by the web application.

[0175] @JSON_schema: The name of the JSON_schema.

[0176] @action: This specifies how the framework interacts with the database, supporting the following methods:

[0177]

[0178] Since there may be many function names and function entry addresses registered in the system, this application organizes the function entry addresses into a red-black tree to quickly find the function entry address based on the function name. The key is the function name, and the value is the function entry address.

[0179] This application embodiment provides a basis for internal data structure and SQL statement conversion of JSON format data requests by pre-registering function names, entry addresses, JSON patterns, and JSON pattern knowledge bases in the system.

[0180] Based on the above embodiments, the pre-built JSON pattern knowledge base includes at least one JSON pattern, and different JSON patterns can be named with different titles. In this embodiment, the JSON patterns can be saved to tables in a relational database, with each JSON pattern corresponding one-to-one with a table in the database. For example, if the name corresponding to a JSON pattern is ezmgd_example_cfg, then there is a corresponding data table in the database named ezmgd_example_cfg.

[0181] The data table contains columns for all fields declared as persist=1 in the JSON schema, and the column name can be the same as the field name declared in the JSON schema, and the data type of the column corresponds to the data type of the field in the JSON schema.

[0182] For example: if the data type of a field with persist=1 in JSON mode is integer, then the data type of the corresponding column in the database is INTEGER; if the data type of a field with persist=1 in JSON mode is string, then the data type of the corresponding column in the database is VARCHAR, and the length is the length declared in JSON mode.

[0183] Taking the target JSON pattern in the above embodiment as an example, its corresponding data table is as follows:

[0184] create table ezmgd_example_cfg(mode INTEGER,statusvarchar(63));

[0185] It should be noted that the name of the data table can be different from the name in the JSON schema, as long as the name of the data table corresponds one-to-one with the name in the JSON schema. Similarly, the field names in the data table can also be different from the field names declared in the JSON schema, again as long as they correspond one-to-one.

[0186] In this embodiment of the application, by creating a data table in the database corresponding to the JSON pattern, and the data table containing all the fields whose attributes in the JSON pattern are stored in the database, the data foundation for subsequent operations on the various data tables in the database is provided.

[0187] Figure 3 This is a schematic diagram of a data processing device structure provided in an embodiment of this application. The device can be a module, program segment, or code on an electronic device. It should be understood that this device is similar to the one described above. Figure 1 The method implementation corresponds to this and can be executed. Figure 1 The specific functions of the device involved in each step of the method embodiment can be found in the description above; to avoid repetition, detailed descriptions are omitted here. The device includes: a parsing module 301, a JSON pattern determination module 302, an SQL statement generation module 303, and a database operation module 304; wherein:

[0188] The parsing module 301 is used to parse the received JSON data request and obtain the function name;

[0189] The JSON pattern determination module 302 is used to determine the target JSON pattern based on the function name. The target JSON pattern includes the fields in the data request and the corresponding JSON attributes of the fields. The JSON attributes include extended attributes.

[0190] SQL statement generation module 303 is used to generate SQL statements based on extended attributes and data requests in JSON schema;

[0191] The database operation module 304 is used to operate on the database based on SQL statements.

[0192] Based on the above embodiments, the SQL statement generation module 303 is specifically used for:

[0193] Transform the data request into an internal data structure based on the target JSON schema;

[0194] The corresponding callback function is called based on the function name to access the internal data structure and obtain the callback return value;

[0195] If the callback returns a successful result, an SQL statement is generated based on the extended attributes and data request in the JSON schema.

[0196] Based on the above embodiments, the SQL statement generation module 303 is specifically used for:

[0197] Allocate memory space according to the total memory occupied by each field in the target JSON schema;

[0198] The starting address of the memory space occupied by each field is determined based on the order of the fields in the target JSON schema;

[0199] Based on the starting address of each field, the corresponding fields are stored in the memory space to obtain the internal data structure.

[0200] Based on the above embodiments, the SQL statement generation module 303 is specifically used for:

[0201] The starting address of each field in the memory space is determined according to the starting address calculation formula, which includes:

[0202]

[0203] Where n represents the nth field defined in the target JSON schema; Offset n The starting address of the nth field, typeof(n-1) indicates the data type of the (n-1)th field, sizeof(typeof(n-1)) indicates the memory size occupied by the (n-1)th field; aligned() indicates the starting address of the corresponding field.

[0204] Based on the above embodiments, the SQL statement generation module 303 is specifically used for:

[0205] Generate a struct based on the target JSON schema, and the order of the member variables in the struct is consistent with the order of the fields in the target JSON schema;

[0206] Retrieve the internal data structure in memory space using a pointer to the structure;

[0207] The corresponding callback function is called based on the function name, and the callback function is used to access the internal data structure.

[0208] Based on the above embodiments, the SQL statement generation module 303 is specifically used for:

[0209] The callback function is used to modify fields in the internal data structure that do not meet the requirements, and the modified internal data structure is obtained.

[0210] Convert the modified internal data structure into a new data request in JSON format;

[0211] Generate SQL statements based on the extended attributes in the target JSON schema and the new data request.

[0212] Based on the above embodiments, the extended attributes include whether to store database attributes and whether to use them as key-value attributes; the SQL statement generation module 303 is specifically used for:

[0213] The target field is determined from the data request based on whether it is stored as a database attribute and whether it is used as a key-value attribute;

[0214] Generate SQL statements based on the target fields and according to the preset SQL template.

[0215] Based on the above embodiments, the device further includes an initialization module, used for:

[0216] The system is initialized, which includes registering function names and entry addresses, registering JSON patterns, and generating a JSON pattern knowledge base.

[0217] Based on the above embodiments, the JSON schema knowledge base includes at least one JSON schema;

[0218] A corresponding data table is generated in the database for each JSON pattern; the fields in the data table include all fields whose attributes in the JSON pattern are stored in the database.

[0219] Based on the above embodiments, the device further includes a return module, used for:

[0220] Convert the callback return value into the target return value in JSON format;

[0221] Send the target return value to the front-end interface.

[0222] Figure 4 This is a schematic diagram of the physical structure of the electronic device provided in the embodiments of this application, such as... Figure 4 As shown, the electronic device includes: a processor 401, a memory 402, and a bus 403; wherein,

[0223] The processor 401 and the memory 402 communicate with each other through the bus 403;

[0224] The processor 401 is used to call program instructions in the memory 402 to execute the methods provided in the above method embodiments, such as: parsing the received JSON format data request to obtain the function name; determining the target JSON pattern based on the function name, the target JSON pattern including fields in the data request and corresponding JSON attributes, the JSON attributes including extended attributes; generating an SQL statement based on the extended attributes in the target JSON pattern and the data request; and operating the database based on the SQL statement.

[0225] Processor 401 can be an integrated circuit chip with signal processing capabilities. The processor 401 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor.

[0226] The memory 402 may include, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.

[0227] This embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer can perform the methods provided in the above-described method embodiments, such as: parsing a received JSON format data request to obtain a function name; determining a target JSON pattern based on the function name, the target JSON pattern including fields in the data request and corresponding JSON attributes, the JSON attributes including extended attributes; generating an SQL statement based on the extended attributes in the target JSON pattern and the data request; and performing operations on the database based on the SQL statement.

[0228] This embodiment provides a non-transitory computer-readable storage medium storing computer instructions that cause the computer to execute the methods provided in the above-described method embodiments. These instructions include, for example, parsing a received JSON-formatted data request to obtain a function name; determining a target JSON pattern based on the function name, the target JSON pattern including fields in the data request and corresponding JSON attributes, the JSON attributes including extended attributes; generating an SQL statement based on the extended attributes in the target JSON pattern and the data request; and performing database operations based on the SQL statement.

[0229] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.

[0230] Furthermore, the units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0231] Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0232] In this document, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, without necessarily requiring or implying any such actual relationship or order between these entities or operations.

[0233] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A data processing method, characterized in that, include: Parse the received JSON data request to obtain the function name; The target JSON pattern is determined based on the function name. The target JSON pattern includes the fields in the data request and the corresponding JSON attributes of the fields. The JSON attributes include extended attributes. Generate SQL statements based on the extended attributes in the target JSON schema and the data request; Operate on the database according to the SQL statement; The step of generating SQL statements based on the extended attributes in the JSON schema and the data request includes: The data request is converted into an internal data structure according to the target JSON pattern. The corresponding callback function is called according to the function name to access the internal data structure and obtain the callback return value; If the callback return value indicates success, then an SQL statement is generated based on the extended attributes in the JSON pattern and the data request.

2. The method according to claim 1, characterized in that, The step of converting the data request into an internal data structure according to the target JSON schema includes: Allocate memory space according to the total memory occupied by each field in the target JSON schema; The starting address of the memory space occupied by each field is determined according to the order of the fields in the target JSON pattern; According to the starting address of each field, the corresponding fields are stored in the memory space to obtain the internal data structure.

3. The method according to claim 2, characterized in that, The step of determining the starting address of the memory space occupied by each field according to the order of the fields in the target JSON pattern includes: The starting address of each field in the memory space is determined according to the starting address calculation formula, which includes: ; in, This indicates the first JSON schema defined by the target. One field; Indicates the first The starting address of each field, Indicates the first The data type of each field, Indicates the first The memory size occupied by each field; This indicates the starting address of the corresponding field.

4. The method according to claim 2, characterized in that, The step of calling the corresponding callback function based on the function name to access the internal data structure includes: A structure is generated based on the target JSON pattern, wherein the order of the member variables in the structure is consistent with the order of the fields in the target JSON pattern; The internal data structure in the memory space is obtained based on the pointer of the structure; The corresponding callback function is called based on the function name, and the internal data structure is accessed using the callback function.

5. The method according to claim 4, characterized in that, Accessing the internal data structure using the callback function includes: The callback function is used to modify fields in the internal data structure that do not conform to the regulations, thereby obtaining the modified internal data structure; The step of generating SQL statements based on the extended attributes in the target JSON schema and the data request includes: The modified internal data structure is converted into a new data request in JSON format. Generate SQL statements based on the extended attributes in the target JSON schema and the new data request.

6. The method according to claim 1, characterized in that, The extended attributes include whether to store database attributes and whether to use them as key-value attributes; The step of generating SQL statements based on the extended attributes in the target JSON schema and the data request includes: The target field is determined from the data request based on whether it is stored as a database attribute and whether it is used as a key-value attribute; Based on the target field, the SQL statement is generated according to the preset SQL template.

7. The method according to claim 1, characterized in that, Before parsing the received JSON data request, the method further includes: The system is initialized, which includes registering function names and entry addresses, registering JSON patterns, and generating a JSON pattern knowledge base.

8. The method according to claim 7, characterized in that, The JSON schema knowledge base includes at least one JSON schema. A corresponding data table is generated in the database according to each JSON pattern; wherein, the fields in the data table include all fields in the JSON pattern whose attributes are stored in the database.

9. The method according to any one of claims 1-8, characterized in that, After obtaining the callback return value, the method further includes: Convert the callback return value into the target return value in JSON format; Send the target return value to the front-end interface.

10. A data processing apparatus, characterized in that, include: The parsing module is used to parse the received JSON data request and obtain the function name; The JSON pattern determination module is used to determine the target JSON pattern based on the function name. The target JSON pattern includes fields in the data request and JSON attributes corresponding to the fields. The JSON attributes include extended attributes. The SQL statement generation module is used to generate SQL statements based on the extended attributes in the JSON pattern and the data request. The database operation module is used to operate the database according to the SQL statement; The SQL statement generation module is specifically used for: The data request is converted into an internal data structure according to the target JSON pattern. The corresponding callback function is called according to the function name to access the internal data structure and obtain the callback return value; If the callback return value indicates success, then an SQL statement is generated based on the extended attributes in the JSON pattern and the data request.

11. An electronic device, characterized in that, include: Processor, memory, and bus, among which, The processor and the memory communicate with each other via the bus; The memory stores program instructions that can be executed by the processor, and the processor can execute the method as described in any one of claims 1-9 by calling the program instructions.

12. A non-transitory computer-readable storage medium, characterized in that, The non-transitory computer-readable storage medium stores computer instructions that, when executed by a computer, cause the computer to perform the method as described in any one of claims 1-9.

Citation Information

Patent Citations

  • Data processing method and device

    CN111767057A

  • Data management method and system, computer equipment and storage medium

    CN114168614A