Method, system and equipment for automatically generating database operation instruction according to WEB API request and medium

By analyzing WEB API requests and establishing an intermediate representation IR conversion algorithm, it is automatically mapped to database operation instructions, and the code redundancy caused by changes in database table structure and data operation requirements in the prior art is solved, and development efficiency is improved.

CN119248351APending Publication Date: 2025-01-03孙龙
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411425662.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-13
Publication Date
2025-01-03

AI Technical Summary

Technical Problem

In the prior art, when the database table structure changes or the front-end data operation requirements change, the back-end code needs to be adjusted frequently, resulting in code redundancy, large workload of development and testing, and inefficient.

Method used

By analyzing WEB API requests, establishing an intermediate representation IR conversion algorithm, mapping it to database operation instructions, realizing automatic conversion of WEB API requests to database operation instructions, reducing the workload of back-end code development.

Benefits of technology

It realizes that the front-end only needs to write WEB API requests to meet various database access needs, greatly reducing the workload of back-end code development and improving development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119248351A_ABST
    Figure CN119248351A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of database development. In particular to a database access method, which comprises the following steps of: mapping each part of a database operation instruction into a WEB API request line and a request body through an intermediate expression IR by analyzing a WEB API request specification for requesting back-end database operation and a characteristic rule of the database operation instruction, so as to realize grammar conversion from a WEB API to the database operation instruction; therefore, the front end can automatically generate the database operation instruction only by writing the WEB API request according to the specification, and various access requirements of the front end on resources in the database are quickly responded on the basis of reducing back-end codes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of database development and specifically relates to a database access method, which automatically converts a WEB API request into a corresponding database operation instruction by parsing the specification of a WEB API request back-end database operation and the characteristic law of a database operation instruction. Background Art

[0002] With the development of database and software development technology, various application systems generally break down database access into individual instances, write corresponding class codes, and then generate WEB API interfaces to access the backend in order to meet the large number of front-end access requirements. The backends also use this WEB API interface to operate data with each other. When the database table and table structure change, the corresponding backend program code must be adjusted. Even if the database table and table structure do not change, when the front-end has new data operation requirements, it can generally only generate WEB API requests to access the backend data, which requires additional code writing at the backend. These codes are highly redundant and the workload of development and testing is large. Summary of the invention

[0003] The present invention realizes a method for automatically converting a WEB API request for operating a database into a database operation instruction, and its schematic diagram is shown in FIG. Figure 1 .

[0004] The objects of various operation instructions in the database can be modeled at the granularity of library, table, row, and field. The library, table, row, and field can be combined to form expressions to form more complex data operation objects, and then through conditional parameters including aggregation, paging, sorting, and querying, the ever-increasing data operation needs can be realized in the combination of the operation instruction commands, objects, and parameters.

[0005] The present invention establishes an intermediate representation IR conversion algorithm for the commands, objects and parameters of database operation instructions, as well as their operations, expressions and clauses; establishes an intermediate representation IR conversion algorithm that maps to the HTTP METHOD, URI resources and request body structure of the WEB API request, and implements the syntax conversion from the WEB API request to the database operation instruction through the intermediate representation IR, thereby realizing that the front end can achieve various access requirements to the resources in the database by only writing the WEB API request. Including:

[0006] A WEB API request consists of the data in the request line and the request body. You can refer to the commands, objects, and parameters of database operation instructions, as well as the composition of their operations, expressions, clauses, and other elements to establish the corresponding request data structure specifications.

[0007] According to the rules of the operation instructions of the WEB API request to the backend database, the WEB API request interface model is formed by the request data structure specification, including the syntax conversion rules of the request line, the request body structure to the intermediate representation IR;

[0008] Specifically, the HTTP METHOD of the request line includes GET, POST, PUT, and DELETE. The information in the URI and request body includes objects such as libraries, tables, rows, and fields, as well as expressions and predicates, which are converted into the intermediate representation IR of database operation instructions such as CRUD.

[0009] Specifically, the rules of METHOD, URI PATH and QUERY in the WEB API request, as well as the format of the request body, are analyzed and parsed into commands, objects, and parameters corresponding to the database operation instructions. The mapping to the intermediate representation IR of the data operation instructions can be established one by one.

[0010] After parsing the WEB API request to obtain the intermediate representation IR, the system refers to the database operation instruction grammar rules, traverses the intermediate representation IR, and automatically generates database operation instructions without the need for further programming development.

[0011] To achieve the above object, the present invention also provides a system for implementing the method of automatically generating database operation instructions from the WEB API request.

[0012] To achieve the above objectives, the present invention also provides a computer device, including a memory and a processor, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor executes the method of automatically generating database operation instructions from the WEB API request.

[0013] To achieve the above-mentioned purpose, the present invention also provides a storage medium storing a program file capable of implementing the method for automatically generating database operation instructions from WEB API requests.

[0014] Beneficial effects of the invention: The method for converting database operation instructions into a WEB API request interface provided by the invention establishes specifications for encoding each relational algebra and clause in the database operation instruction into the METHOD, URI and request body of the WEB API request, thereby realizing that the WEB API request is written according to the specification, and the database operation instructions for database access can be automatically generated, which greatly reduces the workload of back-end code development, so that the front-end development can realize database operation as long as it is familiar with the WEB API convention specifications, thereby greatly improving the development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1Schematic diagram of a method for automatically generating database operation instructions for a WEB API request

[0016] Figure 2 A system architecture diagram provided in an embodiment DETAILED DESCRIPTION

[0017] The technical solutions in the embodiments of the present invention are described below, and the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0018] The current mainstream mode of WEB development is the separation of front-end and back-end, and the mainstream interface standard for front-end and back-end interactive data is WEBAPI. Since the development of the back-end response to WEB API requests is driven by the business model, each data table and related use cases will be mapped to different ORM, DAO, DTO objects, etc. according to the requirements. These object codes are largely repeated, and the work of writing test codes is also largely repeated. Moreover, if there is a slight change, the corresponding development, testing and deployment will require repeated work, which is inefficient.

[0019] This embodiment provides a method for automatically generating database operation instructions from a WEB API request. Specifically, the WEB API adopts a REST API, and the data operation instructions adopt SQL, including the following steps:

[0020] With reference to the SQL data manipulation statement specification, based on the rules and connections between the query statements including SELECT, FROM, WHERE, GROUP BY, and ORDER BY and the REST API requests, the request data of each part of the query statement is included in the data structure specifications of the REST HTTP request line and request body, and a parsing of the WEB API request syntax to the intermediate representation IR is established.

[0021] Refer to the SQL data manipulation statement specification. For insert statements, the table name is included in the URI, and the field name and field value of the inserted row are organized in a key-value pair structure in the REST request body.

[0022] Refer to the SQL data manipulation statement specification. For update statements, include the table name and conditional expression in the URI. At the same time, organize the relevant table field names and corresponding field values ​​in the key-value pair structure in the REST API request structure.

[0023] Refer to the SQL data manipulation statement specification. For delete statements, include the table name and conditional expression in the URI.

[0024] Refer to the SQL data definition language specification to convert the data definition database operation instructions into the CRUD operations of field definition, and then use the above REST API request specification accordingly.

[0025] Analyze the rules of URI's PATH and QUERY and the format of the REST API request body, and establish mappings to clauses one by one; the REST API requests HTTP METHOD's GET, POST, PUT, and DELETE respectively implement CRUD operations on data resources.

[0026] According to the URI and request body information in the REST API, determine the database operation instruction category corresponding to the REST request, for example, whether the request is a database query instruction or a database definition instruction.

[0027] For database query instructions, the parsed REST HTTP METHOD operation is converted into the intermediate expression IR of the database CRUD instruction mode.

[0028] Specifically, the parsed URI and request body contain table name information. The field names and values ​​of the records appear in the request as key-value pairs and are converted into the intermediate expression IR of the database resource information. The predicates and expressions in the database operation instructions refer to the general EL expression specification and are converted into the intermediate expression IR of the expression.

[0029] For database definition instructions, the parsed CRUD operations are converted into intermediate expressions IR of instruction patterns such as table names and field definitions.

[0030] Specifically, the parsed URI and request body contain table name information, and the field definition information appears in the request in the form of key-value pairs, which are converted into the intermediate expression IR of the database operation instruction.

[0031] After the intermediate expression IR is generated, it is traversed according to the SQL grammar rules to generate SQL instructions.

[0032] Specifically, for the intermediate expression IR of data manipulation instructions, refer to the INSERT, SELECT, UPDATE, and DELETE specifications according to the CRUD categories, and traverse the intermediate expression IRs of table names, key-value pairs of record field names and their values, predicates, and expressions one by one to convert them into corresponding string representations in SQL, and then splice them from bottom to top according to the SQL query language grammar rules to generate complete SQL statement instructions.

[0033] Specifically, for the intermediate expression IR of the data definition instruction, the intermediate expression IR of the table name, field name, and field definition information key-value pairs are traversed one by one and converted into corresponding string representations in SQL, such as ADD, DROP COLUMN, and ALTER COLUMN statements of CREATE TABLE or ALTERTABLE; wherein the key-value pairs of the table name and field definition information are converted into strings of the corresponding field definitions in SQL, and the algorithm then performs bottom-up splicing according to the grammatical rules of the SQL definition language to generate a complete SQL statement instruction.

[0034] In one embodiment, the backend is a NOSQL database mongodb, and the WEB API request is converted into a mongodb database operation instruction through the algorithm;

[0035] In NOSQL databases, although the terminology is somewhat different from that of SQL, the present invention uniformly expresses it from the dimensions of library, table, row, and field. For example, in the mongodb of this embodiment, the database is similar to the concept of database in SQL, which is equivalent to the library in this patent; the collection is similar to the concept of table in SQL, which is equivalent to the table in this patent; the document is similar to the concept of row in SQL, which is equivalent to the row in this patent; the field is similar to the concept of column in SQL, which is equivalent to the field in this patent;

[0036] Specifically, analyze the rules of URI PATH and QUERY and the format of WEB API request body; WEB API request HTTP METHOD GET, POST, PUT, DELETE respectively implement CRUD operations on data resources, and convert them into intermediate expression IR of database CRUD.

[0037] The system will correspond the CRUD intermediate expression IR to the data processing commands of MongoDB, including insert, remove, find, and update methods, and use the JSON information in the request body as the method parameter, and then convert it into the database operation instructions of MongoDB.

[0038] Specifically, add the document intermediate expression IR and the document information intermediate expression IR in the request body and convert them into the mongdb database insert instruction; delete the document intermediate expression IR and the conditional information intermediate expression IR in the request line request body and convert them into the mongdb database remove instruction; modify the document intermediate expression IR and the json document information and conditional information intermediate expression IR in the request line request body and convert them into the mongdb database update instruction; search for the document intermediate expression IR and the conditional information intermediate expression IR in the request line request body and convert them into the mongdb database find instruction.

[0039] The present invention also adopts a method of converting a WEB API request into a database operation instruction and applies it to the software system. The overall architecture design of the system is shown in Figure 2 , the system comprising:

[0040] S1 input module, the system starts the database service and HTTP service, the HTTP service initializes the database connection and listens to the front-end request;

[0041] S2 conversion module, including: S21 parses the WEB API request submitted by the front end, and generates an intermediate representation IR according to the HTTP METHOD, URI and request body of the WEB API request. S22 traverses the intermediate representation IR and generates database operation instructions according to grammatical rules;

[0042] S3 execution module, the backend executes database operation instructions and obtains the database instruction execution results;

[0043] S4 display module, the backend returns the execution results and the frontend displays them;

[0044] The storage medium of the embodiment of the present invention stores a program file capable of implementing all the above methods, wherein the program file can be stored in the above storage medium in the form of a software product, including several instructions for enabling a computer device or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media capable of storing program codes, or a computer, a server, and a portable terminal device.

[0045] It should be noted that, in this article, the terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes one..." does not exclude the existence of other identical elements in the process, device, article or method including the element. In the absence of further restrictions, an element defined by the sentence "includes one of..." and a combination thereof does not exclude the existence of other identical elements in the process, device, article or method including the element.

[0046] It should be noted that SQL / NOSQL in the present invention refers to a relational database DBMS that can be standardized by SQL language, or a big data system that operates according to SQL language rules; NOSQL can be an unstructured database, or a non-SQL language specification, which provides an application interface for data resource organization methods similar to libraries, tables, rows and fields, and data resource operations such as addition, deletion, query and modification. The methods described in the present invention automatically realize the conversion of operation instructions for data resources with a unified WEB API request interface specification.

[0047] In the embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0048] The present invention expresses database operation instructions in the form of commands, objects, and parameters, which is a summary of the current relational database and non-relational database operation objects. The scope of the invention involved in this application is not limited to the technical solutions formed by the specific combination of the above technical features, but also should cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept.

[0049] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages and disadvantages of the embodiments. Through the description of the above implementation modes, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course, by hardware, but in many cases the former is a better implementation mode. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium as described above, and includes a number of instructions for enabling a terminal device to execute the methods described in each embodiment of the present invention.

Claims

1. A method for automatically generating database operation instructions from a WEB API request, characterized in that: By converting WEB API requests into intermediate representation IR, the intermediate representation IR is automatically converted into database operation instructions.

2. The method for automatically generating database operation instructions from a WEB API request as claimed in claim 1, characterized in that: include: The system establishes an intermediate representation IR conversion algorithm for each component of the database operation instruction, including commands, objects, parameters, as well as their operations, expressions, and clauses; Establish a WEB API request interface, including syntax conversion rules from request line and request body structure to intermediate representation IR; the system performs syntax parsing on the WEB API request and generates intermediate representation IR; Traverse the intermediate representation IR and generate database operation instructions according to the database operation instruction grammar rules.

3. The method for automatically generating database operation instructions from a WEB API request as claimed in claim 2, wherein the conversion rules include: The HTTP METHOD in the request line includes GET, POST, PUT, DELETE, URI and request body structure, which are converted into the intermediate representation IR of database operation instructions such as CRUD commands, as well as the intermediate representation IR including libraries, tables, rows, fields, operators, expressions and predicates.

4. The method for automatically generating database operation instructions from WEB API requests as described in claim 2, wherein the grammar rules include SQL grammar rules and / or NOSQL grammar rules.

5. A system, characterized in that: A system for realizing the method of automatically generating database operation instructions from a WEB API request as claimed in any one of claims 1 to 4.

6. A computer device, characterized in that: The method comprises a processor and a memory connected to the processor, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the method for automatically generating database operation instructions from a WEB API request as claimed in any one of claims 1 to 5.

7. A storage medium having a computer program stored thereon, characterized in that: The program is executed by a processor to implement the method for automatically generating database operation instructions from a WEB API request as claimed in any one of claims 1 to 5.

Citation Information

Patent Citations

  • An openEHR template-based data interface dynamic generation method

    CN106991276A

  • Compiler automatic verification method and apparatus

    CN107301121A

  • Configuration and execution method and system of a web API and medium

    CN109165039A

  • Compiling processing method and device and device for compiling processing

    CN111142876A

  • Data set generation method and device, electronic equipment and readable medium

    CN117194472A