Method and device for querying database, electronic equipment and computer readable medium

By identifying and converting function keywords and expressions in custom query statements, and calling the corresponding database connection engine to send query statements, the problem of framework redundancy and inability to adapt to multiple databases in the existing technology is solved, and multi-database support and framework lightweighting is realized.

CN119597735APending Publication Date: 2025-03-11CHINA CONSTRUCTION BANK +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411733481.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

In the prior art, there are problems such as framework redundancy and the inability to adapt multiple databases at the same time during database migration and transformation.

Method used

By receiving custom query statements transmitted from the service layer, function keywords and their corresponding expressions are identified, and converted into database query statements based on pre-configured mapping relationships. Then, the identity of the database connection engine is identified from the custom query statement, the corresponding database connection engine is called, and the query statement is sent to each database.

Benefits of technology

It implements multi-database support, can operate multiple databases at the same time, and does not require reference to third-party component packages, which helps to achieve lightweighting of the framework.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597735A_ABST
    Figure CN119597735A_ABST
Patent Text Reader

Abstract

The invention discloses a database query method and device, electronic equipment and a computer readable medium, and relates to the technical field of databases. The method comprises the following steps: receiving a user-defined query statement transmitted by a service layer; function keywords and expressions corresponding to the function keywords are recognized from the user-defined query statements; according to a pre-configured mapping relation, converting an expression corresponding to the function keyword into at least one database query statement segment, and splicing the at least one database query statement into a database query statement; and identifying identifiers of one or more database connection engines from the custom query statement, and calling the one or more database connection engines, so that each database connection engine sends the database query statement to a database corresponding to each database connection engine. According to the implementation mode, the technical problems of framework redundancy and incapability of adapting to multiple databases at the same time can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a method, device, electronic device and computer-readable medium for querying a database. Background Art

[0002] In the process of migration and transformation from one database to another, it is necessary to consider the compatibility and versatility of the system, so that the original system can not only adapt from one database to another, but also connect to multiple databases at the same time. The system can run on multiple database platforms at the same time and ensure the normal, safe and stable operation of the system.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0004] 1) The system framework is relatively heavy, requiring reference to third-party component packages, and many contents are redundant;

[0005] 2) Existing technologies all migrate and transform from one database to another, but they cannot guarantee that the two databases can run in parallel, nor can they adapt to multiple databases at the same time. Summary of the invention

[0006] In view of this, embodiments of the present invention provide a method, device, electronic device and computer-readable medium for querying a database to solve the technical problems of framework redundancy and inability to adapt to multiple databases at the same time.

[0007] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for querying a database is provided, comprising:

[0008] Receive custom query statements transmitted from the business layer;

[0009] Identify function keywords and their corresponding expressions from the custom query statement;

[0010] According to a pre-configured mapping relationship, the expression corresponding to the function keyword is converted into at least one database query statement segment, and the at least one database query statement is spliced ​​into a database query statement; wherein the mapping relationship defines the corresponding relationship between each function keyword and each expression;

[0011] Identify the identifiers of one or more database connection engines from the custom query statement, and call the one or more database connection engines so that each database connection engine sends the database query statement to a database corresponding to each database connection engine.

[0012] Optionally, after calling the database connection engine, the method further includes:

[0013] Receiving an execution result returned by the database connection engine, wherein the execution result is obtained after the database executes the database query statement and is returned by the database;

[0014] The execution result is returned to the service layer.

[0015] Optionally, before receiving the custom query statement transmitted by the business layer, the method further includes:

[0016] Configure each database connection engine and its corresponding database connection string in the configuration file;

[0017] Initialize each database connection engine.

[0018] Optionally, identifying identifiers of one or more database connection engines from the custom query statement, and calling the one or more database connection engines so that each database connection engine sends the database query statement to a database corresponding to each database connection engine, respectively, includes:

[0019] Identify the identifiers of one or more database connection engines from the custom query statement, call the one or more database connection engines, so that each database connection engine searches for the database connection string corresponding to each database connection engine from the configuration file, thereby performing data connection with each database according to each database connection string, and sending the database query statement to the database corresponding to each database connection engine.

[0020] Optionally, according to a preconfigured mapping relationship, converting the expression corresponding to the function keyword into at least one database query statement segment includes:

[0021] According to the pre-configured mapping relationship between the database table entity and the table name of the database table and the fields in the database table, the function keyword and its corresponding expression are converted into at least one database query statement segment.

[0022] Optionally, the mapping relationship is declared by entity annotation, and the declaration of the database table entity defines the table name of the database table corresponding to the entity class and the fields in the database table corresponding to the attributes in the entity class.

[0023] In addition, according to another aspect of an embodiment of the present invention, there is provided a device for querying a database, comprising:

[0024] The receiving module is used to receive the custom query statements transmitted from the business layer;

[0025] An identification module, used to identify function keywords and their corresponding expressions from the custom query statement;

[0026] A conversion module, used to convert the expression corresponding to the function keyword into at least one database query statement segment according to a pre-configured mapping relationship, and splice the at least one database query statement into one database query statement; wherein the mapping relationship defines the corresponding relationship between each function keyword and each expression;

[0027] The query module is used to identify the identifiers of one or more database connection engines from the custom query statement, and call the one or more database connection engines to enable each database connection engine to send the database query statement to the database corresponding to each database connection engine.

[0028] Optionally, the receiving module is further used for:

[0029] Receiving an execution result returned by the database connection engine, wherein the execution result is obtained after the database executes the database query statement and is returned by the database;

[0030] The execution result is returned to the service layer.

[0031] Optionally, the device further comprises a configuration module, configured to:

[0032] Configure each database connection engine and its corresponding database connection string in the configuration file;

[0033] Initialize each database connection engine.

[0034] Optionally, the query module is further used to:

[0035] Identify the identifiers of one or more database connection engines from the custom query statement, call the one or more database connection engines, so that each database connection engine searches for the database connection string corresponding to each database connection engine from the configuration file, thereby performing data connection with each database according to each database connection string, and sending the database query statement to the database corresponding to each database connection engine.

[0036] Optionally, the conversion module is further used for:

[0037] According to the pre-configured mapping relationship between the database table entity and the table name of the database table and the fields in the database table, the function keyword and its corresponding expression are converted into at least one database query statement segment.

[0038] Optionally, the mapping relationship is declared by entity annotation, and the declaration of the database table entity defines the table name of the database table corresponding to the entity class and the fields in the database table corresponding to the attributes in the entity class.

[0039] According to another aspect of an embodiment of the present invention, there is further provided an electronic device, including:

[0040] one or more processors;

[0041] a storage device for storing one or more programs,

[0042] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any one of the above embodiments.

[0043] According to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described in any one of the above embodiments is implemented.

[0044] According to another aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the method described in any one of the above embodiments is implemented.

[0045] An embodiment of the above invention has the following advantages or beneficial effects: because the expression corresponding to the function keyword identified from the custom query statement is converted into a database query statement according to a pre-configured mapping relationship, and then the identifier of one or more database connection engines is identified from the custom query statement, and one or more database connection engines are called to enable each database connection engine to send the database query statement to the database corresponding to each database connection engine, the technical problems of framework redundancy and inability to adapt to multiple databases at the same time in the prior art are overcome. The embodiment of the present invention can realize multi-database support and can realize simultaneous operation of multiple databases, and does not need to reference third-party component packages, which helps to realize lightweight framework.

[0046] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:

[0048] Figure 1 is a flowchart of a method for querying a database according to an embodiment of the present invention;

[0049] Figure 2 is a flowchart of a method for querying a database according to a reference embodiment of the present invention;

[0050] Figure 3 is a flowchart of a method for querying a database according to another reference embodiment of the present invention;

[0051] Figure 4 is a flowchart of a method for querying a database according to yet another reference embodiment of the present invention;

[0052] Figure 5 is a schematic diagram of a device for querying a database according to an embodiment of the present invention;

[0053] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0054] Figure 7 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0055] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0056] It should be noted that in the technical solution of the present invention, the collection, analysis, use, transmission, storage and other aspects of user personal information involved are in compliance with the provisions of relevant laws and regulations, are used for legal and reasonable purposes, are not shared, leaked or sold outside of these legal uses, and are subject to supervision and management by regulatory authorities. Necessary measures should be taken for user personal information to prevent illegal access to such personal information data, ensure that persons who have access to personal information data comply with the provisions of relevant laws and regulations, and ensure the security of user personal information. Once these user personal information data are no longer needed, the risks should be minimized by limiting or even prohibiting data collection and / or deleting data.

[0057] When applicable, including in certain relevant applications, protect user privacy by de-identifying data, such as by removing specific identifiers (e.g., date of birth, name, age, gender, etc.) when applicable, controlling the amount or specificity of the data stored, controlling how the data is stored, and / or other methods of de-identification.

[0058] Figure 1 is a flow chart of a method for querying a database according to an embodiment of the present invention. As an embodiment of the present invention, Figure 1 As shown, the method for querying the database may include:

[0059] Step 101: Receive a custom query statement transmitted from the business layer.

[0060] The query system receives a custom query statement (FQL) transmitted from the business layer. The custom query statement may be sent from the client to the business layer, or may be transmitted from other systems or other layers to the business layer, which is not limited in this embodiment of the present invention.

[0061] Step 102: Identify function keywords and their corresponding expressions from the custom query statement.

[0062] After receiving the custom query statement transmitted from the business layer, the query system identifies the function keyword and the expression containing the function keyword (i.e., the expression corresponding to the function keyword) from the custom query statement. It should be noted that one or more function keywords can be identified from the custom query statement, each function keyword corresponds to an expression, but the same expression can contain one or more function keywords.

[0063] Step 103, according to a pre-configured mapping relationship, convert the expression corresponding to the function keyword into at least one database query statement segment, and splice the at least one database query statement into a database query statement; wherein the mapping relationship defines the correspondence between each function keyword and each expression.

[0064] After identifying the function keyword and its corresponding expression from the custom query statement, the query system converts the expression corresponding to the function keyword into a database query statement (such as a SQL statement) according to a pre-configured mapping relationship. The mapping relationship pre-defines the correspondence between each function keyword and each expression. Therefore, the expression corresponding to the function keyword can be converted into at least one database query statement segment according to the pre-configured correspondence between each function keyword and each expression.

[0065] In an embodiment of the present invention, if there are multiple expressions corresponding to the function keyword, these expressions are converted into one database query statement; if there is only one expression corresponding to the function keyword, the expression is converted into one database query statement.

[0066] Step 104: Identify the identifiers of one or more database connection engines from the custom query statement, and call the one or more database connection engines so that each database connection engine sends the database query statement to a database corresponding to each database connection engine.

[0067] After the database query statement is converted, the query system continues to identify the identifier of the database connection engine (dbEntity) from the custom query statement, and calls the database connection engine according to the identified database connection engine identifier, so that the database connection engine sends the database query statement converted in step 103 to the database corresponding to the database connection engine (such as a Mysql database or an Oracle database).

[0068] dbEntity connects to different databases through the database connection engine according to different custom implementations.

[0069] For example, the declaration of the database connection engine is:

[0070] @DBNAME("ORACLE")

[0071] dbEntity

[0072] The database connection engine will search the configuration file for a database connection string named Oracle, which corresponds to an Oracle database, and perform a database connection.

[0073] For another example, the declaration of the database connection engine is:

[0074] @DBNAME("MySQL")

[0075] dbEntity

[0076] The database connection engine will search the configuration file for a database connection string named Mysql, which corresponds to the Mysql database, and connect to the database.

[0077] The embodiment of the present invention can distinguish which database is connected by declaring the database connection engine, which is simple and easy to use and helps to achieve lightweight framework.

[0078] According to the various embodiments described above, it can be seen that the embodiments of the present invention solve the technical problems of framework redundancy and inability to adapt to multiple databases at the same time in the prior art by first converting the expression corresponding to the function keyword identified from the custom query statement into a database query statement according to the pre-configured mapping relationship, and then identifying the identifier of one or more database connection engines from the custom query statement, calling one or more database connection engines, so that each database connection engine sends the database query statement to the database corresponding to each database connection engine. The embodiments of the present invention can realize multi-database support and can realize simultaneous operation of multiple databases, and do not need to reference third-party component packages, which helps to realize lightweight framework.

[0079] Figure 2 1 is a flowchart of a method for querying a database according to a reference embodiment of the present invention. As another embodiment of the present invention, Figure 2 As shown, the method for querying the database may include:

[0080] Step 201, configure each database connection engine and its corresponding database connection string in a configuration file.

[0081] First, configure each database connection engine and its corresponding database connection string in the configuration file. It should be noted that each database connection engine corresponds to a database connection string, and the database connection engine connects to the corresponding database through the database connection string.

[0082] Step 202: Initialize each database connection engine.

[0083] After each database connection engine is configured in the configuration file, each database connection engine is initialized so that each database connection engine can connect to the corresponding database through the database connection string.

[0084] Step 203: Receive the custom query statement transmitted by the business layer.

[0085] Step 204: Identify function keywords and their corresponding expressions from the custom query statement.

[0086] Step 205, according to the pre-configured mapping relationship, convert the expression corresponding to the function keyword into at least one database query statement segment, and splice the at least one database query statement into a database query statement; wherein the mapping relationship defines the correspondence between each function keyword and each expression.

[0087] After identifying the function keyword and its corresponding expression from the custom query statement, the query system converts the expression corresponding to the function keyword into a database query statement according to the pre-configured mapping relationship. In an embodiment of the present invention, if there are multiple expressions corresponding to the function keyword, these expressions are converted into one database query statement, and if there is only one expression corresponding to the function keyword, the expression is converted into one database query statement.

[0088] Step 206, identifying the identifiers of one or more database connection engines from the custom query statement, calling the one or more database connection engines, so that each database connection engine respectively searches the configuration file for the database connection string corresponding to each database connection engine, thereby performing data connection with each database according to each database connection string, and sending the database query statement to the database corresponding to each database connection engine.

[0089] The custom query statement may include the identifiers of one or more database connection engines. After the query system identifies the identifiers of one or more database connection engines from the custom query statement, it calls the corresponding one or more database connection engines, so that each database connection engine searches for its corresponding database connection string from the configuration file respectively. Then each database connection engine connects to its corresponding database according to its corresponding database connection string, and sends the database query statement converted in step 205 to the database corresponding to the database connection engine.

[0090] It should be noted that each database connection engine is configured with a database connection string, and each database connection string corresponds to a database. Therefore, each database connection engine can establish a data connection with its corresponding database through the database connection string and send database query statements to the database, thereby realizing simultaneous operation of multiple databases.

[0091] Step 207: receiving the execution result returned by the database connection engine, wherein the execution result is obtained after the database executes the database query statement and is returned by the database.

[0092] Step 208: Return the execution result to the service layer.

[0093] After receiving the database query statement sent by the database connection engine, the database executes the database query statement to obtain the execution result, and returns the execution result to the corresponding database connection engine. The database connection engine then returns the execution result to the query system, and finally the query system returns the execution result to the service layer.

[0094] In addition, the specific implementation content of the method for querying a database in a reference embodiment of the present invention has been described in detail in the method for querying a database described above, so the repeated content will not be described here.

[0095] Figure 3 , which is a flowchart of a method for querying a database according to another reference embodiment of the present invention. Figure 3 As shown, the method for querying the database may include:

[0096] Step 301: Receive a custom query statement transmitted from the business layer.

[0097] Step 302: Identify function keywords and their corresponding expressions from the custom query statement.

[0098] For example, the query system receives the custom query statement transmitted by the service layer as follows:

[0099] var aList = sendService.dbEntity.Select ().Where(a -> a.id = id).OrderBy(A.id,OrderType.Desc), where the value of id is "123".

[0100] Then, keyword recognition is performed on the above custom query statement to obtain function keywords and their corresponding expressions, such as the following three function keywords and their corresponding expressions:

[0101] Select ()

[0102] Where(a->a.id=id) id=123

[0103] OrderBy(A.id,OrderType.Desc)

[0104] Step 303: convert the expression corresponding to the function keyword into at least one database query statement segment according to the pre-configured mapping relationship.

[0105] In an embodiment of the present invention, the mapping relationship is declared by entity annotation, and the declaration of the database table entity defines the table name of the database table corresponding to the entity class and the fields in the database table corresponding to the attributes in the entity class. Therefore, the expression corresponding to the function keyword can be converted into at least one database query statement segment according to the pre-declared database table entity.

[0106] Optionally, step 303 may include: according to the pre-configured mapping relationship between the database table entity and the table name of the database table and the fields in the database table, converting the function keyword and its corresponding expression into at least one database query statement segment. The three expressions identified in step 302 are converted to obtain the following three database query statement segments (SQL statement segments):

[0107] select * from TABLE_A a

[0108] where a.id = '123'

[0109] order by id desc

[0110] Among them, A represents the database table entity, and the mapping process from the database table entity (A) to the table name (TABLE_A) in the SQL statement is declared by entity annotation.

[0111] For example, the declaration of A is as follows:

[0112] @Table("TABLE_A")

[0113] Public class A

[0114] {

[0115] @Field("id",PK=True)

[0116] public String id;

[0117] @Field("name")

[0118] public String name;

[0119] }

[0120] The declaration of the database table entity defines the table name of the database table corresponding to the entity class and the fields in the database table corresponding to the attributes in the entity class. For example, the field in the database table corresponding to the attribute id in the entity is id, and the field in the database table corresponding to the attribute name in the entity is name.

[0121] Step 304: concatenate the at least one database query statement into one database query statement.

[0122] Concatenate the above three SQL statements into one SQL statement, namely:

[0123] select * from TABLE_A a where a.id = '123' order by id desc

[0124] Step 305: Identify the identifiers of one or more database connection engines from the custom query statement, and call the one or more database connection engines to enable each database connection engine to send the database query statement to the database corresponding to each database connection engine.

[0125] After the database query statement is converted, the query system continues to identify the identifier of the database connection engine from the custom query statement, and calls the database connection engine according to the identified identifier of the database connection engine, so that the database connection engine sends the database query statement converted in step 103 to the database corresponding to the database connection engine.

[0126] In addition, the specific implementation content of the method for querying a database in another reference embodiment of the present invention has been described in detail in the method for querying a database described above, so the repeated content will not be described here.

[0127] Figure 4 1 is a flowchart of a method for querying a database according to another reference embodiment of the present invention. Figure 4 As shown, the method for querying the database may include:

[0128] Step 401 , each database table entity is declared by annotation, wherein the declaration of the database table entity defines the table name of the database table corresponding to the entity class and the fields in the database table corresponding to the attributes in the entity class.

[0129] Step 402: configure each database connection engine and its corresponding database connection string in the configuration file, and initialize each database connection engine.

[0130] Step 403: Receive the custom query statement transmitted by the business layer.

[0131] Step 404: Identify function keywords and their corresponding expressions from the custom query statement.

[0132] Step 405: According to the declared database table entity, convert the function keyword and its corresponding expression into at least one database query statement segment.

[0133] Step 406: concatenate the at least one database query statement into one database query statement.

[0134] Step 407, identifying the identifiers of one or more database connection engines from the custom query statement, calling the one or more database connection engines, so that each database connection engine respectively searches the configuration file for the database connection string corresponding to each database connection engine, thereby performing data connection with each database according to each database connection string, and sending the database query statement to the database corresponding to each database connection engine.

[0135] Step 408: Receive the execution result returned by the database connection engine, where the execution result is obtained after the database executes the database query statement and is returned by the database.

[0136] Step 409: Return the execution result to the service layer.

[0137] In addition, the specific implementation content of the method for querying a database in another reference embodiment of the present invention has been described in detail in the method for querying a database described above, so the repeated content will not be described here.

[0138] Figure 5 Schematic diagram of a device for querying a database according to an embodiment of the present invention. Figure 5 As shown, the device 500 for querying a database includes a receiving module 501, an identification module 502, a conversion module 503 and a query module 504; wherein the receiving module 501 is used to receive a custom query statement transmitted from the business layer; the identification module 502 is used to identify a function keyword and its corresponding expression from the custom query statement; the conversion module 503 is used to convert the expression corresponding to the function keyword into at least one database query statement segment according to a pre-configured mapping relationship, and splice the at least one database query statement into a database query statement; wherein the mapping relationship defines the corresponding relationship between each function keyword and each expression; the query module 504 is used to identify the identifier of one or more database connection engines from the custom query statement, and call the one or more database connection engines so that each database connection engine sends the database query statement to the database corresponding to each database connection engine respectively.

[0139] Optionally, the receiving module 501 is further used for:

[0140] Receiving an execution result returned by the database connection engine, wherein the execution result is obtained after the database executes the database query statement and is returned by the database;

[0141] The execution result is returned to the service layer.

[0142] Optionally, the device further comprises a configuration module, configured to:

[0143] Configure each database connection engine and its corresponding database connection string in the configuration file;

[0144] Initialize each database connection engine.

[0145] Optionally, the query module 504 is further used to:

[0146] Identify the identifiers of one or more database connection engines from the custom query statement, call the one or more database connection engines, so that each database connection engine searches for the database connection string corresponding to each database connection engine from the configuration file, thereby performing data connection with each database according to each database connection string, and sending the database query statement to the database corresponding to each database connection engine.

[0147] Optionally, the conversion module 503 is further used for:

[0148] According to the pre-configured mapping relationship between the database table entity and the table name of the database table and the fields in the database table, the function keyword and its corresponding expression are converted into at least one database query statement segment.

[0149] Optionally, the mapping relationship is declared by entity annotation, and the declaration of the database table entity defines the table name of the database table corresponding to the entity class and the fields in the database table corresponding to the attributes in the entity class.

[0150] It should be noted that the specific implementation content of the device for querying a database in the present invention has been described in detail in the method for querying a database described above, so the repeated content will not be described again here.

[0151] Figure 6 An exemplary system architecture 600 is shown to which the method for querying a database or the apparatus for querying a database according to the embodiments of the present invention may be applied.

[0152] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0153] The user can use the terminal devices 601, 602, 603 to interact with the server 605 through the network 604 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 601, 602, 603, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only for example).

[0154] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.

[0155] The server 605 may be a server that provides various services, such as a backend management server (for example only) that provides support for shopping websites browsed by users using the terminal devices 601, 602, and 603. The backend management server may analyze and process the received data such as the item information query request, and feed back the processing results to the terminal device.

[0156] It should be noted that the method for querying a database provided in the embodiment of the present invention is generally executed by the server 605 , and accordingly, the device for querying a database is generally disposed in the server 605 .

[0157] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.

[0158] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of a terminal device suitable for implementing an embodiment of the present invention. Figure 7 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0159] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 to a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other through a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0160] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.

[0161] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.

[0162] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0163] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0164] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a receiving module, an identification module, a conversion module and a query module, wherein the names of these modules do not constitute a limitation on the modules themselves in some cases.

[0165] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device implements the following method: receiving a custom query statement transmitted from the business layer; identifying a function keyword and its corresponding expression from the custom query statement; converting the expression corresponding to the function keyword into at least one database query statement segment according to a pre-configured mapping relationship, and splicing the at least one database query statement into a database query statement; wherein the mapping relationship defines the corresponding relationship between each function keyword and each expression; identifying the identifier of one or more database connection engines from the custom query statement, calling the one or more database connection engines, so that each database connection engine sends the database query statement to the database corresponding to each database connection engine.

[0166] As another aspect, an embodiment of the present invention further provides a computer program product, including a computer program, and when the computer program is executed by a processor, the method described in any of the above embodiments is implemented.

[0167] According to the technical solution of the embodiment of the present invention, the expression corresponding to the function keyword identified from the custom query statement is converted into a database query statement according to a pre-configured mapping relationship, and then the identifier of one or more database connection engines is identified from the custom query statement, and one or more database connection engines are called to enable each database connection engine to send the database query statement to the database corresponding to each database connection engine. Therefore, the technical problems of framework redundancy and inability to adapt to multiple databases at the same time in the prior art are overcome. The embodiment of the present invention can realize multi-database support and can realize simultaneous operation of multiple databases, and does not need to reference third-party component packages, which helps to realize lightweight framework.

[0168] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for querying a database, characterized in that: include: Receive custom query statements transmitted from the business layer; Identify function keywords and their corresponding expressions from the custom query statement; According to a pre-configured mapping relationship, the expression corresponding to the function keyword is converted into at least one database query statement segment, and the at least one database query statement is spliced ​​into a database query statement; wherein the mapping relationship defines the corresponding relationship between each function keyword and each expression; Identify the identifiers of one or more database connection engines from the custom query statement, and call the one or more database connection engines so that each database connection engine sends the database query statement to a database corresponding to each database connection engine.

2. The method according to claim 1, characterized in that After calling the database connection engine, the method further includes: Receiving an execution result returned by the database connection engine, wherein the execution result is obtained after the database executes the database query statement and is returned by the database; The execution result is returned to the service layer.

3. The method according to claim 1, characterized in that Before receiving the custom query statement transmitted by the business layer, the method further includes: Configure each database connection engine and its corresponding database connection string in the configuration file; Initialize each database connection engine.

4. The method according to claim 3, characterized in that Identifying the identifiers of one or more database connection engines from the custom query statement, and calling the one or more database connection engines so that each database connection engine sends the database query statement to a database corresponding to each database connection engine, including: Identify the identifiers of one or more database connection engines from the custom query statement, call the one or more database connection engines, so that each database connection engine searches for the database connection string corresponding to each database connection engine from the configuration file, thereby performing data connection with each database according to each database connection string, and sending the database query statement to the database corresponding to each database connection engine.

5. The method according to claim 1, characterized in that According to the pre-configured mapping relationship, the expression corresponding to the function keyword is converted into at least one database query statement segment, including: According to the pre-configured mapping relationship between the database table entity and the table name of the database table and the fields in the database table, the function keyword and its corresponding expression are converted into at least one database query statement segment.

6. The method according to claim 5, characterized in that The mapping relationship is declared by entity annotation. The declaration of the database table entity defines the table name of the database table corresponding to the entity class and the fields in the database table corresponding to the attributes in the entity class.

7. A device for querying a database, characterized in that: include: The receiving module is used to receive the custom query statements transmitted from the business layer; An identification module, used to identify function keywords and their corresponding expressions from the custom query statement; A conversion module, used to convert the expression corresponding to the function keyword into at least one database query statement segment according to a pre-configured mapping relationship, and splice the at least one database query statement into one database query statement; wherein the mapping relationship defines the corresponding relationship between each function keyword and each expression; The query module is used to identify the identifiers of one or more database connection engines from the custom query statement, and call the one or more database connection engines to enable each database connection engine to send the database query statement to the database corresponding to each database connection engine.

8. The device according to claim 7, characterized in that The receiving module is also used for: Receiving an execution result returned by the database connection engine, wherein the execution result is obtained after the database executes the database query statement and is returned by the database; The execution result is returned to the service layer.

9. The device according to claim 7, characterized in that Also includes configuration modules for: Configure each database connection engine and its corresponding database connection string in the configuration file; Initialize each database connection engine.

10. The device according to claim 9, characterized in that The query module is also used for: Identify the identifiers of one or more database connection engines from the custom query statement, call the one or more database connection engines, so that each database connection engine searches for the database connection string corresponding to each database connection engine from the configuration file, thereby performing data connection with each database according to each database connection string, and sending the database query statement to the database corresponding to each database connection engine.

11. The device according to claim 7, characterized in that The conversion module is also used for: According to the pre-configured mapping relationship between the database table entity and the table name of the database table and the fields in the database table, the function keyword and its corresponding expression are converted into at least one database query statement segment.

12. The device according to claim 11, characterized in that The mapping relationship is declared by entity annotation. The declaration of the database table entity defines the table name of the database table corresponding to the entity class and the fields in the database table corresponding to the attributes in the entity class.

13. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.

14. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

15. 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 6 is implemented.