CN110674205A - Single table query method, device, terminal and readable storage medium - Google Patents

Single table query method, device, terminal and readable storage medium Download PDF

Info

Publication number
CN110674205A
CN110674205A CN201910898540.9A CN201910898540A CN110674205A CN 110674205 A CN110674205 A CN 110674205A CN 201910898540 A CN201910898540 A CN 201910898540A CN 110674205 A CN110674205 A CN 110674205A
Authority
CN
China
Prior art keywords
data table
information
interface
name
slice
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201910898540.9A
Other languages
Chinese (zh)
Other versions
CN110674205B (en
Inventor
智鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Da Jia Ying Information Technology Co Ltd
Original Assignee
Suzhou Da Jia Ying Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Da Jia Ying Information Technology Co Ltd filed Critical Suzhou Da Jia Ying Information Technology Co Ltd
Priority to CN201910898540.9A priority Critical patent/CN110674205B/en
Publication of CN110674205A publication Critical patent/CN110674205A/en
Application granted granted Critical
Publication of CN110674205B publication Critical patent/CN110674205B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2452Query translation
    • G06F16/24528Standardisation; Simplification
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services

Abstract

The embodiment of the invention discloses a single table query method, a single table query device, a terminal and a readable storage medium. The method comprises the following steps: acquiring the information of a request body, a response body, the identification of a server and a general query interface required by single-table query; calling a general query interface, reading information of a data table corresponding to a request body, and splicing the information of the data table into a Structured Query Language (SQL) statement, wherein the data table is stored in the server; and calling a general query interface, filling an execution result of the SQL statement in the database into the object pointer slice according to the response body, and returning the object pointer slice. The embodiment of the invention reduces the workload and time consumption of development and is beneficial to the efficient operation and propulsion of the business operation platform.

Description

Single table query method, device, terminal and readable storage medium
Technical Field
The embodiment of the invention relates to a database technology, in particular to a single table query method, a single table query device, a terminal and a readable storage medium.
Background
In most business operation platforms, the business layer needs to query the data table in the base layer frequently to obtain the data required by the business operation. At present, a base layer provides query services externally in a modern, open-source and efficient Remote Procedure Call (RPC) interface mode proposed by google, and depends on the definition of a proto file. And generating a corresponding intermediate file pb.go through the proto file, finishing the interface realization in the pb.go by the basic layer, and finishing the interface calling by the business layer by the pb.go.
At present, in order to meet the query requirements of various data tables of a service layer, a base layer provides a large number of customized query interfaces which have no universality and increase the development workload; moreover, the function of the query interface is similar, which brings certain trouble to the naming and definition of the interface.
Disclosure of Invention
The embodiment of the invention provides a single table query method, a single table query device, a terminal and a continuous storage medium, so as to reduce the workload and time consumption of single table query.
In a first aspect, an embodiment of the present invention provides a single table lookup method, including:
acquiring identifiers of a request body, a response body and a server required by single table query and information of a universal query interface, wherein the request body comprises a name of an object corresponding to a data table to be queried, a primary key identifier of the data table and an attribute name to be returned, and the response body is an address of an object pointer slice;
calling a general query interface, reading information of a data table corresponding to a request body, and splicing the information of the data table into a Structured Query Language (SQL) statement, wherein the data table is stored in the server;
and calling a general query interface, filling an execution result of the SQL statement in the database into the object pointer slice according to the response body, and returning the object pointer slice.
In a second aspect, an embodiment of the present invention further provides a single table lookup apparatus, including:
the acquisition module is used for acquiring the information of a request body, a response body, the identification of a server and a universal query interface which are required by the single table query, wherein the request body comprises the name of an object corresponding to a data table to be queried, the primary key identification of the data table and the attribute name to be returned, and the response body is the address of an object pointer slice;
the splicing module is used for calling the universal query interface, reading the information of the data table corresponding to the request body, and splicing the information of the data table into a Structured Query Language (SQL) statement, wherein the data table is stored in the server;
and the return module is used for calling the general query interface, filling the execution result of the SQL statement in the database into the object pointer slice according to the response body, and returning the object pointer slice.
In a third aspect, an embodiment of the present invention further provides a terminal, where the terminal includes:
one or more processors;
a memory for storing one or more codes,
when executed by the one or more processors, cause the one or more processors to implement the single table lookup method of any of the embodiments.
In a fourth aspect, the present invention further provides a computer-readable storage medium, on which computer code is stored, and when the computer code is executed by a processor, the single-table lookup method according to any embodiment is implemented.
The embodiment of the invention provides a single table query method based on a universal query interface, which can be realized by the method provided by the embodiment for single table query based on a primary key identifier without independent development, has certain universality, and reduces the development workload and time consumption; according to the embodiment, the single-table query is realized through the universal query interface, a large number of customized query interfaces are converged into the universal query interface, for a caller, the customized query interface does not need to be searched, and only the information of the request body, the response body, the identification of the server and the universal query interface required by the single-table query is needed to be compiled, so that the accurate call can be realized, and the mental burden is reduced.
Drawings
FIG. 1 is a flowchart of a single table lookup method according to an embodiment of the present invention;
FIG. 2 is a flowchart of a single-table lookup method according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a single-table lookup apparatus according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of a terminal according to a fourth embodiment of the present invention;
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of a single table query method according to an embodiment of the present invention, which is applicable to a situation where a single table stored in a base layer is queried through a service layer in a service operation platform. For a mid-sized business operating platform, 50 to 100 data sheets can be stored in the base layer without considering horizontal slicing. In this embodiment, the base layer is located at the server, the service layer is located at the terminal, and the service layer performs query operation on the single table of the server through Remote Procedure Call (RPC). Optionally, in this embodiment, the service end list table is queried by using a gRPC, which is an RPC proposed by google.
The method in this embodiment may be performed by a single table lookup apparatus, which may be formed by software and/or hardware and is generally integrated in a terminal. With reference to fig. 1, the single-table lookup method provided in the embodiment of the present invention specifically includes the following operations:
s110, acquiring the information of the request body, the response body, the identification of the server and the universal query interface required by the single-table query.
The business layer provides a programming interface facing to a caller, and the caller inputs a request body, a response body, the identification of a service end and a general query interface required by single-table query in the programming interface. The following is a corresponding code example:
Figure BDA0002211070400000041
the following describes the four elements of the acquisition in detail with reference to a code example. The requesting body (i.e. req) includes the name (i.e. "Sp") of the object corresponding to the data table to be queried, the primary key identifier (i.e. "1") of the data table, and the attribute name (i.e. "SpFullName", SpShortName ") to be returned. The primary key identification of the data table is used for uniquely identifying the primary key, such as the serial number of the primary key, the name of the primary key and the like; the number of primary keys may be 1, or more than 2, i.e. constitute a set of primary keys. The attribute names to be returned may include at least one, separated by commas.
The responder is the address of the object pointer slice (i.e., the address of common dao.
The identification of the server includes, but is not limited to, a unique identification such as an address of the server, a name and a number of the server. And (5) identification of the server. Under the scene of adopting the gRPC, the address of the gRPC service end is packaged in the gRPC service frame.
The information of the universal query interface may be a universal query interface name, which is obtained by concatenating a character string of the universal query interface (i.e., FindById) and a service name of the microservice (i.e., sp _ basic _ impl).
And S120, calling a general query interface, reading the information of the data table corresponding to the request body, and splicing the information of the data table into an SQL statement, wherein the data table is stored in the server.
Initializing and executing the codes to realize the calling of the universal query interface.
The method for realizing the universal query interface comprises the following steps of: reading the information of the data table corresponding to the request body, and splicing the information of the data table into an SQL statement; and according to the response body, filling the execution result of the SQL statement in the database into the object pointer slice, and returning the object pointer slice.
Based on the method, when the universal query interface is called, the information of the data table corresponding to the request body can be read, the information of the data table is spliced into the SQL statement, the execution result of the SQL statement in the database is filled into the object pointer slice according to the response body, and the object pointer slice is returned.
The server side in which the data table is stored can be determined through the identification of the server side.
In this embodiment, the query on the data table includes two aspects: from which data sheet the data source came; which attributes in the data table are obtained. The name of the object has a one-to-one correspondence relationship with the data table, and identifies the data table from which the data source comes. The primary key identification of the data table and the name of the attribute to be returned together identify which attributes in the data table. Thus, the requester can accurately lock the contents of the data table that needs to be queried.
And S130, calling a general query interface, filling the execution result of the SQL statement in the database into the object pointer slice according to the response body, and returning the object pointer slice.
The information of the data table is a scattered field and cannot be recognized and executed by the database. Therefore, it is necessary to splice information of a data table into a Structured Query Language (SQL) statement, such as select a (attribute name) from B (data table name) where C (main key field)? . And then, transmitting the SQL statement to a database so that the database executes the SQL statement in a data table to obtain an execution result. Since the execution result of the query operation by the current standard database is recorded by rows, that is, the execution result is placed in rows. Therefore, the execution result in rows needs to be extracted and filled in the Object pointer slice by the Object Relational Mapping (ORM) known three-party library (gorm) of the go language.
Wherein the filled address needs to be determined according to the responder. The responder in this embodiment is an address of an object pointer slice, and is used for protobuf deserialization in a service framework. Accordingly, the execution result (byte sequence) in rows is filled in the object pointer slice by gorm according to the address of the object pointer slice, and the object type is generated.
For callers, similar to ordinary function calls, RPC calls also require a function return value. This embodiment returns the object pointer slice filled with the execution results. And at this point, the single-table query is realized by calling the universal query interface.
The embodiment of the invention provides a single table query method based on a universal query interface, which can be realized by the method provided by the embodiment for single table query based on a primary key identifier without independent development, has certain universality, and reduces the development workload and time consumption; according to the embodiment, the single-table query is realized through the universal query interface, a large number of customized query interfaces are converged into the universal query interface, for a caller, the customized query interface does not need to be searched, and only the information of the request body, the response body, the identification of the server and the universal query interface required by the single-table query is needed to be compiled, so that the accurate call can be realized, and the mental burden is reduced.
Example two
Fig. 2 is a flowchart of a single-table lookup method according to a second embodiment of the present invention. The present embodiment is further optimized on the basis of various optional implementation manners of the above-described embodiment. When the code is initialized, the information of the data table is stored into the local storage space through reflection; and subsequently, only the information corresponding to the request body needs to be read from the local storage space, reflection is not needed in the operation process, and performance loss is avoided.
The present embodiment also includes a series of pre-preparation before initializing and running the code.
The first step is as follows: an abstract interface is defined. The method for packaging the abstract interface comprises the following steps: and transmitting the object pointer slice to an ORM frame, and loading the information of the data table in the server side through reflection by the ORM frame. Further, the method for encapsulating the abstract interface further comprises the following steps: in RPC as return structure is used directly. The following is an example of code that defines an abstract interface:
Figure BDA0002211070400000071
the abstract interface is named GormSlice, and proto.message can be directly used as a return structure of RPC (such as gRPC). Since the return body of the gRPC only recognizes one structure, it is the object pointer that implements the proto. Therefore, proto.message can be used directly as a return structure of the gRPC, and GormSlice that implements the proto.message interface can also be used directly as a return structure of the gRPC.
The GetSlice () is a self-defined abstract interface, and the implementation of the GetSlice () is that an object pointer slice is transmitted to the ORM frame of gorm in a mode of generating a template code by the code, so that the ORM frame loads the information of the data table in the server side by reflection, and the universality is realized.
The second step is that: and generating an object and an object pointer slice corresponding to the data table. Specifically, proto structure common dao. It can be seen that the object is proto-structured, since this object itself is also used as a return structure for the gRPC.
The following is a corresponding code example:
Figure BDA0002211070400000081
where Sp is the structure (or object) corresponding to the Sp data table, and SpSlice is the pointer slice of the Sp object. The tag (tag) portion in the code example above corresponds to a table in the database, and Sp is the object corresponding to this table.
The third step: and generating a go file of the object. Specifically, go file commondao.
Figure BDA0002211070400000091
The gorm tag part in the code is that PbGenerator writes a comment when generating a proto structure (i.e. an object) by scanning the structure of a data table, and generates the comment in the form of tag when generating pb. go by protoc. It can be seen that the go file comprises a structure of the object (Sp) and a structure of the object pointer slice (SpSlice). The object pointer slice is originally defined by proto message, so that the object pointer slice in the go file generated by proto naturally realizes a proto message interface, that is, the object pointer slice in the go file realizes a method directly used as a return structure in RPC.
The fourth step: and transmitting the object pointer slice in the go file to an ORM frame by a mode of generating a template code by the code, and loading the information of the data table in the server side by the ORM frame through reflection.
The following is a template code example:
Figure BDA0002211070400000101
here the object pointer slice implements the GetSlice method and, since it naturally implements the proto.message interface, the object pointer slice implements the abstract interface GormSlice defined above.
The object pointer slice at this time has three capabilities: data can be manipulated in an object manner by gorm; can be directly used as a return structure in gRPC; the multiple modes are realized through a GormSlice interface, and the universality of codes is realized.
Now that the preliminary preparation work has been completed, we begin to describe how to use these preliminary preparations to perform the general single-form look-up function.
Specifically, the method illustrated in fig. 2 specifically includes the following operations:
and S210, predefining the mapping relation between the name of the object and the abstract interface.
The name of the object is substantially a character string of the object name, and the caller only recognizes the character string and does not need to know the corresponding data table. The following is a corresponding code example:
Figure BDA0002211070400000102
in the above code, the abstract interface name is GormSlice, "Sp" is the name of the object, and & commonodao.
And S220, when the code is initialized, calling the abstract interface to load the information of the data table in the server according to the mapping relation between the name of the object and the abstract interface, and storing the information of the data table in a local storage space.
Because the abstract interface realizes the GetSlice method, the information of the data table corresponding to the abstract interface loading object can be called by loading the information of the data table in the server through reflection.
Specifically, when code initialization is carried out, according to the mapping relation between the name of the object and an abstract interface, calling the abstract interface to read an ORM tag (such as gorm tag) from the go file; reflecting the ORM label to obtain the information of the data table; the ORM tag is written with a comment when an object is generated by scanning the structure of the data table, and the comment is generated in the form of a tag when a go file is generated.
After loading the information of the data table, storing the information of the data table to a local storage space. The local storage space may be a memory cache or a disk cache. The following is a corresponding code example:
Figure BDA0002211070400000121
in the above code, "COLUMN" is the gorm tag of the Sp object and is obtained by scanning the data sheet. The code realizes the information obtained by reflecting and loading the scanning data table, and the loaded information is sequentially written into the cache.
And S230, acquiring the information of the request body, the response body, the identification of the server and the universal query interface required by the single-table query.
Optionally, a definition request body is further included before S230, and the generic query interface is defined and implemented.
Specifically, the request body comprises the name of the object, the primary key identification of the data table to be queried and the attribute name to be returned. The following is a corresponding code example:
Figure BDA0002211070400000122
where dao denotes the name of the object to be queried, id denotes the primary key id of the data table to be queried, fields denotes the set of attributes to be returned, and the set of attributes is a comma-separated character string (such as "SpFullName,
SpShortName”)。
the method for encapsulating the universal query interface comprises the following steps: reading the information of the data table corresponding to the request body, and splicing the information of the data table into an SQL statement; and according to the response body, filling the execution result of the SQL statement in the database into the object pointer slice, and returning the object pointer slice. The following are corresponding code and annotation examples:
in the above code, FindById is the name of the universal query interface, and gormInfo, err ═ gormtil. The subsequent codes sequentially realize the process of reading the mapping relation between the attribute names and the field names, the data table names and the main key fields corresponding to the request bodies from the local cache space.
It should be noted that the core of the above code lies in the use of an abstract interface (GormSlice), and the mapping relationship between the attribute name and the field name, the primary key field and the data table name are first taken from the local storage space by Dao in the request body, so that the concatenation of SQL can be completed by gorm. Furthermore, a pointer of common dao.spslice { } is obtained, and since the pointer implements the GetSlice () method, the pointer slice [ ] × Sp { } of the Sp object is imported into db.scan (), and the gorm can complete the filling of the database operation result from rows to [ ] × Sp { }. Finally, the gorginfo. gormslice returns a proto. message interface. The SpSlice itself is generated by the messageSpSlice, which naturally implements the proto. That is, what the present embodiment actually returns is the object pointer slice of the SpSlice filled with the execution result.
When the gRPC returns the SpSlice code, the advantages of protobuf high-efficiency and quick coding and decoding and the like can be used, and one gRPC call is completed without multiple gRPC calls.
In some cases, the generic single-table lookup interface is named FindByIds, and the specific definition and implementation are substantially the same as FindById, and are not described here again.
And S240, calling a general query interface, and reading the information of the data table corresponding to the request body from the local storage space.
Optionally, the information of the data table includes at least one of a mapping relationship of an attribute name and a field name, a primary key field, and a data table name. Accordingly, in connection with the definition and implementation code of the universal query interface (FindById), the present operations include at least one of:
calling a universal query interface, and reading the corresponding relation between the attribute name and the field name from the local storage space according to the attribute name in the request body; calling a universal query interface, and reading a data table name corresponding to the name of the object from the local storage space according to the name of the object in the request body; and calling a general query interface, and reading a main key field corresponding to the main key identification from the local storage space according to the main key identification of the data table in the request body. Wherein the primary key field is obtained by reflecting the ORM tag.
And S250, splicing the information of the data table into a Structured Query Language (SQL) statement.
And S260, calling a general query interface, filling an execution result of the SQL statement in the database into the object pointer slice according to the response body, and returning the object pointer slice.
In the embodiment, when the code is initialized, the information of the data table is stored into the local storage space through reflection; the information corresponding to the request body is only needed to be read from the local storage space subsequently, reflection is not needed in the operation process, and performance loss is avoided; by maintaining the mapping relation between the names of the objects and the abstract interfaces, a large number of customized query interfaces can be converged into a universal single-table query interface without additional function development; by setting the abstract interface, the generalization of single-table query is realized, and the defects of poor maintainability and inconvenient use caused by frequent code copying are avoided.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a single-table query device according to a third embodiment of the present invention, where this embodiment is applicable to a case where a single table stored in a base layer is queried through a service layer in a service operation platform. With reference to fig. 3, the apparatus comprises: an acquisition module 31, a stitching module 32 and a return module 33.
An obtaining module 31, configured to obtain information of a request entity, a response entity, an identifier of a server and a general query interface, which are required by a single table query;
the splicing module 32 is configured to invoke a general query interface, read information of a data table corresponding to the request body, and splice the information of the data table into a Structured Query Language (SQL) statement, where the data table is stored in the server;
and the returning module 33 is configured to invoke the general query interface, fill the execution result of the SQL statement in the database into the object pointer slice according to the response body, and return the object pointer slice.
The embodiment of the invention provides a single table query method based on a universal query interface, which can be realized by the method provided by the embodiment for single table query based on a primary key identifier without independent development, has certain universality, and reduces the development workload and time consumption; according to the embodiment, the single-table query is realized through the universal query interface, a large number of customized query interfaces are converged into the universal query interface, for a caller, the customized query interface does not need to be searched, and only the information of the request body, the response body, the identification of the server and the universal query interface required by the single-table query is needed to be compiled, so that the accurate call can be realized, and the mental burden is reduced.
Optionally, the request body includes a name of an object corresponding to the data table to be queried, a primary key identifier of the data table and an attribute name to be returned, and the response body is an address of the object pointer slice.
Optionally, the apparatus further comprises a pre-defining module and an initializing module. The method for encapsulating the abstract interface comprises the following steps that a pre-defining module is used for pre-defining the mapping relation between the name of an object and the abstract interface before calling a general query interface and reading the information of a data table corresponding to a request body, and the method for encapsulating the abstract interface comprises the following steps: and transmitting the object pointer slice to an Object Relational Mapping (ORM) framework, and loading the information of the data table in the server side through reflection by the ORM framework. The initialization module is used for calling the information of the data table in the abstract interface loading server according to the mapping relation between the name of the object and the abstract interface when the code is initialized, and storing the information of the data table in a local storage space.
Optionally, the splicing module 32 is specifically configured to invoke the general query interface and read the information of the data table corresponding to the request entity from the local storage space when invoking the general query interface and reading the information of the data table corresponding to the request entity.
Optionally, the information of the data table includes at least one of a mapping relationship of an attribute name and a field name, a primary key field, and a data table name. Accordingly, when the splicing module 32 calls the general query interface and reads the information of the data table corresponding to the request body from the local storage space, it is specifically configured to perform at least one of the following operations: calling a universal query interface, and reading the corresponding relation between the attribute name and the field name from the local storage space according to the attribute name in the request body; calling a universal query interface, and reading a data table name corresponding to the name of the object from the local storage space according to the name of the object in the request body; and calling a general query interface, and reading a main key field corresponding to the main key identification from the local storage space according to the main key identification of the data table in the request body.
Optionally, the apparatus further includes an abstract interface implementation module, configured to define an abstract interface before the predefining a mapping relationship between the name of the object and the abstract interface, where the method for encapsulating the abstract interface further includes: directly using the RPC as a return structure in Remote Procedure Call (RPC); generating an object and an object pointer slice corresponding to the data table; generating a go file of the object, wherein the go file comprises a structure of the object and a structure of the object pointer slice, and the object pointer slice in the go file realizes a method directly used as a return structure in RPC; and transmitting the object pointer slice in the go file to an Object Relational Mapping (ORM) framework by a mode of generating a template code by the code, and loading the information of the data table in the server side by the ORM framework through reflection.
Optionally, when the initialization module calls the information of the data table in the abstract interface loading server according to the mapping relationship between the name of the object and the abstract interface during code initialization, the initialization module is specifically configured to: when code initialization is carried out, calling the abstract interface to read an ORM tag from the go file according to the mapping relation between the name of the object and the abstract interface; reflecting the ORM label to obtain the information of the data table; the ORM tag is written with a comment when an object is generated by scanning the structure of the data table, and the comment is generated in the form of a tag when a go file is generated.
Optionally, the apparatus further comprises: the request body definition module is used for defining a request body before acquiring the request body, a response body, a server and a universal query interface which are required by the single-table query; the request body comprises the name of the object, the primary key identification of the data table to be inquired and the attribute name to be returned.
Optionally, the apparatus further comprises: a general query interface defining and realizing module, configured to define the general query interface before a request body, a response body, a server and a general query interface that are required by the acquisition form query; implementing the generic query interface; the method for encapsulating the universal query interface comprises the following steps: reading the information of the data table corresponding to the request body, and splicing the information of the data table into an SQL statement; and according to the response body, filling the execution result of the SQL statement in the database into the object pointer slice, and returning the object pointer slice.
The single table query device provided by the embodiment of the invention can execute the single table query method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
Example four
Fig. 4 is a schematic structural diagram of a terminal according to a fourth embodiment of the present invention, as shown in fig. 4, the terminal includes a processor 40, a memory 41, an input device 42, and an output device 43; the number of the processors 40 in the terminal may be one or more, and one processor 40 is taken as an example in fig. 4; the processor 40, the memory 41, the input device 42 and the output device 43 in the terminal may be connected by a bus or other means, as exemplified by the bus connection in fig. 4.
The memory 41 is a computer-readable storage medium, and can be used for storing software codes, computer-executable codes, and modules, such as code instructions/modules corresponding to the single-table lookup method in the embodiment of the present invention (for example, the obtaining module 31, the splicing module 32, and the returning module 33 in the single-table lookup apparatus). The processor 40 executes various functional applications of the terminal and data processing, i.e., implements the above-described single table lookup method, by executing software codes, instructions, and modules stored in the memory 41.
The memory 41 may mainly include a storage code area and a storage data area, wherein the storage code area may store an operating system, application code required for at least one function; the storage data area may store data created according to the use of the terminal, and the like. Further, the memory 41 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, memory 41 may further include memory located remotely from processor 40, which may be connected to the terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
Input device 42 may be used to input caller-written code. The output means 43 comprises an output interface for outputting the object pointer slice.
EXAMPLE five
An embodiment of the present invention also provides a computer-readable storage medium having stored thereon computer code, which when executed by a computer processor is configured to perform a method of single table lookup, the method comprising:
acquiring the information of a request body, a response body, the identification of a server and a general query interface required by single-table query;
calling a general query interface, reading information of a data table corresponding to a request body, and splicing the information of the data table into a Structured Query Language (SQL) statement, wherein the data table is stored in the server;
and calling a general query interface, filling an execution result of the SQL statement in the database into the object pointer slice according to the response body, and returning the object pointer slice.
Of course, the computer code of the computer-readable storage medium stored with the computer code according to the embodiment of the present invention is not limited to the method operations described above, and may also perform related operations in the single-table lookup method according to any embodiment of the present invention.
From the above description of the embodiments, it is obvious for those skilled in the art that the present invention can be implemented by software and necessary general hardware, and certainly, can also be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods according to the embodiments of the present invention.
It should be noted that, in the embodiment of the single-table lookup apparatus, the included units and modules are merely divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (12)

1. A method for single table lookup, comprising:
acquiring the information of a request body, a response body, the identification of a server and a general query interface required by single-table query;
calling a general query interface, reading information of a data table corresponding to a request body, and splicing the information of the data table into a Structured Query Language (SQL) statement, wherein the data table is stored in the server;
and calling a general query interface, filling an execution result of the SQL statement in the database into the object pointer slice according to the response body, and returning the object pointer slice.
2. The method of claim 1, wherein the request body comprises a name of an object corresponding to the data table to be queried, a primary key identifier of the data table and an attribute name to be returned, and the response body is an address of an object pointer slice.
3. The method according to claim 1, before said invoking the universal query interface to read information of the data table corresponding to the requestor, further comprising:
predefining a mapping relation between the name of the object and an abstract interface, wherein the abstract interface packaging method comprises the following steps: and transmitting the object pointer slice to an Object Relational Mapping (ORM) framework, and loading the information of the data table in the server side through reflection by the ORM framework.
4. The method according to claim 3, before said invoking the universal query interface to read information of the data table corresponding to the requestor, further comprising:
when a code is initialized, calling the abstract interface to load the information of the data table in a server according to the mapping relation between the name of the object and the abstract interface, and storing the information of the data table in a local storage space;
correspondingly, the invoking the universal query interface, reading information of the data table corresponding to the request body, including:
and calling a general query interface, and reading the information of the data table corresponding to the request body from the local storage space.
5. The method according to claim 4, wherein the information of the data table comprises at least one of a mapping relationship of an attribute name and a field name, a primary key field, and a data table name;
correspondingly, the invoking the universal query interface to read the information of the data table corresponding to the request body from the local storage space includes at least one of the following operations:
calling a universal query interface, and reading the corresponding relation between the attribute name and the field name from the local storage space according to the attribute name in the request body;
calling a universal query interface, and reading a data table name corresponding to the name of the object from the local storage space according to the name of the object in the request body;
and calling a general query interface, and reading a main key field corresponding to the main key identification from the local storage space according to the main key identification of the data table in the request body.
6. The method of claim 4, further comprising, before the predefining the mapping relationship between the name of the object and the abstract interface:
defining an abstract interface, the method of abstract interface encapsulation further comprising: directly using the RPC as a return structure in Remote Procedure Call (RPC);
generating an object and an object pointer slice corresponding to the data table;
generating a go file of the object, wherein the go file comprises a structure of the object and a structure of the object pointer slice, and the object pointer slice in the go file realizes a method directly used as a return structure in RPC;
and transmitting the object pointer slice to the ORM frame by the object pointer slice in the go file in a mode of generating a template code by the code, and loading the information of the data table in the server side by the ORM frame through reflection.
7. The method according to claim 6, wherein when the code is initialized, calling the abstract interface to load information of the data table in the server according to a mapping relationship between a name of the object and the abstract interface includes:
when code initialization is carried out, calling the abstract interface to read an ORM tag from the go file according to the mapping relation between the name of the object and the abstract interface;
reflecting the ORM label to obtain the information of the data table;
the ORM tag is written with a comment when an object is generated by scanning the structure of the data table, and the comment is generated in the form of a tag when a go file is generated.
8. The method according to any one of claims 1-7, wherein before the requester, responder, server and general query interface required for obtaining the single table query, further comprising:
defining a request body;
the request body comprises the name of the object, the primary key identification of the data table to be inquired and the attribute name to be returned.
9. The method according to any one of claims 1-7, wherein before the requester, responder, server and general query interface required for obtaining the single table query, further comprising:
defining the universal query interface;
implementing the generic query interface;
the method for encapsulating the universal query interface comprises the following steps: reading the information of the data table corresponding to the request body, and splicing the information of the data table into an SQL statement; and according to the response body, filling the execution result of the SQL statement in the database into the object pointer slice, and returning the object pointer slice.
10. A single table lookup apparatus, comprising:
the acquisition module is used for acquiring the information of the request body, the response body, the identification of the server and the universal query interface required by the single-table query;
the splicing module is used for calling the universal query interface, reading the information of the data table corresponding to the request body, and splicing the information of the data table into a Structured Query Language (SQL) statement, wherein the data table is stored in the server;
and the return module is used for calling the general query interface, filling the execution result of the SQL statement in the database into the object pointer slice according to the response body, and returning the object pointer slice.
11. A terminal, characterized in that the terminal comprises:
one or more processors;
a memory to store one or more codes;
when executed by the one or more processors, cause the one or more processors to implement the single table lookup method of any one of claims 1-9.
12. A computer readable storage medium having stored thereon computer code, wherein the code when executed by a processor implements a single table lookup method as claimed in any one of claims 1 to 9.
CN201910898540.9A 2019-09-23 2019-09-23 Single table query method, device, terminal and readable storage medium Active CN110674205B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910898540.9A CN110674205B (en) 2019-09-23 2019-09-23 Single table query method, device, terminal and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910898540.9A CN110674205B (en) 2019-09-23 2019-09-23 Single table query method, device, terminal and readable storage medium

Publications (2)

Publication Number Publication Date
CN110674205A true CN110674205A (en) 2020-01-10
CN110674205B CN110674205B (en) 2022-07-26

Family

ID=69077554

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910898540.9A Active CN110674205B (en) 2019-09-23 2019-09-23 Single table query method, device, terminal and readable storage medium

Country Status (1)

Country Link
CN (1) CN110674205B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111752602A (en) * 2020-06-28 2020-10-09 上海莉莉丝科技股份有限公司 Method for generating protobuf file running in GO language
CN112667663A (en) * 2020-12-28 2021-04-16 北京明略软件系统有限公司 Data query method and system
CN115481137A (en) * 2022-09-21 2022-12-16 深圳市沃享科技有限公司 Software generation method, device, equipment and medium based on SQL (structured query language) statement

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130054630A1 (en) * 2011-08-30 2013-02-28 International Business Machines Corporation Pre-generation of structured query language (sql) from application programming interface (api) defined query systems
US20140188916A1 (en) * 2013-01-03 2014-07-03 Sap Ag Combining odata and bpmn for a business process visibility resource model
CN104536963A (en) * 2014-11-13 2015-04-22 中国建设银行股份有限公司 A dispatching method and system during storing process
CN109522139A (en) * 2018-11-23 2019-03-26 杭州数梦工场科技有限公司 A kind of tables of data service creation call method, device, equipment and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130054630A1 (en) * 2011-08-30 2013-02-28 International Business Machines Corporation Pre-generation of structured query language (sql) from application programming interface (api) defined query systems
US20140188916A1 (en) * 2013-01-03 2014-07-03 Sap Ag Combining odata and bpmn for a business process visibility resource model
CN104536963A (en) * 2014-11-13 2015-04-22 中国建设银行股份有限公司 A dispatching method and system during storing process
CN109522139A (en) * 2018-11-23 2019-03-26 杭州数梦工场科技有限公司 A kind of tables of data service creation call method, device, equipment and storage medium

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111752602A (en) * 2020-06-28 2020-10-09 上海莉莉丝科技股份有限公司 Method for generating protobuf file running in GO language
CN111752602B (en) * 2020-06-28 2024-02-20 上海莉莉丝科技股份有限公司 Method for generating protobuf file running in GO language
CN112667663A (en) * 2020-12-28 2021-04-16 北京明略软件系统有限公司 Data query method and system
CN115481137A (en) * 2022-09-21 2022-12-16 深圳市沃享科技有限公司 Software generation method, device, equipment and medium based on SQL (structured query language) statement
CN115481137B (en) * 2022-09-21 2023-10-31 深圳市沃享科技有限公司 SQL statement-based software generation method, device, equipment and medium

Also Published As

Publication number Publication date
CN110674205B (en) 2022-07-26

Similar Documents

Publication Publication Date Title
WO2016192556A1 (en) Interface invoking method, device and terminal
CN110674205B (en) Single table query method, device, terminal and readable storage medium
CN110647316B (en) Method and device for generating universal business object, computer equipment and storage medium
CN110351325B (en) Data processing method and related equipment
CN111400246B (en) Asynchronous file import method, device, computer equipment and storage medium
CN111324619B (en) Object updating method, device, equipment and storage medium in micro-service system
CN111367635B (en) Application interface implementation method, device, equipment and medium in host platform layer
CN116737127A (en) Low code development method, device, equipment and storage medium
CN110109983B (en) Method and device for operating Redis database
CN116521181B (en) Script data processing method, device, equipment and medium based on game system
CN111324395B (en) Calling method, device and computer readable storage medium
CN110457013B (en) Program component configuration device and method
CN110633162B (en) Remote call implementation method and device, computer equipment and storage medium
CN109597825B (en) Rule engine calling method, device, equipment and computer readable storage medium
US11016830B2 (en) Entity-based service operation for object-based persistence
CN112783915A (en) Data transmission object mapping method and unit based on SpringMVC + Mybatis framework
US20220374423A1 (en) Running method and device for stored procedure, database system and storage medium
CN111221860A (en) Mixed query optimization method and device based on big data
CN111221841A (en) Real-time processing method and device based on big data
CN112398870B (en) Cross-platform protocol generation method, device, system, equipment and storage medium
KR102600321B1 (en) Methods, devices, facilities and media for implementing application interfaces at the host platform layer
CN111309319B (en) Inheritable office data dynamic page configuration method and device
CN113626001A (en) API dynamic editing method and device based on script
CN114238407A (en) Pre-compiling method and system based on sub-library and sub-table middleware
CN116186022A (en) Form processing method, form processing device, distributed form system and computer storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant