Data query method, server, device, and storage medium

CN115982199BActive Publication Date: 2026-09-15SHENZHEN FULIN TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310014256.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-01-05
Publication Date
2026-09-15
Estimated Expiration
2043-01-05

AI Technical Summary

Technical Problem

[0003]现有技术中,并没有统一规范化且功能全面的实现GraphQL查询的方法,此外,GraphQL支持嵌套查询的语法,GraphQL查询语句可以解析成一棵多叉树,但是随着嵌套层数的增加,对数据源的访问次数会呈指数级上升,查询结果的大小也会指数级上升,这会对服务端造成巨大的压力,严重影响GraphQL的查询效率

Benefits of technology

[0036] This invention standardizes and configures GraphQL queries through pre-configured preset type pools and preset attribute pools, improving development efficiency and query comprehensiveness. At the same time, it adopts a combination of wrapper parsing functions and multi-goroutine execution to ensure that batch queries of the same level of attributes are effective without generating additional goroutines, thus improving query efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115982199B_ABST
    Figure CN115982199B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of data processing, and discloses a data query method, which comprises the following steps: receiving a query request triggered by a user on a query page, parsing a GraphQL query statement of the query request to obtain a data type corresponding to the query request; obtaining a function type corresponding to the data type from a preset type pool and obtaining an analysis function corresponding to the function type from a preset attribute pool; executing the analysis function to obtain a plurality of SQL query statements, splicing the plurality of SQL query statements to obtain a dynamic query statement, executing the dynamic query statement to obtain a query result, and returning the query result to the query page. The data query method improves the development efficiency and query comprehensiveness, and adopts a combination method of a wrapped analysis function and multi-coroutine execution to ensure that batch queries of the same layer of attributes are normally effective without generating additional goroutines, thereby improving the query efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to a data query method, server, device and storage medium. Background Technology

[0002] GraphQL was proposed by Facebook in 2012 and has been widely used in web application development in recent years. According to its official definition, GraphQL is an API query language and a server-side runtime that can perform query operations on data based on a user-defined type system.

[0003] In the current technology, there is no unified, standardized and fully functional method for implementing GraphQL queries. In addition, GraphQL supports nested query syntax. GraphQL query statements can be parsed into a multi-branch tree. However, as the nesting level increases, the number of accesses to the data source will increase exponentially, and the size of the query results will also increase exponentially. This will put a huge pressure on the server and seriously affect the query efficiency of GraphQL. Summary of the Invention

[0004] In light of the above, it is necessary to provide a data query method to improve the data query efficiency of nested queries in GraphQL.

[0005] To achieve the above objectives, the present invention provides a data query method applied to a server, the method comprising:

[0006] Receive a query request triggered by a user on the query page, parse the GraphQL query statement of the query request to obtain the data type corresponding to the query request;

[0007] Retrieve the function type corresponding to the data type from the preset type pool, and retrieve the parsing function corresponding to the function type from the preset attribute pool;

[0008] The parsing function is executed to obtain multiple SQL query statements. The multiple SQL query statements are concatenated to obtain a dynamic query statement. The dynamic query statement is executed to obtain the query results, and the query results are returned to the query page.

[0009] Optionally, parsing the GraphQL query statement of the query request to obtain the data type corresponding to the query request includes:

[0010] Extract the request parameters from the query request, and use a parser to parse the request parameters according to GraphQL syntax to obtain a query tree;

[0011] The query tree is recursively processed by the query preprocessor according to the parameter type to obtain a syntactically correct recursive query tree structure.

[0012] The data type corresponding to the request parameters of the query request is obtained by parsing the recursive query tree structure.

[0013] Optionally, before obtaining the function type corresponding to the data type from the preset type pool and the parsing function corresponding to the function type from the preset attribute pool, the following steps are included:

[0014] The database build page queries the corresponding query data table;

[0015] Build a pool of preset types and a pool of preset properties using the application framework;

[0016] Register the function types defined in the preset attribute pool into the package containing the parsing function.

[0017] Optionally, the construction of the preset type pool and preset attribute pool through the application framework includes:

[0018] The application framework defines data types and their corresponding functional types to generate a preset type pool.

[0019] The application framework establishes a mapping between the data fields of the query data table and the function types to generate a preset attribute pool.

[0020] Optionally, after constructing the preset type pool and preset property pool through the application framework, the method further includes:

[0021] When the query service corresponding to the query data table is started, the preset type pool and the preset attribute pool are initialized.

[0022] Optionally, the execution of the parsing function to obtain multiple SQL query statements includes:

[0023] Multiple parsing functions obtained from the preset property pool are wrapped into multiple Thunk objects;

[0024] The multiple Thunk objects are distributed to multiple coroutines for execution, resulting in the SQL query statement corresponding to each parsing function.

[0025] Optionally, distributing the plurality of Thunk objects to multiple coroutines for execution includes:

[0026] The depth-first traversal algorithm is used to traverse and find the shallowest unexecuted Thunk objects, and the multiple unexecuted Thunk objects are collected and executed together to obtain the execution result;

[0027] If the execution result contains slice and map data types, then the execution results of slice and map data types are added to the stack, and the next round of depth-first traversal is executed until the execution result no longer contains slice and map data types.

[0028] Furthermore, to achieve the above objectives, the present invention also provides a data query device, the data query device comprising:

[0029] The request processing module is used to receive query requests triggered by users on the query page, parse the GraphQL query statement of the query request to obtain the data type corresponding to the query request;

[0030] The function configuration module is used to obtain the function type corresponding to the data type from the preset type pool and the parsing function corresponding to the function type from the preset attribute pool;

[0031] The data query module is used to execute the parsing function to obtain multiple SQL query statements, concatenate the multiple SQL query statements to obtain a dynamic query statement, execute the dynamic query statement to obtain query results, and return the query results to the query page.

[0032] Furthermore, to achieve the above objectives, the present invention also provides an electronic device, the electronic device comprising:

[0033] Memory, storing at least one computer program; and

[0034] The processor executes the program stored in the memory to implement the data query method described above.

[0035] In addition, to achieve the above objectives, the present invention also provides a computer-readable storage medium storing at least one computer program, which is executed by a processor in an electronic device to implement the data query method described above.

[0036] This invention standardizes and configures GraphQL queries through pre-configured preset type pools and preset attribute pools, improving development efficiency and query comprehensiveness. At the same time, it adopts a combination of wrapper parsing functions and multi-goroutine execution to ensure that batch queries of the same level of attributes are effective without generating additional goroutines, thus improving query efficiency. Attached Figure Description

[0037] Figure 1 This is an exemplary system architecture diagram in which the present invention can be applied;

[0038] Figure 2 This is a flowchart of an embodiment of the data query method of the present invention;

[0039] Figure 3 This is a schematic diagram of an embodiment of the electronic device of the present invention;

[0040] Figure 4 This is a schematic diagram of an embodiment of the data query device of the present invention;

[0041] Figure 5 This is a flowchart of an embodiment of the data query program in the electronic device of the present invention.

[0042] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0043] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without inventive effort are within the scope of protection of this invention.

[0044] It should be noted that the descriptions involving "first," "second," etc., in this invention are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of that feature. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed by this invention.

[0045] like Figure 1 As shown, system architecture 100 may include terminal devices 101, 102, and 103, a network 104, and a server 105. Network 104 serves as the medium for providing communication links between terminal devices 101, 102, and 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0046] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social media platform software, etc.

[0047] Terminal devices 101, 102, and 103 can be various electronic devices with displays and support web browsing, including but not limited to smartphones, tablets, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 players (Moving Picture Experts Group Audio Layer IV), laptops, and desktop computers, etc.

[0048] Server 105 can be a server that provides various services, such as a backend server that supports the pages displayed on terminal devices 101, 102, and 103.

[0049] It should be noted that the data query method provided in this application embodiment is generally executed by a server / terminal device, and correspondingly, the data query device is generally set in the server / terminal device.

[0050] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0051] Example 1

[0052] like Figure 2 The diagram shown is a flowchart of an embodiment of the data query method of the present invention. The data query method is applied to a data query device and includes steps S1-S3.

[0053] S1. Receive the query request triggered by the user on the query page, and parse the GraphQL query statement of the query request to obtain the data type corresponding to the query request.

[0054] In one embodiment, the data types obtained by parsing the GraphQL query statement of the query request include:

[0055] Extract the request parameters of the query request, and use a parser to parse the request parameters according to GraphQL syntax to obtain a query tree, which is a SelectionSet data structure;

[0056] The query tree is recursively processed by the query preprocessor according to the parameter type to obtain a syntactically correct recursive query tree structure.

[0057] The data type corresponding to the request parameters of the query request is obtained by parsing the recursive query tree structure.

[0058] Specifically, SelectionSet represents all subquery fields under the currently queried field in the GraphQL query tree. In this embodiment, the query tree is traversed using a recursive algorithm, and the recursive algorithm is optimized using a query preprocessor. Furthermore, breadth-first and depth-first optimization instructions for the query tree can be configured in the query preprocessor for subsequent calls.

[0059] Specifically, the recursive query tree structure is parsed to obtain one or more words with fixed formats, which are used as the data types corresponding to the request parameters of the query request. The number of queries corresponding to each data type is determined based on the word. When the parsed word contains the suffix "-s", the number of queries corresponding to that data type is determined to be multiple; when the parsed word does not contain the suffix "-s", the number of queries corresponding to that data type is determined to be single. For example, if the parsed word is "projects", then the data type corresponding to the request parameter of the query request is determined to be "projects", and the number of queries corresponding to that data type is multiple.

[0060] In this embodiment, the query preprocessor employs recursive queries that support nested query parameters. Different processing methods are used depending on the parameter type, such as list queries, union queries, and single object queries. It determines whether the entire query tree conforms to the syntax, ensuring compatibility with complex data query needs. The request parameters for the query request have a fixed format; the first word obtained through syntax analysis indicates the data type corresponding to that request parameter.

[0061] S2. Obtain the function type corresponding to the data type from the preset type pool, and obtain the parsing function corresponding to the function type from the preset attribute pool.

[0062] In one embodiment, the server pre-builds a query data table corresponding to the page query request in the database, and constructs a preset type pool and a preset attribute pool through the application framework. The functional types defined in the preset attribute pool are registered to a program package containing parsing functions. This embodiment achieves dynamic addition or removal of attributes without service downtime by registering the preset attribute pool.

[0063] Specifically, the preset type pool and the preset attribute pool are standardized interfaces built according to the application framework, and these standardized interfaces are pre-configured. The configuration content includes, but is not limited to, attribute types, parsing functions, corresponding names, and whether they are required. The server retrieves the corresponding function type from the preset type pool interface through a query interface configuration based on the parsed data type, and then retrieves the corresponding parsing function from the preset attribute pool interface through a query interface configuration based on the function type.

[0064] In this embodiment, when the interface for the preset type pool and preset attribute pool is implemented through the application framework, the tool based on the application framework automatically generates the initial code.

[0065] Specifically, the construction of the preset type pool and preset attribute pool through the application framework includes:

[0066] The application framework defines data types and their corresponding functional types to generate a preset type pool.

[0067] The application framework establishes a mapping between the data fields of the query data table and the function types to generate a preset attribute pool.

[0068] In one embodiment, the server initializes the preset type pool and the preset attribute pool when the query service corresponding to the query data table is started.

[0069] In one embodiment, when constructing a preset attribute pool through an application framework, a mapping is established between database fields and attributes in the preset attribute pool based on the interface of the preset attribute pool.

[0070] S3. Execute the parsing function to obtain multiple SQL query statements, concatenate the multiple SQL query statements to obtain a dynamic query statement, execute the dynamic query statement to obtain query results, and return the query results to the query page.

[0071] In one embodiment, executing the parsing function to obtain multiple SQL query statements includes:

[0072] Multiple parsing functions obtained from a preset attribute pool are packaged into multiple Thunk objects, and these multiple Thunk objects are distributed to multiple coroutines for execution to obtain the SQL query statement corresponding to each parsing function, thereby improving query efficiency.

[0073] Specifically, distributing the multiple Thunk objects to multiple goroutines for execution includes: using a depth-first search algorithm to find the shallowest unexecuted Thunk objects, collecting these unexecuted Thunk objects together for unified execution to obtain the execution result; if the execution result contains slice and map data types, then the execution results of slice and map data types are added to the stack, and the next round of depth-first traversal is executed until the execution result no longer contains slice and map data types. This method can ensure that batch queries of the same level of attributes work normally without generating additional goroutines, thus improving query efficiency.

[0074] Specifically, the dynamic query statement is a dynamic SQL query statement that makes judgments based on conditions. When field names, table names, database names, etc. are used as variables, SQL data queries must be performed using dynamic SQL statements.

[0075] As can be seen from the above embodiments, the data query method proposed in this invention achieves standardized and configurable processing of GraphQL queries through a pre-configured preset type pool and preset attribute pool, which improves development efficiency and query comprehensiveness. At the same time, by adopting a combination of wrapper parsing functions and multi-goroutine execution, batch queries of the same layer of attributes are guaranteed to take effect normally without generating additional goroutines, thus improving query efficiency.

[0076] like Figure 3 The diagram shown is a schematic representation of an embodiment of the electronic device of the present invention. The electronic device 1 is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions. The electronic device 1 can be a computer, a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing, which is a type of distributed computing consisting of a super virtual computer composed of a group of loosely coupled computers.

[0077] In this embodiment, the electronic device 1 includes, but is not limited to, a memory 11, a processor 12, and a network interface 13 that can be interconnected via a system bus. The memory 11 stores a data query program 10, which can be executed by the processor 12. Figure 3 Only the electronic device 1 having components 11-13 and the data query program 10 is shown. Those skilled in the art will understand that... Figure 3 The structure shown does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown, or combine certain components, or have different component arrangements.

[0078] The memory 11 includes RAM and at least one type of readable storage medium. The RAM provides a cache for the operation of the electronic device 1; the readable storage medium can be volatile or non-volatile. Specifically, the readable storage medium can be a storage medium such as flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the readable storage medium can be an internal storage unit of the electronic device 1, such as the hard disk of the electronic device 1; in other embodiments, the storage medium can also be an external storage device of the electronic device 1, such as a plug-in hard disk, smart media card (SMC), secure digital card (SD), flash card, etc., equipped on the electronic device 1. In this embodiment, the readable storage medium of the memory 11 mainly includes a program storage area and a data storage area. The program storage area is typically used to store the operating system and various application software installed on the electronic device 1, such as the code of the data query program 10 in one embodiment of the present invention. The data storage area can store data created based on the use of blockchain nodes, such as various types of data that have been output or will be output.

[0079] In some embodiments, processor 12 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. Processor 12 is typically used to control the overall operation of the electronic device 1, such as performing control and processing related to data interaction or communication with other devices. In this embodiment, processor 12 is used to run program code stored in memory 11 or process data, such as running data query program 10.

[0080] The network interface 13 may include a wireless network interface or a wired network interface, which is used to establish a communication connection between the electronic device 1 and the client (not shown in the figure).

[0081] Optionally, the electronic device 1 may further include a user interface, which may include a display, an input unit such as a keyboard, and optionally, a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an organic light-emitting diode (OLED) touchscreen, etc. The display may also be appropriately referred to as a screen or display unit, used to display information processed in the electronic device 1 and to display a visual user interface.

[0082] In one embodiment of the present invention, when the data query program 10 is executed by the processor 12, it performs the following steps S1-S3.

[0083] S1. Receive the query request triggered by the user on the query page, and parse the GraphQL query statement of the query request to obtain the data type corresponding to the query request;

[0084] S2. Obtain the function type corresponding to the data type from the preset type pool, and obtain the parsing function corresponding to the function type from the preset attribute pool;

[0085] S3. Execute the parsing function to obtain multiple SQL query statements, concatenate the multiple SQL query statements to obtain a dynamic query statement, execute the dynamic query statement to obtain query results, and return the query results to the query page.

[0086] The specific operation steps implemented by the above steps S1-S3 are largely the same as those in an embodiment of the data query method of the present invention, and will not be repeated here.

[0087] In other embodiments, the data query program 10 may be divided into one or more modules, which are stored in the memory 11 and executed by one or more processors (processor 12 in this embodiment) to complete the present invention. The module referred to in the present invention refers to a series of computer program instruction segments that can perform specific functions and are used to describe the execution process of the data query program 10 in the electronic device 1.

[0088] like Figure 4 The diagram shown is a schematic diagram of an embodiment of the data query device of the present invention.

[0089] In a first embodiment of the present invention, the data query device 10 includes a request processing module 110, a function configuration module 120, and a data query module 130, exemplarily:

[0090] The request processing module 110 is used to receive a query request triggered by a user on the query page, and parse the GraphQL query statement of the query request to obtain the data type corresponding to the query request.

[0091] In one embodiment, the request processing module 110 parses the GraphQL query statement of the query request to obtain data types including:

[0092] Extract the request parameters of the query request, and use a parser to parse the request parameters according to GraphQL syntax to obtain a query tree, which is a SelectionSet data structure;

[0093] The query tree is recursively processed by the query preprocessor according to the parameter type to obtain a syntactically correct recursive query tree structure.

[0094] The data type corresponding to the request parameters of the query request is obtained by parsing the recursive query tree structure.

[0095] Specifically, SelectionSet represents all subquery fields under the currently queried field in the GraphQL query tree. In this embodiment, the query tree is traversed using a recursive algorithm, and the recursive algorithm is optimized using a query preprocessor. Furthermore, breadth-first and depth-first optimization instructions for the query tree can be configured in the query preprocessor for subsequent calls.

[0096] Specifically, the recursive query tree structure is parsed to obtain one or more words with fixed formats, which are used as the data types corresponding to the request parameters of the query request. The number of queries corresponding to each data type is determined based on the word. When the parsed word contains the suffix "-s", the number of queries corresponding to that data type is determined to be multiple; when the parsed word does not contain the suffix "-s", the number of queries corresponding to that data type is determined to be single. For example, if the parsed word is "projects", then the data type corresponding to the request parameter of the query request is determined to be "projects", and the number of queries corresponding to that data type is multiple.

[0097] In this embodiment, the query preprocessor employs recursive queries that support nested query parameters. Different processing methods are used depending on the parameter type, such as list queries, union queries, and single object queries. It determines whether the entire query tree conforms to the syntax, ensuring compatibility with complex data query needs. The request parameters for the query request have a fixed format; the first word obtained through syntax analysis indicates the data type corresponding to that request parameter.

[0098] The function configuration module 120 is used to obtain the function type corresponding to the data type from the preset type pool and the parsing function corresponding to the function type from the preset attribute pool.

[0099] In one embodiment, the server pre-builds a query data table corresponding to the page query request in the database, and constructs a preset type pool and a preset attribute pool through the application framework. The functional types defined in the preset attribute pool are registered to a program package containing parsing functions. This embodiment achieves dynamic addition or removal of attributes without service downtime by registering the preset attribute pool.

[0100] Specifically, the preset type pool and the preset attribute pool are standardized interfaces built according to the application framework, and these standardized interfaces are pre-configured. The configuration content includes, but is not limited to, attribute types, parsing functions, corresponding names, and whether they are required. The server retrieves the corresponding function type from the preset type pool interface through a query interface configuration based on the parsed data type, and then retrieves the corresponding parsing function from the preset attribute pool interface through a query interface configuration based on the function type.

[0101] In this embodiment, when the interface for the preset type pool and preset attribute pool is implemented through the application framework, the tool based on the application framework automatically generates the initial code.

[0102] Specifically, the construction of the preset type pool and preset attribute pool through the application framework includes:

[0103] The application framework defines data types and their corresponding functional types to generate a preset type pool.

[0104] The application framework establishes a mapping between the data fields of the query data table and the function types to generate a preset attribute pool.

[0105] In one embodiment, the server initializes the preset type pool and the preset attribute pool when the query service corresponding to the query data table is started.

[0106] In one embodiment, when constructing a preset attribute pool through an application framework, a mapping is established between database fields and attributes in the preset attribute pool based on the interface of the preset attribute pool.

[0107] The data query module 130 is used to execute the parsing function to obtain multiple SQL query statements, concatenate the multiple SQL query statements to obtain a dynamic query statement, execute the dynamic query statement to obtain query results, and return the query results to the query page.

[0108] In one embodiment, the data query module 130 executes the parsing function to obtain multiple SQL query statements, including:

[0109] Multiple parsing functions obtained from a preset attribute pool are packaged into multiple Thunk objects, and these multiple Thunk objects are distributed to multiple coroutines for execution to obtain the SQL query statement corresponding to each parsing function, thereby improving query efficiency.

[0110] Specifically, distributing the multiple Thunk objects to multiple goroutines for execution includes: using a depth-first search algorithm to find the shallowest unexecuted Thunk objects, collecting these unexecuted Thunk objects together for unified execution to obtain the execution result; if the execution result contains slice and map data types, then the execution results of slice and map data types are added to the stack, and the next round of depth-first traversal is executed until the execution result no longer contains slice and map data types. This method can ensure that batch queries of the same level of attributes work normally without generating additional goroutines, thus improving query efficiency.

[0111] Specifically, the dynamic query statement is a dynamic SQL query statement that makes judgments based on conditions. When field names, table names, database names, etc. are used as variables, SQL data queries must be performed using dynamic SQL statements.

[0112] Furthermore, this embodiment of the invention also proposes a computer-readable storage medium, which can be volatile or non-volatile. Specifically, the computer-readable storage medium can be any one or any combination of several of the following: hard disk, multimedia card, SD card, flash memory card, SMC, read-only memory (ROM), erasable programmable read-only memory (EPROM), portable compact disc read-only memory (CD-ROM), USB memory, etc. The computer-readable storage medium stores a data query program 10.

[0113] like Figure 5 The diagram shown is a flowchart illustrating an embodiment of a data query program 10 in a computer-readable storage medium according to the present invention. When the data query program 10 is executed by a processor, it performs the following operations:

[0114] A1. Receive query requests triggered by users on the query page;

[0115] A2. Parse the GraphQL query statement of the query request to obtain the data type corresponding to the query request;

[0116] A3. Obtain the function type corresponding to the data type from the preset type pool;

[0117] A4. Obtain the parsing function corresponding to the function type from the preset attribute pool;

[0118] A5. Execute the parsing function to obtain multiple SQL query statements, and concatenate the multiple SQL query statements to obtain a dynamic query statement;

[0119] A6. Execute the dynamic query statement to obtain the query results, and return the query results to the query page.

[0120] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0121] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, data querying device, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, data querying device, article, or method. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, data querying device, article, or method that includes that element.

[0122] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0123] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.

Claims

1. A data query method, applied to a server, characterized in that, The method includes: Receive a query request triggered by a user on the query page, parse the GraphQL query statement of the query request to obtain the data type corresponding to the query request; On the database construction page, query the data table corresponding to the query request, build a preset type pool and a preset attribute pool through the application framework, register the functional types defined in the preset attribute pool to the program package containing the parsing function, obtain the functional type corresponding to the data type by querying the interface configuration of the preset type pool, and obtain the parsing function corresponding to the functional type by querying the interface configuration of the preset attribute pool. Multiple parsing functions obtained from a preset attribute pool are packaged into multiple Thunk objects. These Thunk objects are then distributed to multiple coroutines. A depth-first traversal algorithm is used to find the shallowest unexecuted Thunk objects. These unexecuted Thunk objects are then aggregated and executed to obtain the execution result. If the execution result contains slice and map data types, the execution results of slice and map data types are added to the stack, and the next round of depth-first traversal is executed until the execution result no longer contains slice and map data types. This yields the SQL query statement corresponding to each parsing function. Multiple SQL query statements are concatenated to obtain a dynamic query statement. The dynamic query statement is then executed to obtain the query result, which is then returned to the query page.

2. The data query method as described in claim 1, characterized in that, Parsing the GraphQL query statement of the query request yields the data types corresponding to the query request, including: Extract the request parameters from the query request, and use a parser to parse the request parameters according to GraphQL syntax to obtain a query tree; The query tree is recursively processed by the query preprocessor according to the parameter type to obtain a syntactically correct recursive query tree structure. The data type corresponding to the request parameters of the query request is obtained by parsing the recursive query tree structure.

3. The data query method as described in claim 1, characterized in that, The construction of the preset type pool and preset attribute pool through the application framework includes: The application framework defines data types and their corresponding functional types to generate a preset type pool. The application framework establishes a mapping between the data fields of the query data table and the function types to generate a preset attribute pool.

4. The data query method as described in claim 1, characterized in that, After building the preset type pool and preset property pool through the application framework, the method also includes: When the query service corresponding to the query data table is started, the preset type pool and the preset attribute pool are initialized.

5. A data query device, characterized in that, The data query device includes: The request processing module is used to receive query requests triggered by users on the query page, parse the GraphQL query statement of the query request to obtain the data type corresponding to the query request; The function configuration module is used to query the data table corresponding to the query request on the database construction page, build a preset type pool and a preset attribute pool through the application framework, register the function types defined in the preset attribute pool to the program package containing the parsing function, obtain the function type corresponding to the data type by querying the interface configuration of the preset type pool, and obtain the parsing function corresponding to the function type by querying the interface configuration of the preset attribute pool. The data query module is used to package multiple parsing functions obtained from a preset attribute pool into multiple Thunk objects, distribute these Thunk objects to multiple coroutines, and use a depth-first traversal algorithm to find the shallowest unexecuted Thunk objects. These unexecuted Thunk objects are then aggregated and executed to obtain the execution result. If the execution result contains slice and map data types, the execution results of slice and map data types are added to a stack, and the next round of depth-first traversal is executed until the execution result no longer contains slice and map data types. This process yields the SQL query statement corresponding to each parsing function, concatenates multiple SQL query statements to obtain a dynamic query statement, executes the dynamic query statement to obtain the query result, and returns the query result to the query page.

6. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the data query method as described in any one of claims 1 to 4.

7. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the data query method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • GraphQL-based data processing method and device, service terminal and storage medium

    CN112783958A