Data query method and device, electronic equipment and program product
By receiving client query requests, processing and converting query parameters, and generating structured query languages, the complexity and maintenance difficulty of data query modules in software development are solved, and development efficiency and system quality are improved.
Patent Information
- Application Number
- CN202411320257.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-20
- Publication Date
- 2024-12-27
AI Technical Summary
During the software development process, the separate design, development and testing of the data query module is large and the process is complex, resulting in a long development cycle and a lack of unified standards, which increases the difficulty and cost of software maintenance.
By receiving the client's query request, determine whether the target module and query parameters contain custom pre-logic logic, perform parameter conversion, and generate structured query language query results from the database, providing a unified interface and flexible custom logic to adapt to different Data storage environment.
It reduces the amount of development tasks, reduces communication costs, improves the flexibility, efficiency and compatibility of the system, enhances data processing capabilities, adapts to different data storage environments, and improves code reusability and development efficiency.
Smart Images

Figure CN119201976A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data query method, device, electronic equipment and program product. Background Art
[0002] With the development of social science and technology, more and more enterprises and units have increasing demands for digitalization, and the demand for software development is also gradually increasing. In the process of software development, data query is a high-frequency demand scenario; the traditional approach is to design, develop, test and launch each module separately, and the client obtains data through API requests, and the program logic written in each module processes the query request and returns the result.
[0003] However, in the prior art, since query requirements account for a huge proportion of software programs, usually 25%-60% of the entire system functions, the query interface of each query module is designed, developed and tested separately, resulting in a huge workload; the development of a single module requires a complex process, and a large number of query module functions will multiply the development cycle; in addition, there is no unified standard, and the request path and parameters of each query module are not unified, which increases the difficulty and cost of software maintenance. Summary of the invention
[0004] The present application provides a data query method, device, electronic device and program product to solve the technical problems that when any query module processes data query requirements, the query module used is independently designed, developed and tested with a large workload, the process is complicated and the cycle is long, the standards are not unified and the maintenance cost is high.
[0005] In a first aspect, the present application provides a data query method, comprising:
[0006] Receiving a query request sent by a client, wherein the query request includes a target module to be queried and query parameters;
[0007] Determining whether the query request includes a custom pre-logic based on the target module and the query parameter;
[0008] If the query request includes a custom pre-logic, the query parameters in the query request are converted to obtain converted query parameters;
[0009] Based on the target module and the converted query parameters, a structured query language is generated, and the structured query language is used to query the database to be queried to obtain a query result.
[0010] Optionally, the determining whether the query request includes a custom pre-logic based on the target module and the query parameter includes:
[0011] Determine whether the target module is a preconfigured module containing custom pre-logic, and whether the query parameter is an existing parameter of the target module;
[0012] If the target module is a preconfigured module including a custom pre-logic, and the query parameter is not an existing parameter in the target module, it is determined that the query request includes the custom pre-logic.
[0013] Optionally, if the query request includes a custom pre-logic, converting the query parameters in the query request to obtain the converted query parameters includes:
[0014] If the query request includes a custom pre-logic, based on the correspondence between the query parameter and the existing parameter of the target module, the query parameter is converted into a target parameter in the existing parameter of the target module, and the target parameter is the converted query parameter.
[0015] Optionally, the method further includes:
[0016] Determining whether the query request includes custom post-logic based on the query parameters;
[0017] If the query request contains custom post-logic, the query result is converted and sent to the client.
[0018] Optionally, determining whether the query request includes a custom post-logic based on the query parameter includes:
[0019] If the query parameter is not an existing parameter in the target module, or the query parameter is a preset parameter containing a custom post-logic, it is determined that the query request contains a custom post-logic.
[0020] Optionally, the converting the query result includes:
[0021] If the query parameter is not an existing parameter in the target module, converting the query result based on the corresponding relationship between the query parameter and the target parameter;
[0022] If the query parameter is a preset parameter including a custom post-logic, the query result is converted based on the preset custom post-logic corresponding to the query parameter.
[0023] Optionally, generating a structured query language based on the target module and the converted query parameters includes:
[0024] Based on the converted query parameters, determining whether the database to be queried is an external database;
[0025] If the database to be queried is an external database, generating a structured query language for the external database based on the target module and the converted query parameters;
[0026] If the database to be queried is not an external database, a structured query language for the database to be queried is generated based on the target module and the converted query parameters.
[0027] In a second aspect, the present application provides a data query device, comprising:
[0028] The receiving module is used to receive a query request sent by a client, wherein the query request includes a target module to be queried and query parameters.
[0029] A processing module is used to determine whether the query request contains a custom pre-logic based on the target module and the query parameter.
[0030] If the query request contains a custom pre-logic, the processing module is further configured to convert the query parameters in the query request to obtain converted query parameters.
[0031] The processing module is further used to generate a structured query language based on the target module and the converted query parameters, and use the structured query language to query the database to be queried to obtain a query result.
[0032] Optionally, the processing module is further used to determine whether the target module is a preconfigured module containing custom pre-logic, and whether the query parameter is an existing parameter of the target module.
[0033] If the target module is a preconfigured module including a custom pre-logic, and the query parameter is not an existing parameter in the target module, the processing module is further configured to determine that the query request includes the custom pre-logic.
[0034] Optionally, if the query request contains custom pre-logic, the processing module is also used to convert the query parameter into a target parameter in the existing parameters of the target module based on the correspondence between the query parameter and the existing parameters of the target module, and the target parameter is the converted query parameter.
[0035] Optionally, the processing module is further used to determine whether the query request contains custom post-logic based on the query parameters.
[0036] If the query request contains a custom post-logic, the processing module is further configured to perform conversion processing on the query result and send the converted query result to the client.
[0037] Optionally, if the query parameter is not an existing parameter in the target module, or the query parameter is a preset parameter containing a custom post-logic, the processing module is further configured to determine whether the query request contains a custom post-logic.
[0038] Optionally, if the query parameter is not an existing parameter in the target module, the processing module is further configured to perform conversion processing on the query result based on a correspondence between the query parameter and the target parameter.
[0039] If the query parameter is a preset parameter including a custom post-logic, the processing module is further configured to perform conversion processing on the query result based on the preset custom post-logic corresponding to the query parameter.
[0040] Optionally, the processing module is further used to determine whether the database to be queried is an external database based on the converted query parameters.
[0041] If the database to be queried is an external database, the processing module is further configured to generate a structured query language for the external database based on the target module and the converted query parameters.
[0042] If the database to be queried is not an external database, the processing module is further configured to generate a structured query language for the database to be queried based on the target module and the converted query parameters.
[0043] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;
[0044] The memory stores computer-executable instructions;
[0045] The processor executes the computer-executable instructions stored in the memory to implement the data query method as described in the above-mentioned first aspect and various possible implementations of the first aspect.
[0046] In a fourth aspect, the present application provides a program product, including a computer program, which implements the data query method as described above when executed by a processor.
[0047] In a fifth aspect, the present application provides a computer-readable storage medium having computer execution instructions stored thereon, which, when executed by a processor, are used to implement the data query method as described in the first aspect and various possible implementations of the first aspect.
[0048] The data query method, device, electronic device and program product provided by the present application receive a query request sent by a client, determine the target module and query parameters to be queried, and then determine whether the target module is a preconfigured module containing custom pre-logic and whether the query parameter is an existing parameter of the target module; if the target module is a preconfigured module containing custom pre-logic and the query parameter is not an existing parameter in the target module, determine that the query request contains custom pre-logic; if the query request contains custom pre-logic, based on the correspondence between the query parameter and the existing parameter of the target module, convert the query parameter into a target parameter in the existing parameter of the target module, and the target parameter is the converted query parameter; based on the target module and the converted query parameter, generate a structured query language, and use the structured query language to query the database to be queried to obtain the query result; based on the query parameter, determine whether the query request contains custom post-logic. If the query request contains custom post-logic, convert the query result and send the converted query result to the client. By providing a unified interface and flexible custom logic, this method not only solves the problems of large development tasks, high communication costs, and long development cycles, but also improves the flexibility, efficiency, and compatibility of the system, enhances data processing capabilities, can adapt to different data storage environments, improves code reusability, and further improves development efficiency and the overall quality of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0050] Figure 1 A schematic diagram of a scenario of the data query method provided in this application;
[0051] Figure 2 Schematic diagram of the data query method provided in this application Figure 1 ;
[0052] Figure 3 Schematic diagram of the data query method provided in this application Figure 2 ;
[0053] Figure 4 A schematic diagram of the structure of the data query device provided by this application;
[0054] Figure 5A schematic diagram of the structure of the data query device provided in this application.
[0055] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0056] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0057] The terms "first", "second", "third", "fourth", etc. (if any) in the description and claims of the present invention and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in sequences other than those illustrated or described herein, for example.
[0058] In the embodiments of the present application, the words "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0059] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0060] First, the terms used in this embodiment are explained.
[0061] API: Application Programming Interface, an application programming interface, is a method for software components or applications to communicate with each other; in simple terms, API defines how software components interact, including how they pass data, control information, and perform functions.
[0062] HTTP: Hypertext Transfer Protocol is an application layer protocol for transmitting hypermedia documents (such as HTML documents); it is one of the main protocols for transmitting data on the Internet, mainly used for communication between clients (such as browsers) and servers.
[0063] With the development of social science and technology, more and more enterprises and units have increasing demands for digitalization, and the demand for software development is also gradually increasing.
[0064] In many software development processes, an inevitable high-frequency demand scenario is data acquisition, that is, querying data of each module. The traditional approach is to design, develop, test and launch each module; the implementation logic is to write a corresponding program for each module. The basic idea is that the client initiates a request based on the specified request response parameters, request path, field name and other APIs. Each module forwards the data to the corresponding storage medium software through the written program logic to obtain the data, and encapsulates and returns it to the client.
[0065] However, the query module has the following major shortcomings when processing data query requirements:
[0066] First, the workload of program development is large: query requirements account for a huge proportion in a software program, and such interfaces are required in almost all scenarios. In most cases, they account for 25%-60% of the functions in the entire system. The query interface of each query module needs to be designed, developed and tested, which results in a huge workload.
[0067] Second, the communication cost of program development is high: Since a large number of query requirements are designed separately, in the era of microservices, each microservice belongs to different staff, even across departments and organizations. The design of each interface requires communication and collaboration with personnel from each functional module, resulting in huge communication costs.
[0068] Third, the program development cycle is long: the development of a single module needs to go through complex processes such as design, development, testing, and online launch. In the software system, a large number of query module functions will increase the development cycle by multiples, resulting in a long development cycle.
[0069] Fourth, it is not conducive to software maintenance: there is no unified standard, and the request paths and parameters of various query modules are not unified. Every time a person is replaced, each module needs to be re-sorted and understood, which has poor readability and is not friendly to subsequent maintenance personnel, increasing software maintenance costs.
[0070] The data query method provided in this application is intended to solve the above technical problems in the prior art.
[0071] First, the implementation scenarios involved in this application are described.
[0072] Figure 1 A schematic diagram of a scenario of the data query method provided in this application. Figure 1 As shown, multiple clients 101 are respectively connected to the server 102 in communication, and the client can obtain the user's data query demand and send the data query demand to the server 102; the server 102 determines the data query service that the corresponding client can provide according to the data query demand received from different clients, and performs data query according to the data query service that the client can provide, obtains the corresponding query result, and returns the query result to the corresponding client in the multiple clients 101; wherein, any client in the multiple clients 101 can be, for example, a smart mobile terminal or a smart computer, and the server 102 can be, for example, a server provided with a data query system. This application does not impose any special restrictions on the number of clients.
[0073] The present application provides a data query method, which generates a general API interface framework available to different functional modules by setting a fixed query request path and the input format of the query request; when the functional module needs to provide additional query requirements, a custom processing logic is added to the general API interface framework; different functional modules correspond to different module parameters, and according to the module parameters in the query request, the functional module providing the query service at that time is determined, and then combined with the query requirements of the user at that time, the query logic corresponding to the functional module is executed, and automatically spliced into SQL statements, so as to query the corresponding database and return the query results; at the same time, before performing data query, the query requirements are securely filtered, and when the query results are returned, data desensitization is performed. This method not only solves the problems of large development tasks, high communication costs, and long development cycles by providing a unified interface and flexible custom logic, but also improves the flexibility, efficiency and compatibility of the system, enhances data processing capabilities, and can adapt to different data storage environments.
[0074] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0075] Figure 2 Schematic diagram of the data query method provided in the embodiment of the present application Figure 1 The execution subject of this embodiment may be, for example, a data query system provided with different functional modules. Figure 2 As shown, the data query method provided in this embodiment includes:
[0076] S201: receiving a query request sent by a client.
[0077] The query request includes the target module to be queried and query parameters.
[0078] It can be understood that the executor of this step is the data query system, in which multiple functional modules are arranged, and the multiple functional modules are constructed with the same design logic. Each functional module has a pre-set and uniquely corresponding identification information, through which the functional module providing query services to the user can be determined; therefore, according to the identification information input by the user at that time, the corresponding function module to be called can be determined.
[0079] The data query system receives the query request sent by the client, analyzes and processes the query request, obtains the corresponding identification information and specific query content, and thereby determines the target module and query parameters to be queried in the query request.
[0080] A query request usually includes: request path, request type, request body, and query parameters. Since different functional modules are constructed using a unified design logic, the request formats provided by different functional modules to the client are also unified. For example, the request path of different functional modules can be: http: / / {host}:{port} / {version} / xxxx / data / get, where http indicates the use of the HTTP protocol for network communication; host is a placeholder representing the server host name or IP address; port indicates the server port number, and version indicates the version number of the API; / xxxx / usually represents a specific resource or module and can be any identifier used to indicate the target resource or module of the request; data / get is used to indicate the operation of obtaining data; the request type can be: POST, indicating that the POST method in the HTTP protocol is being used to send a request; the request body can include multiple query types, specifically: "module, indicating the module or resource type to be queried", "match, indicating fuzzy query, corresponding data query can be performed based on user information", "term, indicating precise query, by entering id information, you can locate any piece of data information", "terms, indicating precise query, by entering multiple id information, you can locate any number of data information", "range, indicating interval query", "range, indicating sorting of multiple queried data information", among which module is a required field and the rest are non-required fields.
[0081] In addition, a fixed value of the request Query parameter is set according to the usage habits of different users, and the fixed value of the request Query parameter corresponds to the ID information of any data information in the database. The user can directly enter the fixed value of the request Query parameter in the request path to perform corresponding data query. At this time, the user does not need to enter the query data corresponding to the request body.
[0082] For example, receive a query request sent from a client, and the query request received this time includes: "Request path: http: / / www.cuclond.com / api / v1.0 / data / get", "Request type: POST", "Request body:'module: user','match: key-user_name, value-Zhang San', 'term: key-id, value-1', 'range: key-create_time, greater_than-20, less_than-30, greater_than_equals-20, less_than_equals-20, key_type-date','sort: sort_direction-asc, sort_field-id'. Analyze and process this query request, and the corresponding functional module can be obtained as "module: user", and the corresponding query parameters are the data information corresponding to match, term, range, and sort in the request body.
[0083] S202: Determine whether the query request contains custom pre-logic based on the target module and query parameters.
[0084] S203: If the query request contains custom pre-logic, convert the query parameters in the query request to obtain the converted query parameters.
[0085] Among them, the custom pre-logic is used to indicate the logic for preprocessing query parameters before processing the query request.
[0086] It can be understood that when constructing a functional module using a unified design logic, if the corresponding functional module needs to provide additional query services for users, custom processing logic can be set. If the execution timing of this custom processing logic is before querying the database of the corresponding functional module, then this custom processing logic can be determined as custom pre-logic; that is to say, the custom pre-logic can be customized according to specific business requirements and provide custom query parameters; since there is no directly matching field for the custom query parameters in the corresponding functional module, it is necessary to convert the custom query parameters into parameters that can be processed by the current functional module. At this time, the processing logic for converting the custom query parameters into parameters that can be processed by the current functional module is the custom pre-logic.
[0087] Multiple custom pre-logics are preset for different functional modules, and according to the identification information of different functional modules, the query service corresponding to the custom pre-logic provided by the functional module can be determined. Therefore, after receiving the query request sent by the client, the custom pre-logic that can be executed for the current time and the query parameters corresponding to the custom pre-logic can be determined based on the identification information of the corresponding functional module. This application does not impose special restrictions on the number of custom pre-logics.
[0088] Based on the target module and query parameters corresponding to the query request determined for the current time, it is determined whether the query request includes a custom pre-logic, that is, it is determined whether there are custom query parameters in the query parameters. If there are custom query parameters in the query parameters, then according to the custom pre-logic, the custom query parameters in the corresponding query request are converted to obtain the converted query parameters. At this time, the converted query parameters; if there are no custom query parameters in the query parameters, then the corresponding data query is performed according to the query service provided by the current target module.
[0089] For example, if the request body obtained for the current time includes: "‘module: user’, ‘match: key-user_name, value-Zhang San’, ‘term: key-adult, value-1’, and the target module for the current time is the functional module corresponding to user, specifically functional module A; if the query parameters that can be provided by this functional module include: age, where the custom request content is: "‘term: key-adult, value-1’", and the query parameters corresponding to this request content are: "‘is adult, yes’", that is, it is necessary to query the specific people who have reached adulthood in the database. At this time, the corresponding custom pre-logic pre-stored in functional module A is used to convert the custom query parameters, that is, convert "‘is adult, yes’" into query information related to "age", and the obtained converted parameter is "age is greater than or equal to 18".
[0090] Preferably, before determining whether the query request includes a custom pre-logic, it is necessary to perform data processing on the query request obtained for the current time, that is, pre-data processing, and the pre-data processing specifically includes: data verification, security verification, permission verification, and log recording.
[0091] By performing pre-data processing on the query request, it can be ensured that the query request has undergone basic verification and filtering before entering the custom pre-logic processing, ensuring the integrity and validity of the input data, avoiding query failures or system exceptions caused by data errors, and protecting sensitive data to ensure the compliance of data access, thereby improving the security, stability, and reliability of the data query system.
[0092] S204: Generate a structured query language based on the target module and the converted query parameters, and use the structured query language to query the database to be queried to obtain a query result.
[0093] Among them, structured query language refers to a database management language that is used to perform various database operations to meet different business needs.
[0094] It is understandable that different functional modules may use different databases, and different databases use different database management languages. Different functional modules can only generate structured query languages that are compatible with their corresponding databases.
[0095] Based on the target module, the converted query parameters, and the query parameters that can be directly processed by the target module, a structured query language corresponding to the target module is generated, and the structured query language is used to query the database to be queried to obtain the query result.
[0096] For example, if the database corresponding to function module A is MySQL, the converted query parameters obtained this time and the query parameters that can be directly processed by the target module are converted into SQL statements corresponding to the MySQL database, and the SQL statement is used to query the MySQL database to obtain the corresponding query results, and the query results are returned to the client.
[0097] The data query method provided in this embodiment determines the target module and query parameters to be queried by receiving the query request sent by the client; determines whether the query request contains custom pre-logic based on the target module and query parameters; if the query request contains custom pre-logic, the query parameters in the query request are converted to obtain the converted query parameters; based on the target module and the converted query parameters, a structured query language is generated, and the query result is obtained by querying from the database to be queried using the structured query language. By providing a unified interface and flexible custom logic, this method not only solves the problems of large development tasks, high communication costs, and long development cycles, but also improves the flexibility, efficiency, and compatibility of the system and enhances data processing capabilities.
[0098] Figure 3 Schematic diagram of the data query method provided in the embodiment of the present application Figure 2 .like Figure 3 As shown, in this embodiment Figure 2 Based on the embodiment, the data query method is described in detail. The data query method shown in this embodiment includes:
[0099] S301: receiving a query request sent by a client.
[0100] Step S301 is similar to the above-mentioned step S201 and will not be elaborated here.
[0101] S302: Determine whether the target module is a pre-configured module containing custom pre-logic, and whether the query parameter is an existing parameter of the target module.
[0102] S303: If the target module is a pre-configured module containing custom pre-logic and the query parameter is not an existing parameter in the target module, it is determined that the query request contains custom pre-logic.
[0103] It can be understood that for multiple functional modules in the data query system, different functional modules may have different query logics and parameters; when a certain functional module needs to provide additional query services, it can be achieved through pre-configuration of the processing logic, and the execution timing of the pre-configured processing logic corresponds to the query parameters of the additional query service.
[0104] According to the identification information of the target module in the query request, it can be determined whether the target module is a pre-configured module containing custom pre-logic, and whether the query parameter is an existing parameter of the target module; if the target module is a pre-configured module containing custom pre-logic and the query parameter is not an existing parameter in the target module, it is determined that the query request contains custom pre-logic, that is, specific logical operations need to be executed before the actual query.
[0105] For example, if the request body obtained this time includes: "'module: user', 'match: key-user_name, value-Zhang San', 'term: key-adult, value-1'", and the target module this time is the functional module corresponding to user, specifically functional module A, and the query parameters that can be provided in this functional module A include: age; in the pre-configuration information of the data query system, there is pre-configured custom pre-logic in the functional module corresponding to user, specifically: converting the screening information of "whether adult" into screening information related to "age"; at this time, the request content obtained this time is: "term: key-adult, value-1", and the query parameter corresponding to this request content is: "whether adult, yes", which does not match the query parameters that can be provided in functional module A and is not an existing parameter in functional module A. At this time, it can be determined that the query request obtained this time contains custom pre-logic.
[0106] S304: If the query request contains custom pre-logic, based on the correspondence between the query parameter and the existing parameter of the target module, convert the query parameter into the target parameter in the existing parameters of the target module, and the target parameter is the converted query parameter.
[0107] Among them, the existing parameters refer to the parameter types that can be directly queried in the database corresponding to the target module.
[0108] It can be understood that if the query request includes custom pre-logic, it indicates that the target module provides additional query services. When the user uses this query service, the query parameters in the query request sent by the client at that time include custom query parameters corresponding to this additional query service, and there is a corresponding relationship between the custom query parameters and the existing parameters of the target module. The process of converting the custom query parameters into a form that only includes the existing parameters of the target module is the implementation process of this custom pre-logic.
[0109] For example, if the request body obtained this time includes: "‘module: user’, ‘match: key-user_name, value-Zhang San’, ‘term: key-adult, value-1’, and the target module this time is the function module corresponding to user, specifically function module A. There is pre-configured custom pre-logic in the function module corresponding to this user, specifically: converting the screening information of "whether adult" into screening information related to "age"; the custom query parameter is: "term: key-adult, value-1", and the query parameter corresponding to the content of this request body is: "whether adult, yes", that is, it is necessary to query the specific people who are already adults in the database. At this time, the corresponding custom pre-logic stored in advance in function module A is used to convert this custom query parameter, that is, converting "whether adult, yes" into query information related to "age". The obtained converted target parameter is "age greater than or equal to 18", and this target parameter adds a screening condition on the basis of the existing parameter "age" in the MySQL database.
[0110] S305: Generate a structured query language based on the target module and the converted query parameters, and use the structured query language to query the query result from the database to be queried.
[0111] According to the target module determined this time, determine the type of the structured query language adopted by the database corresponding to this target module, and generate the structured query language corresponding to this target module based on the type of this structured query language, the converted query parameters, and the query parameters that can be directly processed by this target module, and use the generated structured query language to query the query result from the database to be queried.
[0112] Specifically, before generating a structured query language based on the target module and the converted query parameters, it is determined whether the database to be queried is an external database based on the converted query parameters; if the database to be queried is an external database, a structured query language for the external database is generated based on the target module and the converted query parameters; if the database to be queried is not an external database, a structured query language for the database to be queried is generated based on the target module and the converted query parameters.
[0113] It is understandable that different databases can recognize different structured query languages. When using different databases to query data, only the query language fixed by the corresponding database can be used to query data.
[0114] Based on the converted query parameters, determine whether the database to be queried is an external database; if the database to be queried is an external database, it indicates that the query information corresponding to the converted query parameters is provided by the external database. At this time, based on the target module and the converted query parameters, a structured query language for the external database is generated, and data is queried on the external database according to the structured query language to obtain corresponding external query results; if the database to be queried is not an external database, it indicates that the query information corresponding to the converted query parameters is provided by the database of the target module. At this time, based on the target module and the converted query parameters, a structured query language for the database to be queried is generated.
[0115] It can be understood that in the process of data query, the query request includes multiple query parameters, and the multiple query parameters may need to execute custom pre-logic for conversion, there may also be query parameters that need to call an external database, and there may also be query parameters corresponding to the target module determined at the time; data query is performed according to the processing logic corresponding to different query parameters, and multiple query results obtained by different query paths are integrated to obtain query results that are consistent with the pronunciation of the query request at the time.
[0116] S306: Determine whether the query request contains custom post-logic based on the query parameters.
[0117] S307: If the query request contains custom post-logic, the query result is converted and sent to the client.
[0118] The custom post-logic is used to indicate the logic for reprocessing the query results after processing the query request.
[0119] It can be understood that since the custom processing logic of different functional modules is pre-configured, and the processing logic that can be implemented by each functional module, that is, the query service that can be provided is fixed, there is unique identification information to identify each functional module; therefore, when determining the target module corresponding to the query request obtained this time, it can be determined whether there is a corresponding custom processing logic in the functional module, and the pre-configured custom processing logic includes: custom pre-logic and custom post-logic, depending on the execution time.
[0120] Based on the query parameters in the current query request, determine whether the query request contains query parameters that require the execution of custom post-logic; if the query request contains query parameters that require the execution of custom post-logic, it means that after obtaining the query result, the query result needs to be converted, and the query result after the conversion is the final query result corresponding to the current query request, and the final query result is sent to the client.
[0121] Specifically, whether the query request contains custom post-logic is determined based on the query parameters, including:
[0122] If the query parameter is not an existing parameter in the target module, or the query parameter is a preset parameter containing a custom post-logic, it is determined that the query request contains the custom post-logic.
[0123] Based on the identification information of the target module in the query request, it can be determined whether the target module is a pre-configured module containing custom post-logic, and whether the query parameter is an existing parameter of the target module; if the target module is a pre-configured module containing custom post-logic, or the query parameter is not an existing parameter in the target module, but there is a corresponding relationship between the query parameter and the existing parameter in the target module, then it can be determined that the query request contains custom post-logic, that is, a specific logical operation that needs to be performed after obtaining the current database query result.
[0124] In addition, different custom post-logics also differ in execution. According to the services actually provided by the corresponding functional modules, the custom post-logic can be processing logic that requires corresponding parameter conversion before querying the database, or it can be processing logic that only needs to process the query results.
[0125] Specifically, when converting the query results, if the query parameters are not existing parameters in the target module, the query results are converted based on the correspondence between the query parameters and the target parameters; if the query parameters are preset parameters containing custom post-logic, the query results are converted based on the preset custom post-logic corresponding to the query parameters.
[0126] When the custom post-logic converts the current custom query parameters into existing parameters in the target module, and then queries the corresponding data information, after obtaining the query results, based on the custom post-logic, converts the data information corresponding to the existing parameters into the data information corresponding to the custom query parameters again; therefore, before querying the database of the target module, based on the identification information corresponding to the target module, it can be determined whether the target module has custom post-logic, and the query parameters in the query request are identified to determine whether they are custom query parameters corresponding to the custom post-logic; if there are custom query parameters corresponding to the custom post-logic, it means that before actually performing the data query, the custom query parameters corresponding to the custom post-logic need to be converted into existing parameters of the target module.
[0127] It can be understood that whether it is necessary to perform parameter conversion before querying the database is determined according to the custom post-logic actually configured in the target module; if the custom query parameter corresponding to the custom post-logic is an existing parameter in the database of the target module, then when the query request contains the custom query parameter, there is no need to perform the corresponding parameter conversion before querying the database; if the custom query parameter corresponding to the custom post-logic is not an existing parameter in the database of the target module, but there is a corresponding relationship with the existing parameter in the database of the target module, then when the query request contains the custom query parameter, it is necessary to perform the corresponding parameter conversion before querying the database.
[0128] Preferably, after obtaining the final query result, it is necessary to perform data processing on the query result determined at that time, that is, post-data processing, and the post-data processing specifically includes: log storage and query data desensitization.
[0129] For example, if the request body obtained this time includes: "'module: user', 'match: key-user_name, value-Zhang San', 'term: key-Fahrenheit, value-86'", and the target module this time is the function module A corresponding to user, and the query parameters that can be provided in this function module A include: Celsius (°C); in the pre-configured information of the data query system, there is pre-configured custom post-logic in the function module corresponding to user, specifically: before querying the database, convert "Fahrenheit" to "Celsius", and after obtaining the query result, convert "Celsius" to "Fahrenheit"; at this time, the request content obtained this time is: "term: key-Fahrenheit, value-86", and the query parameter corresponding to this request content is: "Fahrenheit, 86°F". This query parameter "Fahrenheit" does not match the query parameters that can be provided in the function module A, but there is a conversion relationship between the query parameter "Fahrenheit" and the query parameter "Celsius" that can be provided in the function module A. Therefore, according to the custom post-logic corresponding to the query parameter "Fahrenheit", convert the Celsius data in the query result to Fahrenheit data, and send the converted query result to the client; if the query parameter this time is: data type A, and this "data type A" does not belong to the existing parameters in the function module A, but there is a corresponding relationship with "data type B" in the function module A, and only after obtaining the data information corresponding to "data type B" can the data information corresponding to "data type A" be determined. At this time, corresponding query data conversion also needs to be performed before querying the database.
[0130] The data query method provided by the present implementation receives a query request sent by a client, determines the target module and query parameters to be queried, and then determines whether the target module is a pre-configured module containing custom pre-logic and whether the query parameter is an existing parameter of the target module; if the target module is a pre-configured module containing custom pre-logic, and the query parameter is not an existing parameter in the target module, it is determined that the query request contains custom pre-logic; if the query request contains custom pre-logic, based on the correspondence between the query parameter and the existing parameter of the target module, the query parameter is converted into a target parameter in the existing parameter of the target module, and the target parameter is the converted query parameter; based on the target module and the converted query parameter, a structured query language is generated, and the structured query language is used to query the database to be queried to obtain the query result; based on the query parameter, it is determined whether the query request contains custom post-logic. If the query request contains custom post-logic, the query result is converted and sent to the client. By providing a unified interface and flexible custom logic, this method not only solves the problems of large development tasks, high communication costs, and long development cycles, but also improves the flexibility, efficiency, and compatibility of the system, enhances data processing capabilities, can adapt to different data storage environments, improves code reusability, and further improves development efficiency and the overall quality of the system.
[0131] Figure 4 This is a schematic diagram of the structure of the data query device provided by this application. Figure 4 As shown, the present application provides a data query device, the data query device 400 includes:
[0132] The receiving module 401 is used to receive a query request sent by a client, wherein the query request includes a target module to be queried and query parameters.
[0133] The processing module 402 is used to determine whether the query request contains a custom pre-logic based on the target module and the query parameter.
[0134] If the query request contains a custom pre-logic, the processing module 402 is further configured to convert the query parameters in the query request to obtain converted query parameters.
[0135] The processing module 402 is further configured to generate a structured query language based on the target module and the converted query parameters, and use the structured query language to query the database to be queried to obtain a query result.
[0136] Optionally, the processing module 402 is further used to determine whether the target module is a preconfigured module containing a custom pre-logic, and whether the query parameter is an existing parameter of the target module.
[0137] If the target module is a preconfigured module including a custom pre-logic, and the query parameter is not an existing parameter in the target module, the processing module 402 is further configured to determine whether the query request includes a custom pre-logic.
[0138] Optionally, if the query request contains custom pre-logic, the processing module 402 is also used to convert the query parameter into a target parameter in the existing parameters of the target module based on the correspondence between the query parameter and the existing parameters of the target module, and the target parameter is the converted query parameter.
[0139] Optionally, the processing module 402 is further configured to determine whether the query request includes custom post-logic based on the query parameter.
[0140] If the query request contains a custom post-logic, the processing module 402 is further configured to perform conversion processing on the query result and send the converted query result to the client.
[0141] Optionally, if the query parameter is not an existing parameter in the target module, or the query parameter is a preset parameter containing a custom post-logic, the processing module 402 is further configured to determine whether the query request contains a custom post-logic.
[0142] Optionally, if the query parameter is not an existing parameter in the target module, the processing module 402 is further configured to perform conversion processing on the query result based on a correspondence between the query parameter and the target parameter.
[0143] If the query parameter is a preset parameter including a custom post-logic, the processing module 402 is further configured to perform conversion processing on the query result based on the preset custom post-logic corresponding to the query parameter.
[0144] Optionally, the processing module 402 is further configured to determine whether the database to be queried is an external database based on the converted query parameters.
[0145] If the database to be queried is an external database, the processing module 402 is further configured to generate a structured query language for the external database based on the target module and the converted query parameters.
[0146] If the database to be queried is not an external database, the processing module 402 is further configured to generate a structured query language for the database to be queried based on the target module and the converted query parameters.
[0147] Figure 5 This is a schematic diagram of the structure of the data query device provided by this application. Figure 5 As shown, the present application provides a data query device, and the data query device 500 includes: a receiver 501, a transmitter 502, a processor 503 and a memory 504.
[0148] Receiver 501, used for receiving instructions and data;
[0149] A transmitter 502, used for sending instructions and data;
[0150] Memory 504, used to store computer-executable instructions;
[0151] The processor 503 is used to execute the computer-executable instructions stored in the memory 504 to implement the various steps performed by the data query method in the above embodiment. For details, please refer to the relevant description in the above data query method embodiment.
[0152] Optionally, the memory 504 may be independent or integrated with the processor 503 .
[0153] When the memory 504 is independently provided, the electronic device further includes a bus for connecting the memory 504 and the processor 503 .
[0154] The present application also provides a program product, including a computer program, which implements the data query method as described above when executed by a processor.
[0155] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, a data query method as executed by the above-mentioned data query device is implemented.
[0156] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0157] It should be further noted that, although the various steps in the flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0158] It should be understood that the above-mentioned device embodiments are only illustrative, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.
[0159] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application may be integrated into one unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of a software program module.
[0160] If the integrated unit / module is implemented in the form of hardware, the hardware may be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Unless otherwise specified, the processor may be any appropriate hardware processor, such as a CPU, a GPU, an FPGA, a DSP, an ASIC, etc. Unless otherwise specified, the storage unit may be any appropriate magnetic storage medium or magneto-optical storage medium, such as a resistive random access memory (RRAM), a dynamic random access memory (DRAM), a static random access memory (SRAM), an enhanced dynamic random access memory (EDRAM), a high-bandwidth memory (HBM), a hybrid memory cube (HMC), etc.
[0161] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a memory, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0162] In the above embodiments, the description of each embodiment has its own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0163] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0164] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A data query method, characterized in that: The method comprises: Receiving a query request sent by a client, wherein the query request includes a target module to be queried and query parameters; Determining whether the query request includes a custom pre-logic based on the target module and the query parameter; If the query request includes a custom pre-logic, the query parameters in the query request are converted to obtain converted query parameters; Based on the target module and the converted query parameters, a structured query language is generated, and the structured query language is used to query the database to be queried to obtain a query result.
2. The method according to claim 1, characterized in that The determining whether the query request includes a custom pre-logic based on the target module and the query parameter includes: Determine whether the target module is a preconfigured module containing a custom front-end logic, and whether the query parameter is an existing parameter of the target module; If the target module is a preconfigured module including a custom pre-logic, and the query parameter is not an existing parameter in the target module, it is determined that the query request includes the custom pre-logic.
3. The method according to claim 2, characterized in that If the query request includes the custom pre-logic, the query parameters in the query request are converted to obtain the converted query parameters, including: If the query request includes a custom pre-logic, based on the correspondence between the query parameter and the existing parameter of the target module, the query parameter is converted into a target parameter in the existing parameter of the target module, and the target parameter is the converted query parameter.
4. The method according to claim 3, characterized in that Also includes: Determining whether the query request includes custom post-logic based on the query parameters; If the query request contains custom post-logic, the query result is converted and sent to the client.
5. The method according to claim 4, characterized in that The determining, based on the query parameter, whether the query request includes a custom post-logic includes: If the query parameter is not an existing parameter in the target module, or the query parameter is a preset parameter containing a custom post-logic, it is determined that the query request contains a custom post-logic.
6. The method according to claim 5, characterized in that The converting process of the query result includes: If the query parameter is not an existing parameter in the target module, converting the query result based on the corresponding relationship between the query parameter and the target parameter; If the query parameter is a preset parameter including a custom post-logic, the query result is converted based on the preset custom post-logic corresponding to the query parameter.
7. The method according to any one of claims 1 to 6, characterized in that The generating structured query language based on the target module and the converted query parameters includes: Based on the converted query parameters, determining whether the database to be queried is an external database; If the database to be queried is an external database, generating a structured query language for the external database based on the target module and the converted query parameters; If the database to be queried is not an external database, a structured query language for the database to be queried is generated based on the target module and the converted query parameters.
8. A data query device, characterized in that: include: A receiving module, used to receive a query request sent by a client, wherein the query request includes a target module to be queried and query parameters; A processing module, configured to determine whether the query request contains a custom pre-logic based on the target module and the query parameter; If the query request contains a custom pre-logic, the processing module is further used to convert the query parameters in the query request to obtain converted query parameters; The processing module is further used to generate a structured query language based on the target module and the converted query parameters, and use the structured query language to query the database to be queried to obtain a query result.
9. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 7.
10. A program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 7 when being executed by a processor.
Citation Information
Patent Citations
Data query method and apparatus
CN108614842A
Database query method and device, equipment and storage medium
CN112182014A
Data query method and system, electronic equipment and storage medium
CN114547080A
Optimization method and system based on data service, computer equipment and medium
CN114860770A
Data query method and device, electronic equipment and storage medium
CN116089462A