Data query method and data query device based on Gorm

By storing Gorm query variables in the preset instance model, the problem of redevelopment of Gorm instances is solved, the efficiency and accuracy of data query are achieved, and the development efficiency is improved.

CN118916407APending Publication Date: 2024-11-08SUZHOU DAJIAYING INFORMATION TECH CO LTD +1
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411099678.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-12
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

When using Gorm for database data query, the Gorm instance needs to be redeveloped when the statistical dimension changes, resulting in repeated writing of filtering condition codes, which reduces development efficiency.

Method used

By storing multiple Gorm query variables in the preset instance model, the corresponding Gorm query variables are directly obtained from the preset instance model according to the new data filtering conditions, and the target Gorm query statement is generated to avoid repeated writing of query condition code.

Benefits of technology

It improves development efficiency, simplifies development difficulty, reduces the number of query conditions that need to be written, and ensures the accuracy of data queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916407A_ABST
    Figure CN118916407A_ABST
Patent Text Reader

Abstract

The invention relates to a Gorm-based data query method and device, and the method comprises the steps: obtaining a current data screening condition corresponding to a data query instruction in response to the data query instruction; under the condition that the type of the current data screening condition does not belong to the stored type, creating a new data query model; under the condition that a target query condition is determined based on the current data screening condition, a target Gorm query variable corresponding to the target query condition is obtained from a preset instance model, and the preset instance model is a Gorm instance configured with a plurality of Gorm query variables; under the condition that a target Gorm query statement is generated based on the target query condition and the target Gorm query variable, configuring a data query model through the target Gorm query statement; and operating the data query model to obtain a data query result. The query conditions are copied from the preset instance model, codes of the query conditions do not need to be written repeatedly, and the development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of data processing, and in particular to a data query method and a data query device based on Gorm. Background Art

[0002] Gorm is an excellent ORM (object-relational mapping) library in Go language, which provides a simple and powerful way to handle database operations. At present, for database data query, you can use a solution based on Gorm, for example, write a data query model based on Gorm to realize query statistics of specified data. However, a Gorm instance can only correspond to one statistical method. When facing the same statistical object, if the statistical dimension changes, you need to redevelop a Gorm instance. During the redevelopment process, you need to repeatedly write the code related to the filtering conditions, resulting in low development efficiency. Summary of the invention

[0003] In order to solve at least one of the above-mentioned technical problems, the present disclosure proposes a data query method and a data query device based on Gorm.

[0004] According to some embodiments of the present disclosure, a Gorm-based data query method is provided, including: in response to a data query instruction, obtaining a current data screening condition corresponding to the data query instruction; when the type of the current data screening condition does not belong to a stored type, creating a new data query model, the data query model is used to configure a Gorm query statement to implement a data query function; when a target query condition is determined based on the current data screening condition, obtaining a target Gorm query variable corresponding to the target query condition from a preset instance model, the preset instance model is a Gorm instance configured with multiple Gorm query variables; when a target Gorm query statement is generated based on the target query condition and the target Gorm query variable, configuring the data query model through the target Gorm query statement; and running the data query model to obtain a data query result.

[0005] Based on the above solution, by storing multiple Gorm query variables in the preset instance model, when generating new types of data filtering conditions, the Gorm query variables can be directly obtained from the existing preset instance model to generate the target Gorm query statement, without having to repeatedly write the query condition code according to the current data filtering conditions, thereby improving development efficiency.

[0006] In some possible implementations, the preset instance model is obtained based on the following method: establishing a blank query model, the blank query model is used to configure Gorm query variables; based on the attribute relationship of the target database, determining a first object, the first object is a structure variable that is mapped to the target database, and the target database is a database connected to the blank query model; when the Gorm query variable corresponding to the first object is determined based on the target database, the blank query model is configured by the Gorm query variable corresponding to the first object to obtain the preset instance model.

[0007] Based on the above solution, by establishing a connection with the target database and using object-relational mapping to prepare structure variables in advance, the data screening conditions for the target database can be converted into Gorm query variables. When facing the query and statistical business of the same target database, the Gorm query variables can be directly obtained to improve development efficiency.

[0008] In some possible implementations, before determining the Gorm query variable corresponding to the first object based on the target database, the method further includes: obtaining preset data screening conditions of the target database; when the query conditions of the first object are determined based on the preset data screening conditions, configuring the query conditions of the first object into a second object, the second object representing a structure variable for storing the query conditions; generating a first query function based on the second object, the first query function including at least one Gorm query variable, and the at least one Gorm query variable corresponding to the query conditions of the first object.

[0009] Based on the above solution, the second object can store as many query conditions of the first object as possible, which helps to reduce the number of query conditions that require additional code writing when facing query statistics business of new statistical dimensions in the future, thereby simplifying the development difficulty.

[0010] In some possible implementations, the blank query model is configured through the Gorm query variable corresponding to the first object to obtain the preset instance model, including: generating a Gorm query instance based on the first object, the Gorm query instance being used to implement data query on the target database; configuring the first query function into the Gorm query instance; and assigning a value to the at least one Gorm query variable in the first query function based on the preset data screening condition.

[0011] Based on the above solution, by instantiating the first object, the query conditions of the first object can be saved, so that when a new data query model is created, the corresponding query conditions can be directly called from the Gorm query instance, thereby simplifying the development workload.

[0012] In some possible implementations, obtaining a target Gorm query variable corresponding to the target query condition from a preset instance model includes: obtaining the second object from the preset instance model; obtaining the common query condition between the target query condition and the query condition of the first object; and generating a second query function based on the second object and the common query condition, wherein the second query function includes the target Gorm query variable, and the target Gorm query variable corresponds to the common query condition.

[0013] Based on the above scheme, the second object includes all query conditions of the first object. By finding the target query conditions from the query conditions of the first object, unnecessary query conditions can be removed, and only query conditions that meet the current data screening conditions are retained. Then, the corresponding Gorm query variable in the second object is obtained to complete the acquisition of the query conditions.

[0014] In some possible implementations, the target Gorm query statement is generated based on the target query condition and the target Gorm query variable, including: assigning a value to the target Gorm query variable in the second query function based on the current data screening condition; establishing a third query function based on the newly added query condition, and the newly added query condition indicates the query condition in the target query condition that does not belong to the common query condition.

[0015] Based on the above scheme, by functionalizing the second object, the second query function only accepts the Gorm query variable corresponding to the common query condition and reassigns it, so that the data query model will not be affected by the original assignment when referencing the query condition of the preset instance model; and by functionalizing the newly added query conditions, the accuracy of the data query can be ensured.

[0016] According to some other embodiments of the present disclosure, a Gorm-based data query device is provided, including: an instruction acquisition module, configured to execute in response to a data query instruction, and obtain a current data filtering condition corresponding to the data query instruction; a model generation module, configured to execute, when the type of the current data filtering condition does not belong to a stored type, to create a new data query model; a variable acquisition module, configured to execute, when a target query condition is determined based on the current data filtering condition, to obtain a target Gorm query variable corresponding to the target query condition from a preset instance model; a model configuration module, configured to execute, when a target Gorm query statement is generated based on the target query condition and the target Gorm query variable, to configure the data query model through the target Gorm query statement.

[0017] According to some other embodiments of the present disclosure, a computer-readable storage medium is provided, in which at least one instruction or at least one program is stored, and the at least one instruction or at least one program is loaded and executed by a processor to implement a Gorm-based data query method described in some of the above embodiments.

[0018] According to some other embodiments of the present disclosure, there is provided an electronic device, comprising at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the at least one processor implements a Gorm-based data query method described in some of the above embodiments by executing the instructions stored in the memory.

[0019] According to some other embodiments of the present disclosure, a computer program product is provided, including computer instructions, which, when executed by a processor, implement a Gorm-based data query method described in some of the above embodiments.

[0020] It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.

[0021] Further features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solutions and advantages in the embodiments of this specification or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0023] Figure 1 A flowchart showing a data query method based on Gorm according to an embodiment of the present disclosure is shown;

[0024] Figure 2 A flowchart showing the steps of establishing a configuration of a preset instance model according to an embodiment of the present disclosure;

[0025] Figure 3 A flowchart showing the steps of determining a Gorm query variable corresponding to a first object according to an embodiment of the present disclosure is shown;

[0026] Figure 4 A flowchart showing the steps of configuring a blank query model based on a Gorm query variable according to an embodiment of the present disclosure is shown;

[0027] Figure 5 A flowchart showing the steps of obtaining a target Gorm query variable according to an embodiment of the present disclosure is shown;

[0028] Figure 6 A flowchart showing the steps of generating a target Gorm query statement according to an embodiment of the present disclosure is shown;

[0029] Figure 7 A structural block diagram of a Gorm-based data query device according to an embodiment of the present disclosure is shown;

[0030] Figure 8 A block diagram of an electronic device according to an embodiment of the present disclosure is shown;

[0031] Fig. 9 A block diagram of another electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0032] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0033] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.

[0034] Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.

[0035] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.

[0036] The term "and / or" herein is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C can represent including any one or more elements selected from the set consisting of A, B, and C.

[0037] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.

[0038] In order to facilitate understanding of the disclosed solution, some technical names in the disclosed embodiments are explained as follows:

[0039] Go language, (also known as Go language), is a statically strongly typed, compiled language developed by Robert Griesemer, Rob Pick and Ken Thompson of Google. The syntax of Go language is similar to C, but its functions include: memory safety, GC (garbage collection), structural form and CSP-style concurrent computing.

[0040] Gorm is an excellent ORM (object-relational mapping) library in the Go language. It provides a simple and powerful way to handle database operations, simplifying the process of developers interacting with the database in Go language projects.

[0041] The ORM (Object Relational Mapping) framework uses metadata to describe the details of object-relational mapping. The metadata is generally in XML format and stored in a special object-mapping file.

[0042] Data query services usually require the execution of specified screening steps on the data stored in the database, so as to present the data within the specified range required by the user for subsequent processing. At present, a solution based on Gorm can be used for database data query. Gorm provides a rich API interface to perform CRUD (create, delete, modify and query) operations. Developers can directly write code for structure objects, and Gorm can automatically compile the code into SQL statements, reducing development difficulty and improving development efficiency.

[0043] However, the data query solution based on Gorm also has shortcomings. Since Gorm processes variables mapped to the database, this feature makes Gorm unable to provide statistical methods for different dimensions in the same instance at the same time. For example, in a specific application scenario, when calculating financial settlement statistics, the business end needs to filter the bills to obtain bill records of specified objects, specified amounts, specified times or other specified attributes. At this time, a data query model can be written based on Gorm to realize query statistics of specified data, and query conditions can be set separately to realize the above query functions. However, when a new business is generated or a business needs to add a new statistical dimension, the filtering conditions change, resulting in changes in the Gorm query conditions. In order to ensure the accuracy of data query, the code needs to be rewritten to correspond to the filtering conditions. In other words, a Gorm instance can only correspond to one statistical method. When facing the same statistical object, if the statistical dimension changes, a data query tool needs to be redeveloped, that is, a new Gorm instance. In the redevelopment process, the filtering condition-related code needs to be repeatedly written, resulting in low development efficiency.

[0044] In order to solve the above technical problems, an embodiment of the present disclosure provides a data query method based on Gorm. The method stores query conditions in a Gorm instance. When new data filtering conditions are generated, they are converted into query conditions, and then the relevant query conditions are directly copied from the above Gorm instance. There is no need to repeatedly write the query condition code according to the filtering conditions, which reduces the development difficulty, improves the development efficiency, and also helps to reduce the redundancy of the query method encapsulation.

[0045] Figure 1 The step flow chart of the data query method based on Gorm in the present disclosure is shown as follows: Figure 1 As shown, the method of the present disclosure includes:

[0046] Step S101: In response to a data query instruction, obtain a current data screening condition corresponding to the data query instruction.

[0047] In the disclosed embodiment, the data screening condition is a direct requirement of the front-end business. In a specific application scenario, taking the financial settlement statistics business as an example, the front-end business includes but is not limited to counting bill records for a specified time period, counting bill records for a specified subject amount, counting the total tax amount for a specified time period, and counting the transaction amount of a specified transaction object.

[0048] Step S102: When the type of the current data screening condition does not belong to the stored type, a new data query model is created, and the data query model is used to configure the Gorm query statement to implement the data query function.

[0049] In the disclosed embodiments, the type of data screening condition can be understood as a data statistical dimension. Based on the above content, it can be seen that the data screening condition is a direct demand of the front-end business, that is, the data screening condition is directly related to the data structure of the queried data object. For example, if the data structure of the queried data object is composed of attribute a, attribute b, attribute c, attribute d, and attribute e, the queried object data can be screened according to a single attribute, such as filtering data within the target range only according to attribute a, or the query object data can be screened according to multiple attributes, such as filtering data whose attribute a meets the first condition and whose attribute b meets the second condition. When two data screening conditions are for the same queried object, and the attribute conditions involved in the two data screening conditions are consistent, and only the range conditions are different, the types of the above two data screening conditions can be regarded as the same type.

[0050] In a specific implementation, the front-end business is a member information statistics business, and the first data screening condition is to screen male member records with an age range of 25-30 years old, and the second data screening condition is to screen female member records with an age range of 20-25 years old. The above two screening conditions are both established based on age and gender attributes. Compared with the two screening conditions, the attributes of the object data are the same, but the ranges under the attributes are different, so they are the same type of data screening conditions. It should be understood that in some possible situations, the data screening conditions are not only related to the attributes of the data itself, but also to the association relationship between the attributes. For ease of understanding, it can be interpreted from the perspective of the database that the above attributes are data attributes, and the above association relationship is the relationship between attributes.

[0051] In the embodiment of the present disclosure, the stored type is the type of data screening condition corresponding to the data query model that has been established and saved. When the type of data screening condition corresponding to the data query instruction is a stored type, the corresponding data query model is directly called, and the corresponding range condition is input to obtain the query result. If the type of the current data screening condition does not belong to the stored type, that is, the data statistical dimension has changed, based on the above content, it can be seen that the corresponding data query tool needs to be redeveloped, so the present disclosure creates a new data query model for configuring and saving the current data screening condition.

[0052] Step S103: when a target query condition is determined based on the current data screening condition, a target Gorm query variable corresponding to the target query condition is obtained from a preset instance model, where the preset instance model is a Gorm instance configured with multiple Gorm query variables.

[0053] In the disclosed embodiment, the query condition is an instruction condition oriented to the program object. The query condition is generated based on the data screening condition and corresponds to the data screening condition. In a specific implementation, taking the financial settlement business as an example, the business content is to obtain the total tax amount generated by XX services, then the data screening condition is to obtain the bills of all XX services and calculate the total tax. The corresponding query condition is to obtain the data record containing the bills of all XX services by connecting to the database, and then find the bill record of XX services from the data record, and then obtain the tax value in each bill record of XX services, and finally calculate the total tax amount to obtain the total tax amount generated by XX services. Based on the above content, it can be seen that the query condition is to convert the data screening condition generated by the business into query function-related code that can be read by the data query model. In the disclosed embodiment, the query condition can be expressed as a plug-in, function, interface, etc. implemented based on Gorm.

[0054] It is worth noting that the present disclosure does not limit the specific generation rules of query conditions. The query conditions can be based on intelligent algorithm recognition evolution, or can be implemented based on special compilation software. In some possible cases, they can also be rules agreed upon by developers.

[0055] In the disclosed embodiment, the preset instance model is a data query instance, which corresponds to at least one specific data screening condition, and generates a query condition based on the at least one specific data screening condition, wherein the query condition can be a basic query condition, such as finding a column, sorting, range restriction, and relationship, or relationship, etc.; the query condition can also be a complex condition consisting of multiple basic query conditions, such as obtaining a target number of records based on a certain column, sorting records according to a target rule based on a certain column, etc. It should be understood that the preset instance model and the newly created data query model are both oriented to the same data object, therefore, the preset instance model should save as many query conditions as possible, and the newly created data query model does not need to write new query conditions, thereby shortening the development time.

[0056] Since the above query conditions are saved and configured into the preset instance model, the newly created data query model cannot directly use the corresponding query conditions. However, the reference (reflection) interface in the go language can obtain the variable information of the preset instance model and reassign it. Therefore, the preset instance model will generate Gorm query variables based on the saved query conditions, and the newly created data query model will copy the corresponding query conditions by obtaining the Gorm query variables.

[0057] Step S104: when a target Gorm query statement is generated based on the target query condition and the target Gorm query variable, a data query model is configured through the Gorm query statement.

[0058] Step S105: Run the data query model to obtain data query results.

[0059] In the disclosed embodiment, the Gorm query variable is a variable generated based on the gorm structure, which corresponds to the query condition in the structure. By obtaining the Gorm query variable, the code writing of a part of the query condition can be reduced, and the obtained Gorm query variable cannot be used directly as a query condition, because the current data screening condition type does not belong to the stored type, that is to say, it is necessary to generate a new target Gorm query statement according to the target query condition and the target Gorm query variable before the data query function corresponding to the current data screening condition can be configured.

[0060] Figure 2 A method for establishing a preset instance model according to an embodiment of the present disclosure is shown. Figure 2 As shown, the method includes:

[0061] Step S201: Establish a blank query model, where the blank query model is used to configure Gorm query variables.

[0062] Step S202: Based on the attribute relationship of the target database, determine the first object, where the first object is a structure variable mapped to the target database, and the target database is a database connected to the blank query model.

[0063] Step S203: When the Gorm query variable corresponding to the first object is determined based on the target database, a blank query model is configured through the query variable corresponding to the first object to obtain a preset instance model.

[0064] In the embodiment of the present disclosure, the preset instance model includes at least one Gorm instance, and the Gorm instance is configured with a Gorm query variable. The reason why the present disclosure adopts the Gorm query variable method for instantiation is that: one Gorm instance corresponds to a specific data screening condition, and the data screening condition will be converted into a specific query condition, and the specific query condition is obtained after logical processing of the basic query condition. In the scenario of implementing the data query function based on Gorm, a Gorm instance will set multiple basic query conditions in a sequential logic, such as group by, order by, limit and other limiting conditions. After the Gorm instance obtains the corresponding query result, the above limiting conditions cannot be reset. If part or all of the above query conditions are converted into Gorm query variables, when using the Gorm query variables for instantiation, the parameters of the saved query conditions are directly sent to the Gorm query variables, and then converted into the corresponding Gorm query statements, which helps to improve the flexibility of the query function.

[0065] Please refer to Figure 3 In the above step S203, before determining the Gorm query variable corresponding to the first object based on the target database, the method for establishing the preset instance model further includes the following steps:

[0066] Step S301: Obtain preset data screening conditions of the target database.

[0067] In the disclosed embodiment, the query condition determined by the data screening condition should be understood as the specific query condition obtained by the basic query condition after a certain logical combination, wherein the basic query condition can be understood as each query interface provided in the Gorm library, and the specific query condition is generated based on one or more of the query interfaces provided in the Gorm library, and the specific query condition can directly correspond to the data screening condition. In the actual application scenario, different businesses have the same pre-steps when performing data screening. Taking the application scenario of financial settlement as an example, financial settlement can include statistical businesses such as monthly bill summary, monthly tax return, and revenue calculation. The statistical dimensions corresponding to the above businesses are different, and each statistical dimension is a specific data screening condition. In the related technology, it is necessary to set the Gorm instance to correspond to each specific data screening condition to realize the above business function. However, although the statistical dimensions of the above businesses are different, there are some common query conditions, such as obtaining all bills within a certain time period, screening according to a certain attribute in the data structure, etc. The logical essence of this part of the query condition is the same, which can be used as a general query condition, and the above preset data screening condition corresponds to the general query condition.

[0068] Step S302: when the query condition of the first object is determined based on the preset data screening condition, the query condition of the first object is configured into the second object, and the second object represents a structure variable that stores the query condition.

[0069] In the embodiment of the present disclosure, the first object is a structure corresponding to the target database, that is, a DB structure. The first object includes at least multiple variables that have a one-to-one correspondence with the attribute relationship of the target database. The first object variable generated based on the first object can establish a mapping connection with one or more data records in the target database to realize a specific query function.

[0070] The second object is a structure for saving query conditions, that is, a search structure. The second object contains multiple parameters, each of which corresponds to a specific query condition. In other words, the present disclosure achieves the purpose of saving query conditions by establishing a structure and using the query conditions as parameters of the structure. Based on the above configuration, the query conditions saved by the second object can be non-fixed conditions. When a Gorm instance needs to use the query conditions in the second object, the structure of the second object is imported as a parameter, and the Gorm instance can selectively import all or part of the query conditions in the first object, thereby improving the flexibility of data query.

[0071] Step S303: Generate a first query function based on the second object, where the first query function includes at least one Gorm query variable, and the at least one Gorm query variable corresponds to the query condition of the first object.

[0072] Since the second object is a structure variable, when the query conditions saved in the second object need to be called, a function needs to be created, namely the first query function mentioned above. The first query function accepts the second object as its parameter, and multiple query conditions are stored in the second object. Multiple Gorm query variables will be generated in the first query function. The Gorm query variables correspond to the query conditions in the second object, and the encapsulated first query function can be directly applied to the Gorm instance, thereby realizing the corresponding query function.

[0073] Please refer to Figure 4 Based on the above-mentioned determination step of the Gorm query variable, in the above-mentioned step S203, a blank query model is configured by the Gorm query variable corresponding to the first object to obtain a preset instance model, which specifically includes the following steps:

[0074] Step S401: Generate a Gorm query instance based on the first object, where the Gorm query instance is used to implement data query on a target database.

[0075] Step S402: configure the first query function into the Gorm query instance.

[0076] Step S403: assign a value to at least one Gorm query variable in the first query function based on a preset data screening condition.

[0077] Based on the above steps, the preset instance model can set at least one Gorm instance to save a specific query function. The present disclosure does not limit the number of Gorm instances included in the preset instance model.

[0078] The above embodiments have explained in detail the method for establishing and configuring the preset instance model. It should be understood that the preset instance model itself is a data query model, which can save and encapsulate query conditions so that other data query models can call and copy the query conditions in the preset instance model.

[0079] Since the current data screening conditions do not belong to the stored conditions, that is, the target query conditions are not completely consistent with the query conditions of the first object, the newly created data query model needs to make a judgment and choose between the copied query conditions. In some application scenarios, the new statistical dimension is based on the final result of the existing statistical dimension. At this time, the newly created data query model needs to obtain all query conditions from the preset instance model. When the new statistical dimension is based on the intermediate result of the existing statistical dimension, the newly created data query model only needs to obtain part of the query conditions from the preset instance model.

[0080] For details, please refer to Figure 5 In the above step S103, the target Gorm query variable corresponding to the target query condition is obtained from the preset instance model, including:

[0081] Step S501: Acquire a second object from a preset instance model.

[0082] Step S502: Acquire common query conditions between the target query condition and the query condition of the first object.

[0083] Step S503: Generate a second query function based on the second object and the common query condition, where the second query function includes a target Gorm query variable, and the target Gorm query variable corresponds to the common query condition.

[0084] In the embodiment of the present disclosure, by comparing the common query conditions between the target query conditions and the query conditions of the first object, the number of query conditions that need to be copied from the preset instance model for the newly created data query model is determined. When the common query conditions do not belong to all query conditions, by creating a new second query function and configuring the target Gorm query variables corresponding to the common query conditions in the second query function, the accuracy of the query function of the newly created data query model can be ensured.

[0085] Based on the above embodiment, further, compared with the preset instance model, when the current data screening condition corresponding to the newly created data query model is a newly added statistical dimension, after copying the existing query condition, it is also necessary to configure the query condition of the newly added statistical dimension into the newly created data query model. For details, please refer to Figure 6 In the above step S104, based on the target query condition and the target Gorm query variable, a target Gorm query statement is generated, including:

[0086] Step S601: assign a value to the target Gorm query variable in the second query function based on the current data screening condition;

[0087] Step S602: establishing a third query function based on the newly added query condition, where the newly added query condition indicates a query condition in the target query condition that does not belong to the common query condition.

[0088] Some embodiments of the present disclosure also provide a data query device based on Gorm, such as Figure 7 As shown, the device comprises:

[0089] The instruction acquisition module 101 is configured to execute a response to a data query instruction and acquire a current data screening condition corresponding to the data query instruction;

[0090] The model generation module 102 is configured to create a new data query model when the type of the current data screening condition does not belong to the stored type;

[0091] The variable acquisition module 103 is configured to execute, when a target query condition is determined based on the current data screening condition, acquiring a target Gorm query variable corresponding to the target query condition from a preset instance model;

[0092] The model configuration module 104 is configured to execute, when a target Gorm query statement is generated based on the target query condition and the target Gorm query variable, configuring the data query model through the target Gorm query statement.

[0093] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0094] The present disclosure also provides a computer-readable storage medium, wherein at least one instruction or at least one program is stored in the computer-readable storage medium, and when the at least one instruction or at least one program is loaded and executed by a processor, the method is implemented. The computer-readable storage medium may be a non-volatile computer-readable storage medium.

[0095] The embodiment of the present disclosure also provides an electronic device, comprising: a processor; a memory for storing processor executable instructions; wherein the processor executable instructions are configured as the method. The electronic device can be provided as a terminal, a server or other forms of devices.

[0096] Figure 8800 is a block diagram of an electronic device according to an embodiment of the present disclosure. For example, the electronic device 800 may be a mobile phone, a computer, a messaging device, a tablet device, a personal digital assistant, or other terminal. Figure 8 , the electronic device 800 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output (I / O) interface 812 , a sensor component 814 , and a communication component 816 .

[0097] The processing component 802 generally controls the overall operation of the electronic device 800, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.

[0098] The memory 804 is configured to store various types of data to support operations on the electronic device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0099] The power supply component 806 provides power to the various components of the electronic device 800. The power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 800.

[0100] The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the electronic device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0101] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the electronic device 800 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.

[0102] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: home button, volume button, start button, and lock button.

[0103] The sensor assembly 814 includes one or more sensors for providing various aspects of status assessment for the electronic device 800. For example, the sensor assembly 814 can detect the open / closed state of the electronic device 800, the relative positioning of the components, such as the display and keypad of the electronic device 800, and the sensor assembly 814 can also detect the position change of the electronic device 800 or a component of the electronic device 800, the presence or absence of contact between the user and the electronic device 800, the orientation or acceleration / deceleration of the electronic device 800, and the temperature change of the electronic device 800. The sensor assembly 814 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 814 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0104] The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 can access a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G, 5G or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 further includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (I rDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0105] In an exemplary embodiment, the electronic device 800 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.

[0106] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 804 including computer program instructions, which can be executed by a processor 820 of an electronic device 800 to perform the above method.

[0107] Fig. 9 1 is a block diagram of another electronic device according to an embodiment of the present disclosure. For example, the electronic device 1900 may be provided as a server. Fig. 9 , the electronic device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions executable by the processing component 1922, such as an application. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.

[0108] The electronic device 1900 may also include a power supply component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input / output (I / O) interface 1958. The electronic device 1900 may operate based on an operating system stored in the memory 1932, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™ or the like.

[0109] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the electronic device 1900 to perform the above method.

[0110] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.

[0111] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: 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), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.

[0112] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0113] The computer program instructions for performing the disclosed operation may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.

[0114] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0115] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0116] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0117] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the above-mentioned module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the standard function in the square box can also occur in a sequence different from the standard in the accompanying drawings. For example, two continuous square boxes 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 square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a special hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.

[0118] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A data query method based on Gorm, characterized in that: include: In response to a data query instruction, obtaining a current data screening condition corresponding to the data query instruction; In the case that the type of the current data screening condition does not belong to the stored type, a new data query model is created, and the data query model is used to configure the Gorm query statement to realize the data query function; When a target query condition is determined based on the current data screening condition, a target Gorm query variable corresponding to the target query condition is obtained from a preset instance model, where the preset instance model is a Gorm instance configured with a plurality of Gorm query variables; In the case where a target Gorm query statement is generated based on the target query condition and the target Gorm query variable, configuring the data query model through the target Gorm query statement; Run the data query model to obtain data query results.

2. The method according to claim 1, characterized in that The preset instance model is obtained based on the following method: Establish a blank query model, where the blank query model is used to configure Gorm query variables; Based on the attribute relationship of the target database, determining a first object, wherein the first object is a structure variable mapped to the target database, and the target database is a database connected to the blank query model; When the Gorm query variable corresponding to the first object is determined based on the target database, the blank query model is configured by the Gorm query variable corresponding to the first object to obtain the preset instance model.

3. The method according to claim 2, characterized in that Before determining the Gorm query variable corresponding to the first object based on the target database, the method further includes: Obtaining preset data screening conditions of the target database; When the query condition of the first object is determined based on the preset data screening condition, the query condition of the first object is configured into a second object, and the second object represents a structure variable storing the query condition; A first query function is generated based on the second object, wherein the first query function includes at least one Gorm query variable, and the at least one Gorm query variable corresponds to a query condition of the first object.

4. The method according to claim 3, characterized in that The configuring the blank query model through the Gorm query variable corresponding to the first object to obtain the preset instance model includes: Based on the first object, generate a Gorm query instance, where the Gorm query instance is used to implement data query on the target database; Configuring the first query function into the Gorm query instance; Based on the preset data screening condition, assign a value to the at least one Gorm query variable in the first query function.

5. The method according to claim 4, characterized in that The step of acquiring a target Gorm query variable corresponding to the target query condition from a preset instance model includes: Acquire the second object from the preset instance model; Acquire the common query conditions between the target query condition and the query condition of the first object; Based on the second object and the common query condition, a second query function is generated, wherein the second query function includes the target Gorm query variable, and the target Gorm query variable corresponds to the common query condition.

6. The method according to claim 5, characterized in that The generating a target Gorm query statement based on the target query condition and the target Gorm query variable includes: Based on the current data screening condition, assign a value to the target Gorm query variable in the second query function; A third query function is established based on a newly added query condition, where the newly added query condition indicates a query condition in the target query condition that does not belong to the common query condition.

7. A data query device based on Gorm, characterized in that: include: An instruction acquisition module is configured to execute a response to a data query instruction and acquire a current data screening condition corresponding to the data query instruction; A model generation module is configured to create a new data query model when the type of the current data screening condition does not belong to the stored type; A variable acquisition module is configured to execute, when a target query condition is determined based on the current data screening condition, acquiring a target Gorm query variable corresponding to the target query condition from a preset instance model; The model configuration module is configured to execute, when a target Gorm query statement is generated based on the target query condition and the target Gorm query variable, configuring the data query model through the target Gorm query statement.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement a Gorm-based data query method as described in any one of claims 1-6.

9. An electronic device, characterized in that: It includes at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the at least one processor implements a Gorm-based data query method as described in any one of claims 1 to 6 by executing the instructions stored in the memory.

10. A computer program product comprising computer instructions, characterized in that: When the computer instructions are executed by the processor, a Gorm-based data query method as described in any one of claims 1 to 6 is implemented.

Citation Information

Cited By

  • Data query method and device

    CN119576990A

  • Data query method and apparatus

    CN119576990B