Data query method and device, medium and product
By determining the interface path and query method in the microservice architecture, and generating and executing common SQL query statements, the cumbersome data query process in the microservice architecture is solved, and the data query efficiency is improved.
Patent Information
- Application Number
- CN202510258446.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-05
- Publication Date
- 2025-06-24
AI Technical Summary
In the microservice architecture, the data query process is too cumbersome and requires relying on multiple microservices to provide interfaces to complete data query, resulting in inefficiency.
By determining the interface path and query method in the data query request, the target SQL template is determined, and the query parameters replace placeholders are used to generate a common target SQL query statement, which is executed directly to obtain the query results.
The data query process is simplified, cumbersome interface calls are avoided, data query efficiency is improved, and dependence on private server warehouses is reduced.
Smart Images

Figure CN120196651A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technologies, and particularly to data query methods, devices, media, and products. Background Art
[0002] With the development of software technologies, microservice architectures are increasingly widely applied. In a company's microservice architecture, multiple application programs are built as independent components, and each application program process runs as a service.
[0003] After the microservice transformation of the business system architecture, database table information is split independently according to each service, to solve the problem of supporting data aggregation queries across multiple microservices. Especially if there are many current enterprise systems, the business will be split according to business domains (that is, split into multiple microservices), and the corresponding database tables will also be split with fine granularity. However, in some application scenarios, it is necessary to aggregate data from multiple microservices in the system, which means that it is necessary to rely on multiple microservices to provide interfaces to complete data queries, resulting in a too cumbersome data query process. Summary of the Invention
[0004] The present disclosure provides data query methods, devices, media, and products.
[0005] According to a first aspect of the present disclosure, a data query method is provided. The method is applied to a server, and specifically includes: In response to a data query request provided by a user, determining query parameters, an interface path, and a query method included in the data query request; wherein, the interface path is used to call data tables of each microservice in the microservice architecture; according to the interface path and the query method, determining a target SQL template; using the query parameters to replace placeholder characters in the target SQL template to obtain a target SQL query statement; after executing the target SQL query statement, querying a target query result from at least one microservice.
[0006] Based on the above, it can be known that in a microservice architecture, there are multiple different microservices, and each microservice has its own data table. When it is necessary to call the data table of a microservice, it is not necessary to establish a corresponding call interface for the microservice. Instead, a target SQL template can be determined according to the interface path and the query method included in the data query request. Then, after replacing the placeholder characters in the target SQL template, a general target SQL query statement can be directly generated. Furthermore, a query result is obtained after executing the target SQL query statement. There is no need to perform cumbersome interface calls or multiple interface calls, which can effectively improve the data query efficiency.
[0007] After executing the target SQL query statement according to at least one embodiment of the present disclosure, the target query result is obtained by querying from at least one microservice, including: determining whether the target class file corresponding to the target SQL query statement is included in the private repository; wherein, the compiled class files are stored in the private repository; if included, directly execute the target class file to obtain the target query result.
[0008] According to at least one embodiment of the present disclosure, it further includes: determining whether the target class file corresponding to the target SQL query statement is included in the private repository; if not included, according to the target SQL template, find the corresponding class template path from the first mapping table by looking up the table; wherein, the first mapping table includes the corresponding relationship between the SQL template and the class template path; based on the class template path, find the class template; add the input parameter name and output parameter name parsed from the target SQL query statement to the class template to generate the input parameter class file and the output parameter class file; compile the input parameter class file and the output parameter class file and package and deploy them to the private repository.
[0009] According to at least one embodiment of the present disclosure, determining the target SQL template according to the interface path and the query method includes: finding the corresponding target SQL template from the second mapping table according to the interface path and the query method; wherein, the second mapping table includes the corresponding relationship between the interface path, the query method and the target SQL template.
[0010] According to at least one embodiment of the present disclosure, it further includes: in response to a modification request for the call relationship of any microservice in the microservice architecture, modifying the mapping relationship of the target SQL template in the second mapping table; or, in response to a new request for a new microservice in the microservice architecture, adding a mapping relationship for calling the new microservice in the second mapping table.
[0011] Before determining the target SQL template according to the interface path and the query method according to at least one embodiment of the present disclosure, it further includes: determining the table name, output parameter name, and input parameter name used to construct the target SQL template; wherein, the table name includes the table names of at least one table in the microservice system; construct the target SQL template based on the table name, output parameter name, input parameter name, and placeholder; add the target SQL template to the second mapping table.
[0012] After executing the target SQL query statement according to at least one embodiment of the present disclosure, the target query result is obtained by querying from at least one microservice, including: intercepting the query result using the aspect script; filtering the query result according to the filtering conditions set in the aspect script to obtain the target query result that meets the filtering conditions.
[0013] According to a second aspect of the present disclosure, there is provided an electronic device, including: a memory that stores execution instructions; and a processor that executes the execution instructions stored in the memory, such that the processor executes the method described in the first aspect of any one of the embodiments of the present disclosure.
[0014] According to a third aspect of the present disclosure, there is provided a readable storage medium storing execution instructions, and when the execution instructions are executed by a processor, they are used to implement the method described in the first aspect of any one of the embodiments of the present disclosure.
[0015] According to a fourth aspect of the present disclosure, there is provided a computer program product including a computer program, and when the computer program is executed by a processor, it implements the method described in the first aspect of any one of the embodiments of the present disclosure. Description of the Drawings
[0016] The drawings illustrate exemplary embodiments of the present disclosure and, together with the description thereof, are used to explain the principles of the present disclosure. These drawings are included to provide a further understanding of the present disclosure and are included in this specification and form a part of this specification.
[0017] Figure 1 It is a schematic flowchart of a data query method provided by the present disclosure.
[0018] Figure 2 It is a schematic diagram of a second mapping table provided by the present disclosure.
[0019] Figure 3 It is a schematic diagram of a first mapping table provided by the present disclosure.
[0020] Figure 4 It is a schematic diagram of the process of modifying and adding a second mapping table provided by the present disclosure.
[0021] Figure 5 It is a schematic diagram of a data query process illustrated by an example of the present disclosure.
[0022] Figure 6 It is a schematic block diagram of the structure of a data query device according to an embodiment of the present disclosure.
[0023] Figure 7 It is a schematic block diagram of the structure of an electronic device according to an embodiment of the present disclosure. Detailed Embodiments
[0024] The present disclosure will be further described in detail below with reference to the drawings and examples. It can be understood that the specific examples described herein are only used to explain the relevant content and do not limit the present disclosure. Additionally, it should be noted that for the sake of description, only parts related to the present disclosure are shown in the drawings.
[0025] It should be noted that, without conflict, the embodiments in the present disclosure and the features in the embodiments can be combined with each other. The technical solutions of the present disclosure will be described in detail below with reference to the drawings and in combination with the embodiments.
[0026] In a microservices application scenario, a large application is split into multiple microservices. Each microservice can be developed, deployed, and scaled independently and maintains its own data table. When it is necessary to interact with a microservice, it is necessary to specifically call the corresponding call interface of the microservice. If a data query request involves multiple microservices, it is necessary to make multiple interface calls for multiple different microservices respectively. This makes the call process extremely cumbersome and the data query efficiency low. Therefore, a solution for data query in a microservices architecture that is simple and efficient is needed.
[0027] Term explanation.
[0028] For the convenience of description and to make the technical solutions of the specific embodiments of the present disclosure easier to understand, before describing the data query method implemented in the present disclosure, the technical terms involved in the specific embodiments of the present disclosure are explained as follows.
[0029] Microservice: It is an architecture and organizational method for developing software, where the software consists of small independent services that communicate through well-defined APIs. These services are responsible for each small independent team. The microservices architecture makes the application easier to scale and develop faster, thus accelerating innovation and shortening the time to market for new features. Using the microservices architecture, the application is built as independent components and each application process runs as a service. These services communicate through lightweight APIs via well-defined interfaces.
[0030] Structured Query Language (SQL) is a special-purpose programming language, a database query and programming language used to access data and query, update, and manage relational database systems. Structured Query Language is a high-level non-procedural programming language that allows users to work on high-level data structures. Structured Query Language statements can be nested, which gives it great flexibility and powerful functionality.
[0031] Private repository (Maven): The central repository is a public proxy repository provided by Alibaba Cloud to help R & D personnel improve R & D production efficiency. Using the Alibaba Cloud Maven central repository as the download source is faster and more stable.
[0032] Figure 1 The flowchart of a data query method provided for the present disclosure. As Figure 1The method shown includes steps 101 to 104. Among them, this method can be executed by an electronic device such as a server in a microservices system.
[0033] Specifically, Figure 1 The method shown includes: Step 101: In response to a data query request provided by a user, determine the query parameters, interface path, and query method included in the data query request; among them, the interface path is used to call data tables of each microservice in the microservices architecture.
[0034] In practical applications, the data query request issued by the user can be a query request sent to the microservices system through a client. This data query request can be a query statement in the form of a complete natural language input by the user in the client (for example, please help me query Li Ming's age), or it can be query parameters input by the user in the query search box (for example, the user inputs "Li Ming" in the query search box). In this data query request, only a general interface path needs to be provided to achieve the query of data tables of multiple different microservices. It is not necessary for the user to specify in the data query request which microservice to query data from, nor to specify the corresponding query interface, and accurate query of data of multiple different microservices can be achieved.
[0035] The query parameters mentioned here are the parameters in the query parameter column in the data tables of at least one microservice. This query parameter represents the data that the user wants to query. It should be noted that this query parameter is not the query result, but a parameter used to help find the query result from the data table.
[0036] The interface path mentioned here is a general interface (API). Through this interface path, it can be known from which table to query. Generally speaking, the table name is agreed upon in the interface path, but a specific microservice is not specified. Further, a corresponding SQL query statement can be generated by using a pre-set SQL template.
[0037] The query method mentioned here refers to the action type of this data query request. Generally, the "get" keyword can be used as the query keyword.
[0038] Step 102: Determine the target SQL template according to the interface path and the query method.
[0039] In practical applications, the above solution can be implemented by establishing a SQL template mapping table. Specifically, according to the interface path and the query method, the corresponding target SQL template is found from the second mapping table; among them, the second mapping table contains the corresponding relationship between the interface path, the query method, and the target SQL template.
[0040] Such as Figure 2 is a schematic diagram of the second mapping table provided by this disclosure. FromFigure 2 As can be seen, in the second mapping table, the correspondence between the API interface path, the query method, and the SQL template is set. Specifically, the API interface path is / api / students, where students represents the table name to be queried. The query method is Get.
[0041] When establishing the second mapping table, it is necessary to first determine the table name, output parameter name, and input parameter name used to construct the target SQL template; among them, the table name includes the table names of at least one table in the microservice system; based on the table name, output parameter name, input parameter name, and placeholder, the target SQL template is constructed; the target SQL template is added to the second mapping table.
[0042] SELECT age FROM student WHERE name = :name is the SQL template. In this SQL template, SELECT: This is part of the SQL statement, used to specify which columns (fields) of data to retrieve from the database table. In this example, SELECT age means wanting to retrieve the data of the age column in the student table.
[0043] age: This is the output parameter name specified in the SELECT clause, indicating the data field that wants to be obtained. In this context, age represents the age of the student.
[0044] FROM: This is also part of the SQL statement, used to specify from which table to retrieve data. FROM student means retrieving data from the table named student.
[0045] student: This is the table name specified in the FROM clause, indicating the database table from which to retrieve data. In this example, the student table stores student information.
[0046] WHERE: This is a conditional clause of the SQL statement, used to specify the condition for retrieving data. Only records that meet this condition will be included in the result set. WHERE name = :name means only retrieving those records whose name column value is equal to a specific value.
[0047] name: This is the input parameter name specified in the WHERE clause, indicating the condition field used to filter records. In this context, name represents the name of the student.
[0048] =: This is a comparison operator, used to compare whether two values are equal. In the WHERE clause, it is used to specify the filtering condition.
[0049] :name: This is a placeholder (also known as a parameter in a parameterized query) that is used to be replaced with a specific value when executing a query. In this example, :name will be replaced with the name entered by the user (such as "Li Ming") in order to retrieve the age of the student with that name.
[0050] The meaning of the SQL query statement "SELECT age FROM student WHERE name = :name" is: Retrieve the age column data of those records from the student table whose name column value is equal to the specified name (represented by the :name placeholder). When executing the query, the :name placeholder will be replaced with the actual name value, thereby retrieving the age of the student with that name.
[0051] Step 103: Use the query parameters to replace the placeholders in the target SQL template to obtain the target SQL query statement.
[0052] It should be noted that the placeholders in the target SQL template can be dynamically replaced, that is, when different users have different data query requests, the same SQL template can be used, and the corresponding SQL query statement can be obtained after placeholder replacement. For example, user A enters the query parameter "Li Ming" and uses the Figure 2 shown SQL template to implement the age query. User B enters the query parameter "Zhang San" and can also use the Figure 2 shown SQL template to implement the age query. Using the same template can meet the multiple data query needs of multiple users, and neither of these two queries requires a separate establishment of a corresponding call interface.
[0053] The placeholder mentioned here is a special symbol or string used to represent the value that needs to be filled in the future (i.e., the query parameter) in the output format, or to temporarily replace the actual content during the editing process in order to preview the overall layout and format.
[0054] Based on Figure 2 the shown embodiment, after completing the placeholder replacement, the target SQL query statement that can be obtained is SELECT age FROM student WHERE name = "Li Ming".
[0055] Step 104: After executing the target SQL query statement, query the target query result from at least one of the microservices.
[0056] After generating the target SQL query statement using the SQL template, the target SQL query statement can be executed to query the required target query result from the microservice system. The target query result can be the result queried from one or more microservices in the microservice architecture.
[0057] In the above-mentioned disclosed solution, there are several solutions to implement data query for multiple different microservices through a unified interface path. For example, the API Gateway pattern can be utilized. As a single entry point for all client requests, it is responsible for routing requests to the corresponding microservices and returning responses to the clients. Through the API Gateway, the calls to each microservice can be encapsulated, and a unified interface can be provided externally. Routing rules are configured in the API Gateway to map specific request paths to the corresponding microservice interfaces. The API Gateway can handle Cross-Origin Resource Sharing (CORS) issues, enabling the front-end application to more conveniently call the back-end services. Authentication and authorization are uniformly processed at the API Gateway layer, reducing the repetitive work of each microservice.
[0058] Based on the above content, it can be known that in a microservice architecture, there are multiple different microservices, and each microservice has its own data table. When it is necessary to call the data table of a microservice, there is no need to establish a corresponding call interface for this microservice. Instead, the target SQL template can be determined according to the interface path and query method included in the data query request. Then, after replacing the placeholder in the target SQL template, a general target SQL query statement can be directly generated. Furthermore, the query result can be obtained by executing the target SQL query statement. There is no need to perform cumbersome interface calls or multiple interface calls, which can effectively improve the data query efficiency.
[0059] In one or more embodiments of the present disclosure, after executing the target SQL query statement, the target query result is retrieved from at least one of the microservices, including: determining whether a target class file corresponding to the target SQL query statement is included in the private repository; wherein, the private repository stores the compiled class files; if it is included, the target class file is directly executed to obtain the target query result.
[0060] The private repository stores the class files generated according to the SQL query statement previously. Before executing the target SQL query statement, to avoid the unnecessary workload caused by repeated compilation, it is possible to first query whether there is a class file corresponding to the target SQL query statement in the private repository after generating the target SQL query statement. If it exists, it can be directly called and executed without repeated compilation and deployment, which can significantly improve the data query efficiency.
[0061] When retrieving from the private repository, the command-line tool or API of the build tool can be used to retrieve whether the target class file exists in the private repository. This generally involves checking the dependencies and version numbers, as well as the class file path.
[0062] In languages such as Java, a class loader is required to load the class files downloaded from the private server repository. This may involve placing the class files in a specific directory or JAR package and configuring the classpath. If the class files contain methods for executing SQL queries, the Java reflection mechanism can be used to call these methods. This requires the class files to have accessible public methods or constructors. When executing the class files, it is necessary to handle possible exceptions, such as class not found exceptions, method not found exceptions, SQL execution exceptions, etc.
[0063] It should be noted that the private server repository of this solution stores the compiled class files, and these class files contain the logic for executing SQL queries. If the private server repository stores the compiled files. If the stored files are source code or other formats, then corresponding compilation or conversion steps are required to generate executable class files.
[0064] Based on the above disclosed solution, by storing the class files corresponding to the query statements in the private server repository, it is not necessary to perform cumbersome operations such as compilation and deployment every time a query statement is executed, which can effectively improve the processing efficiency of data query work.
[0065] In one or more embodiments of the present disclosure, it further includes: determining whether the private server repository contains the target class file corresponding to the target SQL query statement. If not, according to the target SQL template, the corresponding class template path is found from the first mapping table by looking up the table; wherein, the first mapping table contains the corresponding relationship between the SQL template and the class template path. Based on the class template path, the class template is found. The input parameter names and output parameter names parsed from the target SQL query statement are added to the class template to generate the input parameter class file and the output parameter class file. The input parameter class file and the output parameter class file are compiled and packaged and deployed to the private server repository.
[0066] In practical applications, if the target class file corresponding to the target SQL query statement is not stored in the private server repository, it may be because the target SQL query statement is a query statement generated for the first time. After this execution is completed, the target class file corresponding to the generated target SQL query statement can be stored in the private server repository.
[0067] Such as Figure 3 is a schematic diagram of the first mapping table provided by the present disclosure. From Figure 3 it can be seen that in the first mapping table, the subsequent SQL templates and class template paths are stored according to the mapping relationship. That is, the path of the class template corresponding to the SQL template "SELECT age FROM student WHERE name = :name" is / templates / input / Input-F1.
[0068] After finding the class template path, the class template can be further located according to the class template path. The class templates mentioned here can be divided into input parameter class templates and output parameter class templates. Further, the target SQL query statement can be parsed to extract the input parameter names and output parameter names contained therein. The extraction can be accomplished using regular expressions, an SQL parsing library, or a custom parser. An object or data structure containing detailed information about the input parameter names and output parameter names is obtained. Specifically, Figure 3 the "name" in
[0069] After filling the input parameters in the target SQL query statement into the input parameter class template to generate the input parameter class file, and filling the output parameters into the output parameter class template to generate the output parameter class file, the class files can be further compiled. Ensure that the compilation environment is correctly configured, including build tools such as JDK, Maven, or Gradle. Use the command-line tool of the build tool to compile the generated class files. For example, in a Maven project, the "mvn compile" command can be run. Check for possible errors during compilation and correct the code or configuration to ensure successful compilation.
[0070] After compilation is completed, packaging and deployment will be carried out. Use the build tool to package the compiled class files into a JAR package or other format of package file. For example, in a Maven project, the "mvn package" command can be run to generate a JAR package. Ensure that the private repository (such as Nexus, Artifactory, etc.) is correctly configured and has the permission to publish package files. Use the command-line tool of the build tool to deploy the packaged files to the private repository. For example, in a Maven project, the distribution Management node can be configured to specify the address of the private repository, and the "mvn deploy" command can be run to deploy the package files. Verify the published package files in the private repository to ensure that they can be correctly referenced by other projects.
[0071] Based on the above disclosed solution, after the user provides a data query request, the automatic generation of code is realized, reducing the workload of manually writing and maintaining JavaBean class files. By automatically compiling, packaging, and deploying these dynamically generated class files to the Maven private repository, the development efficiency and the convenience of code management are improved.
[0072] Deploying class files to the Maven private repository can effectively improve development efficiency. By simplifying dependency management and accelerating the build process, deploying to the Maven private repository can significantly enhance development efficiency, enabling developers to build, test, and deploy applications more quickly. Through the management of different class file versions and dependency sharing, it can ensure that the dependent libraries and components used in the project are stable and compatible, thus reducing project failures caused by dependency issues. Centralizing the management of shared dependent libraries and components can lower maintenance costs because these dependencies only need to be updated and maintained in one place, rather than separately in each project. Deploying dynamically generated input and output class files to the Maven private repository has various uses and benefits in the software development and deployment process, including improving development efficiency, enhancing project stability, reducing maintenance costs, and promoting team collaboration, etc.
[0073] In one or more embodiments of the present disclosure, it further includes: in response to a modification request for the call relationship of any microservice in the microservice architecture, modifying the mapping relationship of the target SQL template in the second mapping table; or, in response to a new request for a new microservice in the microservice architecture, adding a mapping relationship for the call of the new microservice in the second mapping table.
[0074] In practical applications, the call relationships of each microservice are all implemented through the second mapping table. As Figure 4 This is a schematic diagram of the modification and addition process of the second mapping table provided by the present disclosure. From Figure 4 it can be seen that a mapping relationship between the interface path, query method, and SQL template is established in the second mapping table. To facilitate understanding, a description content "query age according to name" can also be added to explain the role of the SQL template.
[0075] When a user wants to modify the mapping relationship, for example, because the table storing student-related information is transferred to the data table of another microservice, at this time, only need to know the table name of the transferred data table and modify the table name to achieve the modification of the mapping relationship.
[0076] For example, before modification, the interface path: / api / students, SQL template: SELECT age FROM student WHERE name = :name. After modification, the interface path: / api / students1, SQL template: SELECT age FROM student WHERE name = :name. It can be seen that only by simply modifying the mapping relationship between the table name and the SQL template can the modification of the service call relationship be achieved. There is no need to perform cumbersome operations such as modifying the call interface, which can effectively reduce the workload of modifying the call relationship.
[0077] When the user wants to add a mapping relationship, for example, add a microservice for managing teacher-related information, the interface path / api / teacher can be added to the second mapping relationship table, and the SQL template: SELECT age FROM teacher WHERE name = :name. Here, teacher represents the table name of the data table used to store teacher-related information. The role of the SQL template is also to query the age based on the name. By establishing the mapping relationship between the new table name and the SQL template, the relevant data query function can be realized without writing the code related to the interface call for the microservice. It can effectively improve work efficiency.
[0078] After executing the target SQL query statement in one or more embodiments of the present disclosure, the target query result is obtained by querying from at least one of the microservices, including: intercepting the query result by using the aspect script; filtering the query result according to the filtering conditions set in the aspect script to obtain the target query result that meets the filtering conditions.
[0079] The aspect script can be understood as a scripting language or script file used to describe the definition of aspects, pointcut expressions, and advice in aspect-oriented programming. In Java development, this is usually achieved by using the Spring AOP framework and annotations. In the solution of the present disclosure, the aspect script is used to implement the filtering of the query result.
[0080] The filtering conditions mentioned here are defined by the user according to their own needs. For example, the user can set the filtering condition to filter those with an age less than 15, or can also set the age range.
[0081] For example, define an aspect script, which will be used to intercept the query result and process it according to the set filtering conditions. In this example, the filtering condition is to delete the data with an age less than 18 years old.
[0082] Configure the aspect script and configure the aspect script into the application. This usually involves adding the aspect script to a specific configuration file or annotation so that it can be loaded and executed when the application starts. The specific configuration method depends on the framework and tools used. For example, in the Spring framework, the aspect can be configured through XML configuration or annotation. In AspectJ, the aspect can be defined through a dedicated AspectJ configuration file.
[0083] When the query method is called, the aspect script will intercept its return result. In this example, the query method may be located in a certain service class and returns a list containing the query result.
[0084] The advice in the aspect script is executed after the query method returns the result. It iterates through the result list, deletes the records where the age is less than 18, and replaces the original result list with the filtered result list (or updates the original list, depending on the implementation).
[0085] Intercept the result list returned by the query method. Iterate through the result list and check the age of each result. Add the records where the age is greater than or equal to 18 to a new list. Replace the original list with the new list (or update the original list).
[0086] After the filtering process, C (age 16) in the query result is deleted, and A (age 21) and B (age 20) are retained. Finally, the service method returns the filtered result list. Final target query result: The query result list contains the ages of A and B. The age of C is successfully deleted.
[0087] The aspect script allows developers to flexibly process the returned results without modifying the original query logic. This means that even if the underlying data model or query logic changes, the filtering logic can remain unchanged or only require minor adjustments. The aspect script can be easily enabled or disabled according to different business scenarios or requirements, providing greater flexibility to developers.
[0088] In addition, in some cases, it may be more efficient to place the filtering logic on the client side (i.e., the application level) rather than the server side (i.e., the database level). For example, when the query result set is very large but the actual amount of data needed is small, filtering on the client can reduce the data transfer volume and server processing time.
[0089] To facilitate understanding of the technical solution of the present disclosure, the implementation process of this solution will be illustrated by specific examples below. As Figure 5 is a schematic diagram of the data query process for illustrating the present disclosure.
[0090] From Figure 5 it can be seen that the data query system includes a client operated by the user, a server for providing data query service functions, and a database for storing relevant data. Of course, if the data volume is not large, the relevant data to be queried can also be stored in the server without the need for a separate database to store it.
[0091] For example, a user wants to use the query function of a mobile APP to query a person's age according to the name.
[0092] Step 501: The user enters the name "Li Ming" in the input box of the mobile APP and clicks the query button.
[0093] Step 502: The mobile phone APP generates a data query request based on this query button and sends the data query request to the server. Among them, this data query request includes the query parameter "Li Ming", the API interface path " / api / students", and the query method "get".
[0094] Step 503: The server receives the query request from the mobile phone APP.
[0095] Step 504: The server parses this query request and extracts the query parameter "Li Ming", the API interface path " / api / students", and the method "get".
[0096] Step 505: The server looks up the target SQL template corresponding to the API interface path " / api / students" and the query method "GET" in the second mapping table (as Figure 2 shown).
[0097] Among them, the SQL template itself is predefined and contains the basic structure and placeholder of the query. Moreover, the SQL template is dynamic and it can change the specific content of the query according to the incoming parameter values.
[0098] For example, in combination with the second mapping table, the target SQL template obtained by the server in the second mapping table is "SELECT age FROM student WHERE name = :name". Among them, the API interface path is: / api / students. The query method is: get. SQL template: SELECT age FROM student WHERE name = :name. Template function description: Query age according to name.
[0099] Step 506: The server replaces the placeholder ":name" in the target SQL template with the query parameter "Li Ming" to form a specific query statement: "SELECT age FROM student WHERE name = 'Li Ming'".
[0100] Among them, the server replaces the query parameters input by the user into the placeholders of the SQL template, and this process is dynamic and it can dynamically generate different query statements according to different query parameters input by the user.
[0101] Step 507: The server determines the path of the class template corresponding to the target SQL template. Based on the first mapping table ( Figure 3It can be known from [[ID=]] that the path of the class template corresponding to the SQL template "SELECT age FROM student WHERE name = :name" is / templates / input / Input-F1.
[0102] Step 508: The server determines the class template according to the path of the class template. Among them, the server can find the corresponding class template based on the path of the class template.
[0103] For example, the class template is: public class ${className} { / / Fields added dynamically will be inserted here } ${className} is a placeholder that will be replaced with a specific class name during generation.
[0104] Step 509: The server parses the SQL template and identifies the input parameter fields and output parameter fields in the SQL template.
[0105] For example, in the SQL template SELECT age FROM students WHERE name = :name, the server can identify that name is an input parameter field (i.e., the input parameter name), and age is an output parameter field (i.e., the return parameter column name, the output parameter name).
[0106] Step 510: The server adds the input parameter fields and output parameter fields parsed from the target SQL query statement to the class template respectively to generate an input parameter class and an output parameter class.
[0107] Among them, the server can automatically generate the class name input for the input parameter class corresponding to the input parameter field name, and add the input parameter field name to the input parameter class template to generate the input parameter class file input.
[0108] For example, the generated input parameter class input is: public class input{ private String name; } Among them, the server can automatically generate the class name output for the output parameter class corresponding to the output parameter field age, and add the output parameter field age to the class template to generate the output parameter class file output.
[0109] For example, the generated output parameter class output is: public class output{ private int age; } Step 511: The server automatically compiles and packages the dynamically generated input parameter class file and output parameter class file, and deploys them to the Maven private repository. In subsequent applications, the stored class files can be directly called from the private repository according to the query requirements, without having to rewrite and compile the class files again, effectively improving the work efficiency of data query.
[0110] Step 512: The server executes the target query statement generated in Step 506: "SELECT age FROM student WHERE name = 'Li Ming'", and obtains the target query result.
[0111] Among them, after the server obtains the target query result, the server can create an object of the output class file according to the target query result, and encapsulate the target query result into the object created by using the output class file.
[0112] For example, if the query result contains the ages of multiple students, the server will create an output object for the age of each student.
[0113] Step 513: In some cases, the query result obtained can be further filtered. When filtering, the microservice does not need to be modified, and the addition of filtering conditions can be achieved by using an aspect script. The server intercepts the query result generated by the query statement, and filters the query result according to the filtering conditions preset by using the script to obtain the final target query result.
[0114] For example, assume that the filtering condition is to delete the data with an age less than 18 years old in the query result. If the query result includes the ages of A, B, and C, the age of A is 21 years old, the age of B is 20 years old, and the age of C is 16 years old, then the server will delete the age of C in the query result based on the filtering condition, and retain the ages of A and B, so as to obtain the final target query result.
[0115] Step 514: The server sends the final target query result to the mobile phone that sent the data query request.
[0116] Based on the above embodiments, it can be seen that in the solution, by defining the API interface path (such as / api / students) and the associated SQL template, the centralized processing of business logic is achieved. This means that originally, multiple service interfaces might need to be called (such as first querying the user ID and then querying the age based on the ID), but now it can be completed through one interface, improving the efficiency. The use of the dynamic SQL template allows the server to dynamically generate specific SQL query statements according to the incoming parameters. This flexibility reduces the number of interfaces because there is no need to design a separate interface for each possible query scenario.
[0117] When it is necessary to modify or expand the function, only the corresponding mapping table or SQL template and class template need to be updated, without the need to perform a large-scale reconstruction of the entire system, thereby improving the maintainability of the system and the efficiency of development iteration.
[0118] Based on any of the above embodiments, the present disclosure also provides a data query device. This device can be applied in a microservices architecture. Figure 6 It is a structural schematic block diagram of the data query device according to an embodiment of the present disclosure. As Figure 6 shown, the data query device includes: a first determination module 61, configured to determine the query parameters, interface path, and query method included in the data query request in response to the data query request provided by the user; wherein, the interface path is used to call the data tables of each microservice in the microservices architecture.
[0119] A second determination module 62, configured to determine the target SQL template according to the interface path and the query method.
[0120] A replacement module 63, configured to replace the placeholder in the target SQL template with the query parameter to obtain the target SQL query statement.
[0121] An execution module 64, configured to query the target query result from at least one microservice after executing the target SQL query statement.
[0122] Optionally, it further includes a judgment module 65, configured to judge whether the private repository contains the target class file corresponding to the target SQL query statement; wherein, the private repository stores the compiled class files; if it contains, directly execute the target class file to obtain the target query result.
[0123] The determination module 65 is further configured to determine whether the target class file corresponding to the target SQL query statement is included in the private server repository; if not, according to the target SQL template, find the corresponding class template path from the first mapping table through a table lookup method; wherein, the first mapping table includes the correspondence between the SQL template and the class template path; based on the class template path, find the class template; add the input parameter name and output parameter name parsed from the target SQL query statement to the class template to generate an input parameter class file and an output parameter class file; compile the input parameter class file and the output parameter class file, and package and deploy them to the private server repository.
[0124] The second determination module 62 is configured to find the corresponding target SQL template from the second mapping table according to the interface path and the query method; wherein, the second mapping table includes the correspondence between the interface path, the query method and the target SQL template.
[0125] The second determination module 62 is further configured to, in response to a modification request for the call relationship of any microservice in the microservice architecture, modify the mapping relationship of the target SQL template in the second mapping table; or, in response to a new request for a new microservice in the microservice architecture, add a mapping relationship for the call of the new microservice in the second mapping table.
[0126] The second determination module 62 is further configured to determine the table name, output parameter name, and input parameter name used to construct the target SQL template; wherein, the table name includes the table names of at least one table in the microservice system; based on the table name, output parameter name, input parameter name, and placeholder, construct the target SQL template; add the target SQL template to the second mapping table.
[0127] The execution module 64 is further configured to intercept the query result using the aspect script; according to the filtering conditions set in the aspect script, filter the query result to obtain the target query result that meets the filtering conditions.
[0128] For the implementation processes of the functions and effects of each module in the above device, please refer to the implementation processes of the corresponding steps in the above method for details, and will not be elaborated here.
[0129] The execution subject of the data query method in the specific implementation manner of the present disclosure may be an electronic device such as a server (including a local server or a cloud server).
[0130] Therefore, based on any of the above embodiments, the present disclosure further provides an electronic device, which can execute the data query method of any of the above embodiments described in the present disclosure.
[0131] Figure 7 It is a structural schematic block diagram of an electronic device according to an embodiment of the present disclosure.
[0132] The hardware structure of the electronic device 1000 can be implemented using a bus architecture. The bus architecture can include any number of interconnected buses and bridges, depending on the specific application of the hardware and the overall design constraints. The bus 1100 connects various circuits including one or more processors 1200, a memory 1300, and / or hardware modules together. The bus 1100 can also connect various other circuits 1400 such as peripheral devices, voltage regulators, power management circuits, external antennas, etc.
[0133] The bus 1100 can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Component (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, only one connecting line is used in this figure, but it does not mean that there is only one bus or one type of bus.
[0134] The present disclosure also provides a readable storage medium in which a computer program is stored. When the computer program is executed by a processor, it is used to implement the above-mentioned method. The "readable storage medium" can be any device that can contain, store, communicate, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. More specific examples of the readable storage medium include the following: an electrical connection part (electronic device) having one or more wirings, a portable computer disk cartridge (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable read-only memory (CDROM), etc.
[0135] The present disclosure also provides a computer program product. The method of the present disclosure can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instructions are loaded and executed, the processes or functions of the present disclosure are executed in whole or in part.
[0136] Computer programs or instructions can be stored in a readable storage medium or transmitted from one readable storage medium to another. For example, the computer programs or instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired or wireless manner. The readable storage medium can be any available medium that can be accessed or a data storage device such as a server or data center integrating one or more available media. The available medium can be a magnetic medium, such as a floppy disk, hard disk, or magnetic tape; it can also be an optical medium, such as a digital video disc; or it can be a semiconductor medium, such as a solid-state drive. The computer-readable storage medium can be a volatile or non-volatile storage medium, or can include both volatile and non-volatile types of storage media.
[0137] Those skilled in the art should understand that the embodiments of the present disclosure can be provided as a method, system, or computer program product. Therefore, the present disclosure can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present disclosure can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memory, CD-ROM, optical memory, etc.) containing computer-usable program code.
[0138] The present disclosure is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to the present disclosure. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data query devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data query devices generate means for implementing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0139] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data query device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction means that implement the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0140] These computer program instructions can also be loaded onto a computer or other programmable data query device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process. Thus, the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in the Figure 1 one process or multiple processes and / or blocks Figure 1 steps of the functions specified in one block or multiple blocks.
[0141] In the description of this specification, the descriptions referring to terms such as "one embodiment / way", "some embodiments / ways", "example", "specific example", or "some examples", etc. mean that the specific features, structures, or characteristics described in connection with the embodiment / way or example are included in at least one embodiment / way or example of the present disclosure. In this specification, the schematic expressions of the above terms do not necessarily refer to the same embodiment / way or example. Moreover, the specific features, structures, or characteristics described can be combined in a suitable manner in any one or more embodiments / ways or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments / ways or examples described in this specification and the features of different embodiments / ways or examples.
[0142] In addition, the terms "first" and "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" can explicitly or implicitly include at least one of the features. In the description of the present disclosure, "a plurality" means at least two, such as two, three, etc., unless otherwise specifically and clearly defined.
[0143] Those skilled in the art should understand that the above embodiments are only for clearly explaining the present disclosure and are not intended to limit the scope of the present disclosure. For those skilled in the art, other changes or variations can be made based on the above disclosure, and these changes or variations are still within the scope of the present disclosure.
Claims
1. A data query method, characterized in that: Applied to a microservice architecture, the method includes: In response to a data query request provided by a user, determine the query parameters, interface path and query method contained in the data query request; wherein the interface path is used to call the data table of each microservice in the microservice architecture; Determine a target SQL template according to the interface path and the query method; Using the query parameters to replace the placeholders in the target SQL template to obtain a target SQL query statement; After executing the target SQL query statement, a target query result is obtained from at least one of the microservices.
2. The method according to claim 1, characterized in that After executing the target SQL query statement, querying and obtaining a target query result from at least one of the microservices includes: Determine whether the private service warehouse contains the target class file corresponding to the target SQL query statement; wherein the private service warehouse stores the compiled class file; If included, the target class file is directly executed to obtain the target query result.
3. The method according to claim 2, characterized in that Also includes: Determine whether the private server warehouse contains the target class file corresponding to the target SQL query statement; If not, find the corresponding class template path from the first mapping table by looking up the target SQL template; wherein the first mapping table contains the correspondence between the SQL template and the class template path; Based on the class template path, find the class template; Add the input parameter name and output parameter name parsed from the target SQL query statement to the class template to generate an input parameter class file and an output parameter class file; The input parameter class file and the output parameter class file are compiled, packaged and deployed to the private server warehouse.
4. The method according to claim 1, characterized in that: The step of determining a target SQL template according to the interface path and the query method includes: According to the interface path and the query method, the corresponding target SQL template is found from the second mapping table; wherein the second mapping table contains the correspondence between the interface path, the query method and the target SQL template.
5. The method according to claim 4, characterized in that Also includes: In response to a request to modify a call relationship of any microservice in the microservice architecture, modify a mapping relationship of a target SQL template in the second mapping table; or, In response to a new request for a new microservice in the microservice architecture, a mapping relationship for calling the new microservice is added to the second mapping table.
6. The method according to claim 4, characterized in that Before determining the target SQL template according to the interface path and the query method, the method further includes: Determine the table name, output parameter name, and input parameter name used to construct the target SQL template; wherein the table name includes the table name of at least one table in the microservice system; The target SQL template is constructed based on the table name, the output parameter name, the input parameter name, and the placeholder; Add the target SQL template to the second mapping table.
7. The method according to claim 1 or 2, characterized in that: After executing the target SQL query statement, querying and obtaining a target query result from at least one of the microservices includes: Use aspect scripts to intercept query results; According to the filtering conditions set in the aspect script, the query results are filtered to obtain the target query results that meet the filtering conditions.
8. An electronic device, characterized in that: include: A memory storing execution instructions; as well as A processor, wherein the processor executes the execution instructions stored in the memory, so that the processor executes the method according to any one of claims 1 to 7.
9. A readable storage medium, characterized in that: The readable storage medium stores execution instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Multi-agent collaborative data query method and device
CN120470019A