CN116414898A - Database access method and device, electronic equipment and storage medium - Google Patents

Database access method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN116414898A
CN116414898A CN202310248576.9A CN202310248576A CN116414898A CN 116414898 A CN116414898 A CN 116414898A CN 202310248576 A CN202310248576 A CN 202310248576A CN 116414898 A CN116414898 A CN 116414898A
Authority
CN
China
Prior art keywords
database
target
query
database access
identifier
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.)
Pending
Application number
CN202310248576.9A
Other languages
Chinese (zh)
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.)
Lianlian Hangzhou Information Technology Co ltd
Original Assignee
Lianlian Hangzhou 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 Lianlian Hangzhou Information Technology Co ltd filed Critical Lianlian Hangzhou Information Technology Co ltd
Priority to CN202310248576.9A priority Critical patent/CN116414898A/en
Publication of CN116414898A publication Critical patent/CN116414898A/en
Pending legal-status Critical Current

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/242Query formulation
    • G06F16/2433Query languages
    • 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
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application discloses a database access method, a device, electronic equipment and a storage medium, wherein the database access method can be applied to the technical field of databases, and comprises the following steps: receiving a current user request based on a user access interface; the user access interface corresponds to a plurality of database access interfaces; each database access interface corresponds to a plurality of query sentences; the multiple query sentences corresponding to each database access interface respectively correspond to different access operation types; determining a database access interface corresponding to the current user request from the plurality of database access interfaces to obtain a target database access interface; determining a query statement matched with the current user request in a plurality of query statements corresponding to the target database access interface to obtain a target query statement; and executing the target query statement. The method and the device can realize differential access of the heterogeneous database.

Description

Database access method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of database technologies, and in particular, to a method and apparatus for accessing a database, an electronic device, and a storage medium.
Background
In software development, the software is generally configured based on related files, so that the software can smoothly interact with database software, thereby completing related business functions. However, in the prior art, the mapping relationship between the access interface and the database is configured only in the configuration file, the relationship is single, but the grammar of the query statement of the heterogeneous database is different from the grammar of the common databases, such as Oracle, SQLServer, DB and MongoDB, mySQL, and the common databases are different from each other, and incompatible SQL grammar exists between the common databases, so that the query statement corresponding to the same access operation of the heterogeneous database may be different, and the query statement under the same access interface may not be uniformly applicable between the heterogeneous databases, so that according to the prior art, the user cannot access the heterogeneous database by using different query statements based on the same access interface.
Disclosure of Invention
In order to solve the problems in the prior art, embodiments of the present application provide a database access method, a database access device, an electronic device, and a storage medium. The technical scheme is as follows:
in one aspect, a database access method is provided, the method including:
Receiving a current user request based on a user access interface; the user access interface corresponds to a plurality of database access interfaces; each database access interface corresponds to a plurality of query sentences; the multiple query sentences corresponding to each database access interface respectively correspond to different access operation types;
determining a database access interface corresponding to the current user request from the plurality of database access interfaces to obtain a target database access interface;
determining a query statement matched with the current user request in a plurality of query statements corresponding to the target database access interface to obtain a target query statement;
and executing the target query statement.
In another aspect, there is provided a database access apparatus, the apparatus comprising:
the request receiving module is used for receiving a current user request based on the user access interface; the user access interface corresponds to a plurality of database access interfaces; each database access interface corresponds to a plurality of query sentences; the multiple query sentences corresponding to each database access interface respectively correspond to different access operation types;
the interface determining module is used for determining a database access interface corresponding to the current user request from the plurality of database access interfaces to obtain a target database access interface;
The statement determining module is used for determining a query statement matched with the current user request in a plurality of query statements corresponding to the target database access interface to obtain a target query statement;
statement execution module for executing the target query statement
In an exemplary embodiment, the current user request includes a target database identification; the interface determining module includes:
the first relation acquisition module is used for acquiring an interface mapping relation table; the interface mapping relation table comprises a plurality of interface mapping relations; each interface mapping relation characterizes the corresponding relation between the database identifier and the database access interface identifier;
the first identification determining module is used for determining a database access interface identification corresponding to the target database identification based on the interface mapping relation table to obtain a target interface identification;
and the first target determining module is used for determining the database access interface indicated by the target interface identifier in the plurality of database access interfaces to obtain the target database access interface.
In an exemplary embodiment, the current user request includes a further target data characteristic and a current access operation type; the statement determination module includes:
The second relation acquisition module is used for acquiring a statement mapping relation table corresponding to the target database access interface; the statement mapping relation table comprises a plurality of statement mapping relations; each statement mapping relation characterizes the corresponding relation between the access operation type and the query statement identification;
the second identification determining module is used for determining the query statement identification corresponding to the current access operation type based on the statement mapping relation table to obtain a target statement identification;
the second target determining module is used for determining the query statement indicated by the target statement mark in a plurality of query statements corresponding to the target database access interface to obtain an initial query statement;
and the statement generation module is used for generating the target query statement based on the initial query statement and the target data characteristic.
In an exemplary embodiment, the sentence execution module includes:
the operation extraction module is used for extracting the current access operation for the target query statement;
the data determining module is used for traversing the database indicated by the target database identifier and determining the data matched with the target data characteristics as target data;
And the operation execution module is used for executing the current access operation on the target data.
In an exemplary embodiment, the apparatus further includes an interface construction module for constructing a user-oriented database access interface, the interface construction module including:
the identification acquisition module is used for acquiring a plurality of database identifications;
the sentence acquisition module is used for acquiring a plurality of inquiry sentences corresponding to each database identifier for each database identifier to obtain a plurality of inquiry sentences corresponding to each database identifier;
the first interface generation module is used for generating a database access interface corresponding to each database identifier based on a plurality of query sentences corresponding to the database identifiers to obtain the plurality of database access interfaces;
and the second interface generation module is used for generating the user access interface based on the plurality of database access interfaces so that the user access interface responds to the user request to access the database.
In an exemplary embodiment, the sentence acquisition module includes:
the third relation acquisition module is used for acquiring a file mapping relation table; the file mapping relation table comprises a plurality of file mapping relations; each file mapping relation characterizes the corresponding relation between the database identifier and the query statement configuration file identifier; the query statement configuration file indicated by the query statement configuration file identification comprises the plurality of query statements;
The third identification determining module is used for determining the query statement configuration file identifications corresponding to the database identifications based on the file mapping relation table for each database identification to obtain the query statement configuration file identifications corresponding to each database identification;
the file determining module is used for determining the query statement configuration files indicated by the query statement configuration file identifiers corresponding to the database identifiers to obtain query statement configuration files corresponding to each database identifier;
the sentence extraction module is used for extracting the plurality of query sentences in the query sentence configuration file corresponding to the database identifiers to obtain a plurality of query sentences corresponding to each database identifier.
In another aspect, an electronic device is provided that includes a processor and a memory having at least one instruction or at least one program stored therein, the at least one instruction or the at least one program loaded and executed by the processor to implement the database access method of any of the above aspects.
In another aspect, a computer readable storage medium having stored therein at least one instruction or at least one program loaded and executed by a processor to implement a database access method according to any of the above aspects is provided.
In another aspect, a computer program product or computer program is provided, the computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the electronic device reads the computer instructions from the computer readable storage medium and executes the computer instructions to cause the electronic device to perform the database access method of any of the aspects described above.
According to the embodiment of the application, the plurality of database behaviors aiming at the databases are constructed as one database access interface, and the database access interfaces corresponding to the plurality of databases are further constructed as one user-oriented database access interface, so that the access of the homologous databases can be realized, the differential access of the heterologous databases can be realized, the abstract extraction complexity of the same behaviors during secondary development can be effectively reduced based on the differential support of the heterologous databases, and the production efficiency is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a schematic flow chart of a database access method according to an embodiment of the present application;
FIG. 2 is a schematic flow chart of determining a database access interface according to an embodiment of the present application;
FIG. 3 is a schematic flow chart of determining a query statement according to an embodiment of the present application;
FIG. 4 is a schematic flow chart of interface construction and database access provided in an embodiment of the present application;
FIG. 5 is a schematic flow chart of constructing a user-oriented database access interface according to an embodiment of the present application;
FIG. 6 is a block diagram of a database access device according to an embodiment of the present application;
fig. 7 is a block diagram of a hardware structure of an electronic device according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present application based on the embodiments herein.
It should be noted that the terms "first," "second," and the like in the description and claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that embodiments of the present application described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or server that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed or inherent to such process, method, article, or apparatus, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It will be appreciated that in the specific embodiments of the present application, related data such as user information is referred to, and when the above embodiments of the present application are applied to specific products or technologies, user permissions or consents need to be obtained, and the collection, use and processing of related data need to comply with related laws and regulations and standards of related countries and regions.
Referring to fig. 1, a flowchart of a database access method according to an embodiment of the present application is shown. It is noted that the present specification provides method operational steps as described in the examples or flowcharts, but may include more or fewer operational steps based on conventional or non-inventive labor. The order of steps recited in the embodiments is merely one way of performing the order of steps and does not represent a unique order of execution. In actual system or product execution, the methods illustrated in the embodiments or figures may be performed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment). As shown in fig. 1, the method may include:
s101, receiving a current user request based on a user access interface.
Wherein the user access interface corresponds to a plurality of database access interfaces.
Wherein each database access interface corresponds to a plurality of query statements.
The multiple query sentences corresponding to each database access interface respectively correspond to different access operation types.
The current user request is a request sent by a user at an application end and received by a user access interface. In a specific implementation, taking shopping software as an example, the current user request may be to add the commodity a to a shopping cart, collect the commodity B, and so on, where the request corresponds to different query sentences under different database access interfaces.
The access operation type is the type to which the operation of the user at the application end belongs. In a specific implementation, taking shopping software as an example, the type of access operation can be order making, shopping cart adding, collection and the like.
Specifically, the user access interface is a database access interface facing to a user, the user request is uniformly received by the user access interface, and the user access interface further finds a query statement matched with the corresponding database access interface according to the user request.
Specifically, the database access interfaces are in one-to-one correspondence with the databases, and the plurality of query sentences corresponding to the database access interfaces are query sentences for accessing the databases corresponding to the corresponding database access interfaces. In the implementation, query sentences written in advance are added in key code classes of an aggregation application program and a database in a software framework MyBatis, and a database access interface corresponding to the database is obtained, wherein the MyBatis version is more than 3.0.
S103, determining a database access interface corresponding to the current user request in the plurality of database access interfaces to obtain a target database access interface.
The target database access interface is a database access interface corresponding to a database which is requested to be accessed by a current user.
Specifically, after receiving a current user request, the user access interface determines a database aimed by the current user access request, then determines an access interface corresponding to the database as a target database access interface, and accesses the database based on the target database access interface.
In an exemplary embodiment, as shown in fig. 2, which is a schematic flowchart of determining a database access interface according to an embodiment of the present application, the step S103 may include:
s201, obtaining an interface mapping relation table.
The interface mapping relation table comprises a plurality of interface mapping relations.
Each interface mapping relation characterizes the corresponding relation between the database identifier and the database access interface identifier.
Wherein the target database identification is the identification of the database for which the current user request is directed.
Wherein the database identifier indicates a specific database, and the database name is usually the database identifier.
The database access interface identifier indicates a specific database access interface, and the name of the database access interface is usually the database access interface identifier.
S203, determining a database access interface identifier corresponding to the target database identifier based on the interface mapping relation table to obtain the target interface identifier.
The target interface identifier is an identifier of a database access interface corresponding to a database for which the current user requests.
In specific implementation, an interface mapping relation containing a target database identifier is found in an interface mapping relation table, and a database access interface identifier in the interface mapping relation is the target interface identifier.
S205, determining the database access interface indicated by the target interface identification in the plurality of database access interfaces to obtain the target database access interface.
The target database access interface is a database access interface corresponding to a database for which the current user request is directed.
As can be seen from the above technical solutions of the embodiments of the present application, in the embodiments of the present application, a database access interface for processing a current user request is determined according to a database for which the current user request is directed by a one-to-one correspondence between a database and a database access interface, so as to implement differential interface access for different databases.
S105, determining a query statement matched with the current user request in a plurality of query statements corresponding to the target database access interface to obtain a target query statement.
The multiple query sentences corresponding to the target database access interface are query sentences for accessing the target database.
Wherein the target query statement characterizes a current user request to perform an access operation with respect to target data in the target database.
Specifically, after the target database access interface is determined, in a plurality of query sentences corresponding to different access operation types, the query sentence corresponding to the access operation type indicated by the current user request is the target query sentence.
In an exemplary embodiment, the current user request includes the target data feature and the current access operation type, as shown in fig. 3, which is a schematic flow chart of determining a query statement provided in the embodiment of the present application, where the step S105 may include:
s301, acquiring a statement mapping relation table corresponding to the target database access interface.
The statement mapping relation table comprises a plurality of statement mapping relations.
Wherein, each statement mapping relation characterizes the mutual corresponding relation between the access operation type and the query statement identification.
Wherein the target data characteristic is a characteristic of the data for which the current user request is directed. In particular implementations, the target data characteristics generally include table identifiers, which are names of tables in the database, and conditional expressions, which are related to fields of the target database, and may indicate a particular data, such as id=1, name=xxx, and so on; conditional expressions may also be broader features, such as score between85and 89, name in ('AAA', 'BBB', 'CCC'), and so forth.
The current access operation type is the type to which the operation of the current user at the application end belongs. In a specific implementation, taking shopping software as an example, the current access operation type can be order, shopping cart, collection, etc.
The statement mapping relation table corresponding to the target database access interface is a statement mapping relation table corresponding to the access interface of the database aimed at by the current user request, and each database access interface corresponds to one statement mapping relation table.
The access operation type is the type to which the operation of the user at the application end belongs.
Wherein the query statement identification indicates a particular query statement.
S303, determining the query statement identification corresponding to the current access operation type based on the statement mapping relation table to obtain a target statement identification.
Wherein the target statement identification is an identification of a query statement that matches the current access operation type in the current user request.
In specific implementation, a statement mapping relation comprising the current access operation type is searched in a statement mapping relation table corresponding to an access interface of a database aimed at by a current user request, and a query statement identifier in the statement mapping relation is a target statement identifier.
S305, determining the query statement indicated by the target statement mark in a plurality of query statements corresponding to the target database access interface to obtain an initial query statement.
The initial query statement is a query statement matched with the current access operation type in the current user request in an access interface of the database for which the current user request is directed.
S307, generating the target query statement based on the initial query statement and the target data feature.
The target query statement is a query statement capable of realizing the current user request.
Specifically, the target data feature includes a table identifier and a conditional expression, and the two are filled into an initial query statement, so that a target query statement can be obtained, for example, the initial query statement sql= "update … set order=00000001 where …", the target data feature indicates data with id=1 in the Message table, and then the target query statement sql= "update Message set order =00000001 where id=1", and a field value with a field name of order in data with id 1 in the Message table is updated to 00000001. In specific implementations, there are cases where the target data feature includes only a table identifier, for example, an initial query statement sql= "insert into … (id, order, item …) values (000001000,12345678,68754123 …)", and the target data feature is a Message table, and then the target query statement is sql= "insert into Message (id, order, item …) values (000001000,12345678,68754123 …)", and a piece of data id=000001000, order=12345678, item= 68754123, … … is added to the Message table.
As can be seen from the above technical solutions of the embodiments of the present application, in the embodiments of the present application, a target query statement is determined according to a current access operation type in a current user request by using a one-to-one correspondence relationship between a query statement corresponding to each database access interface and an access operation type, so as to implement database access for different access operation types.
S107, executing the target query statement.
Specifically, the current access operation is performed on the target data in the target database.
In a specific implementation, taking fig. 4 as an example, a flow chart of interface construction and database access is provided for an embodiment of the present application, where a user behavior builder is a database access interface for a user and is configured to receive user behaviors to access a database, the user behavior builder corresponds to a plurality of database behavior builders, the database behavior builder is an interface for accessing a corresponding database, the database behavior builders are in one-to-one correspondence with the database, the database behavior builder is generated based on the plurality of database behaviors, the database behaviors are behaviors for accessing a database corresponding to the database behavior builder, and are expressed in a query statement form, and the plurality of database behaviors corresponding to each database behavior builder correspond to different user access operation types respectively. Specifically, the user behavior builder receives the user behavior, matches the database behavior builder corresponding to the database for which the user behavior is aimed, further matches the database behavior in the database behavior builder, and executes the database behavior on the database through the database executor.
As can be seen from the above technical solutions of the embodiments of the present application, in the embodiments of the present application, by constructing a plurality of database behaviors for a database as one database access interface, further constructing a database access interface corresponding to the plurality of databases as one user-oriented database access interface, receiving a user request to access the database, not only enabling access of a homologous database, but also enabling differential access of a heterologous database, and based on differential support for the heterologous database, abstraction extraction complexity for the same behavior during secondary development can be effectively reduced, and production efficiency is improved.
In an exemplary embodiment, the step S107 may include the steps of:
extracting a current access operation for the target query statement;
traversing the database indicated by the target database identifier, and determining the data matched with the target data characteristics as target data;
and executing the current access operation on the target data.
Wherein the target query statement characterizes a current user request to perform an access operation with respect to target data in the target database.
The current access operation is an operation of a current user at an application end. In a specific implementation, taking shopping software as an example, the current access operation may be to place a commodity a, add a commodity B to a shopping cart, collect a commodity C, and so on.
Wherein the target database identification is the identification of the database for which the current user request is directed.
Wherein the target data characteristics are characteristics of the data for which the current user requests. Specifically, the target data feature generally includes a table identifier, where the table identifier is a name of a table in the database, and a conditional expression, where the conditional expression is related to a field in the target database, and may indicate a specific data, for example, id=1, name=xxx, and so on; conditional expressions may also be broader features, such as score between 85and 89, name in ('AAA', 'BBB', 'CCC'), and so forth.
The target data is the data for which the current user requests.
Specifically, taking sql= "update Message set order =00000001 where there is a window id=1" as an example, extracting the current access operation set order=00000001, traversing the database indicated by the target database identifier, determining the data with id=1 in the Message table as target data, and updating the field value with the field name order in the target data as 00000001.
As can be seen from the above technical solutions of the embodiments of the present application, in the embodiments of the present application, by executing an access operation indicated by a current user request on data to which the current user request is directed, interaction between a front-end operation of a user and access of a back-end database is implemented.
The following describes a process of constructing a user-oriented database access interface, as shown in fig. 5, which is a schematic flow chart for constructing a user-oriented database access interface according to an embodiment of the present application, and may specifically include:
s501, a plurality of database identifiers are acquired.
Wherein the plurality of database identifications respectively indicate different databases.
S503, for each database identifier, acquiring a plurality of query sentences corresponding to the database identifier, and obtaining a plurality of query sentences corresponding to each database identifier.
Wherein, each database identifier corresponds to a plurality of query sentences respectively and correspondingly different access operation types, and is the query sentence of the indicated database aiming at the corresponding database identifier.
In an exemplary embodiment, the step S503 may include the steps of:
acquiring a file mapping relation table; the file mapping relation table comprises a plurality of file mapping relations; each file mapping relation characterizes the corresponding relation between the database identifier and the query statement configuration file identifier; the query statement configuration file indicated by the query statement configuration file identification comprises the plurality of query statements;
For each database identifier, determining a query statement configuration file identifier corresponding to the database identifier based on the file mapping relation table to obtain a query statement configuration file identifier corresponding to each database identifier;
determining the query statement configuration files indicated by the query statement configuration file identifiers corresponding to the database identifiers to obtain query statement configuration files corresponding to each database identifier;
extracting the plurality of query sentences in the query sentence configuration file corresponding to the database identifiers to obtain a plurality of query sentences corresponding to each database identifier.
Wherein the query statement configuration file is identified as being capable of indicating the identity of a particular query statement configuration file. In implementations, the query statement configuration file is identified as a storage path for the query statement configuration file.
Wherein the plurality of query sentences in the query sentence configuration file are query sentences of the database indicated for the respective database identifications.
Specifically, for each database identifier, a file mapping relation containing the database identifier is found in a file mapping relation table, the query statement configuration file identifier in the file mapping relation is the query statement configuration file identifier corresponding to the database identifier, the query statement configuration file indicated by the query statement configuration file identifier is the query statement configuration file corresponding to the database identifier, and query statements in the query statement configuration file are a plurality of query statements corresponding to the database identifier.
As can be seen from the above technical solutions of the embodiments of the present application, in the embodiments of the present application, query statement configuration files are parsed under paths from database identifiers to corresponding databases, so as to obtain query statements for each database, so that access interfaces are constructed for each database in the following process.
S505, for each database identifier, generating a database access interface corresponding to the database identifier based on a plurality of query sentences corresponding to the database identifier, and obtaining the plurality of database access interfaces.
Wherein the database access interface is an interface for accessing the database indicated by the corresponding database identifier. Specifically, a database access interface is built for each database to accommodate the variability between databases.
S507, generating the user access interface based on the plurality of database access interfaces, such that the user access interface accesses a database in response to the user request.
The user access interface is a database access interface facing to a user and is used for receiving a user request to access a database. Specifically, after receiving the user request, the user access interface matches the database access interface corresponding to the user request, further matches the query statement corresponding to the database access interface, and executes the query statement to realize the access of the user to the database.
In a specific implementation, as shown in fig. 4, a flow chart of interface construction and database access provided in an embodiment of the present application is shown, a database identifier is added in an application configuration file, a corresponding database behavior configuration file is added under a path corresponding to a database indicated by the database identifier, an application is started, the corresponding database configuration file is parsed according to the database identifier in the application configuration file, the database behavior configuration file is parsed under the corresponding path, a database behavior builder is generated, and a user behavior builder facing to a user is generated based on the database behavior builder and is responsible for receiving user behaviors. The content of the database behavior configuration file is a plurality of query sentences, and the content of the database behavior configuration file is the mapping relation between the database identification and the database behavior configuration file.
According to the technical scheme, the database access interfaces corresponding to the databases are further constructed into the user-oriented database access interface by constructing the database behaviors aiming at the databases into one database access interface, so that the access of the homologous databases can be realized, the differential access of the heterologous databases can be realized, the abstract extraction complexity of the same behaviors during secondary development can be effectively reduced based on the differential support of the heterologous databases, and the production efficiency is improved.
Corresponding to the database access methods provided in the foregoing several embodiments, the embodiments of the present application further provide a database access device, and since the database access device provided in the embodiments of the present application corresponds to the database access method provided in the foregoing several embodiments, implementation manners of the foregoing database access method are also applicable to the database access device provided in the embodiments, and will not be described in detail in the embodiments.
Referring to fig. 6, a schematic structural diagram of a database access device provided in an embodiment of the present application is shown, where the device has a function of implementing a database access method in the above method embodiment, and the function may be implemented by hardware or implemented by executing corresponding software by hardware. As shown in fig. 6, the apparatus may include:
a request receiving module 610, configured to receive a current user request based on a user access interface; the user access interface corresponds to a plurality of database access interfaces; each database access interface corresponds to a plurality of query sentences; the multiple query sentences corresponding to each database access interface respectively correspond to different access operation types;
an interface determining module 620, configured to determine, from among the plurality of database access interfaces, a database access interface corresponding to the current user request, and obtain a target database access interface;
The statement determining module 630 is configured to determine, from a plurality of query statements corresponding to the target database access interface, a query statement that matches the current user request, so as to obtain a target query statement;
statement execution module 640 for executing the target query statement.
In an exemplary embodiment, the current user request includes a target database identification; the interface determining module includes:
the first relation acquisition module is used for acquiring an interface mapping relation table; the interface mapping relation table comprises a plurality of interface mapping relations; each interface mapping relation characterizes the corresponding relation between the database identifier and the database access interface identifier;
the first identification determining module is used for determining a database access interface identification corresponding to the target database identification based on the interface mapping relation table to obtain a target interface identification;
and the first target determining module is used for determining the database access interface indicated by the target interface identifier in the plurality of database access interfaces to obtain the target database access interface.
In an exemplary embodiment, the current user request includes a further target data characteristic and a current access operation type; the statement determination module includes:
The second relation acquisition module is used for acquiring a statement mapping relation table corresponding to the target database access interface; the statement mapping relation table comprises a plurality of statement mapping relations; each statement mapping relation characterizes the corresponding relation between the access operation type and the query statement identification;
the second identification determining module is used for determining the query statement identification corresponding to the current access operation type based on the statement mapping relation table to obtain a target statement identification;
the second target determining module is used for determining the query statement indicated by the target statement mark in a plurality of query statements corresponding to the target database access interface to obtain an initial query statement;
and the statement generation module is used for generating the target query statement based on the initial query statement and the target data characteristic.
In an exemplary embodiment, the sentence execution module includes:
the operation extraction module is used for extracting the current access operation for the target query statement;
the data determining module is used for traversing the database indicated by the target database identifier and determining the data matched with the target data characteristics as target data;
And the operation execution module is used for executing the current access operation on the target data.
In an exemplary embodiment, the apparatus further includes an interface construction module for constructing a user-oriented database access interface, the interface construction module including:
the identification acquisition module is used for acquiring a plurality of database identifications;
the sentence acquisition module is used for acquiring a plurality of inquiry sentences corresponding to each database identifier for each database identifier to obtain a plurality of inquiry sentences corresponding to each database identifier;
the first interface generation module is used for generating a database access interface corresponding to each database identifier based on a plurality of query sentences corresponding to the database identifiers to obtain the plurality of database access interfaces;
and the second interface generation module is used for generating the user access interface based on the plurality of database access interfaces so that the user access interface responds to the user request to access the database.
In an exemplary embodiment, the sentence acquisition module includes:
the third relation acquisition module is used for acquiring a file mapping relation table; the file mapping relation table comprises a plurality of file mapping relations; each file mapping relation characterizes the corresponding relation between the database identifier and the query statement configuration file identifier; the query statement configuration file indicated by the query statement configuration file identification comprises the plurality of query statements;
The third identification determining module is used for determining the query statement configuration file identifications corresponding to the database identifications based on the file mapping relation table for each database identification to obtain the query statement configuration file identifications corresponding to each database identification;
the file determining module is used for determining the query statement configuration files indicated by the query statement configuration file identifiers corresponding to the database identifiers to obtain query statement configuration files corresponding to each database identifier;
the sentence extraction module is used for extracting the plurality of query sentences in the query sentence configuration file corresponding to the database identifiers to obtain a plurality of query sentences corresponding to each database identifier.
It should be noted that, in the apparatus provided in the foregoing embodiment, when implementing the functions thereof, only the division of the foregoing functional modules is used as an example, in practical application, the foregoing functional allocation may be implemented by different functional modules, that is, the internal structure of the device is divided into different functional modules, so as to implement all or part of the functions described above. In addition, the apparatus and the method embodiments provided in the foregoing embodiments belong to the same concept, and specific implementation processes of the apparatus and the method embodiments are detailed in the method embodiments and are not repeated herein.
The embodiment of the application provides an electronic device, which comprises a processor and a memory, wherein at least one instruction or at least one section of program is stored in the memory, and the at least one instruction or the at least one section of program is loaded and executed by the processor to realize any database access method provided by the embodiment of the method.
The memory may be used to store software programs and modules that the processor executes to perform various functional applications and data processing by executing the software programs and modules stored in the memory. The memory may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, application programs required for functions, and the like; the storage data area may store data created according to the use of the device, etc. In addition, the memory 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 volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide access to the memory by the processor.
The method embodiments provided in the embodiments of the present application may be performed in a computer terminal, a server, or a similar computing device, i.e., the electronic device may include a computer terminal, a server, or a similar computing device. Fig. 7 is a block diagram of a hardware structure of a computer device for running a database access method according to an embodiment of the present invention, and as shown in fig. 7, the internal structure of the computer device may include, but is not limited to: processor, network interface and memory. The processors, network interfaces, and memories in the computer device may be connected by a bus or other means, and in fig. 7 shown in the embodiment of the present disclosure, the connection by a bus is an example.
Among them, a processor (or CPU (Central Processing Unit, central processing unit)) is a computing core and a control core of a computer device. The network interface may optionally include a standard wired interface, a wireless interface (e.g., WI-FI, mobile communication interface, etc.). Memory (Memory) is a Memory device in a computer device for storing programs and data. It will be appreciated that the memory herein may be a high speed RAM memory device or a non-volatile memory device, such as at least one magnetic disk memory device; optionally, at least one memory device located remotely from the processor. The memory provides a storage space that stores an operating system of the electronic device, which may include, but is not limited to: windows (an operating system), linux (an operating system), android (an Android, a mobile operating system) system, IOS (a mobile operating system) system, etc., the invention is not limited in this regard; also stored in the memory space are one or more instructions, which may be one or more computer programs (including program code), adapted to be loaded and executed by the processor. In the embodiment of the present disclosure, the processor loads and executes one or more instructions stored in the memory to implement the database access method provided in the above embodiment of the method.
Embodiments of the present application also provide a computer readable storage medium that may be disposed in an electronic device to store at least one instruction or at least one program for implementing a database access method, the at least one instruction or the at least one program being loaded and executed by the processor to implement any of the database access methods provided by the method embodiments described above.
Alternatively, in the present embodiment, the storage medium may include, but is not limited to: a U-disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing program codes.
It should be noted that: the foregoing sequence of the embodiments of the present application is only for describing, and does not represent the advantages and disadvantages of the embodiments. And the foregoing description has been directed to specific embodiments of this specification. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments in part.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program for instructing relevant hardware, where the program may be stored in a computer readable storage medium, and the storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The foregoing description of the preferred embodiments of the present application is not intended to limit the invention to the particular embodiments of the present application, but to limit the scope of the invention to the particular embodiments of the present application.

Claims (10)

1. A method of database access, the method comprising:
receiving a current user request based on a user access interface; the user access interface corresponds to a plurality of database access interfaces; each database access interface corresponds to a plurality of query sentences; the multiple query sentences corresponding to each database access interface respectively correspond to different access operation types;
Determining a database access interface corresponding to the current user request from the plurality of database access interfaces to obtain a target database access interface;
determining a query statement matched with the current user request in a plurality of query statements corresponding to the target database access interface to obtain a target query statement;
and executing the target query statement.
2. The database access method of claim 1, wherein the current user request includes a target database identification; determining the database access interface corresponding to the current user request from the plurality of database access interfaces to obtain a target database access interface, including:
obtaining an interface mapping relation table; the interface mapping relation table comprises a plurality of interface mapping relations; each interface mapping relation characterizes the corresponding relation between the database identifier and the database access interface identifier;
determining a database access interface identifier corresponding to the target database identifier based on the interface mapping relation table to obtain a target interface identifier;
and determining the database access interface indicated by the target interface identifier from the plurality of database access interfaces to obtain the target database access interface.
3. The database access method of claim 2, wherein the current user request includes a further target data characteristic and a current access operation type; determining a query sentence matched with the current user request in a plurality of query sentences corresponding to the target database access interface to obtain a target query sentence, wherein the method comprises the following steps:
acquiring a statement mapping relation table corresponding to the target database access interface; the statement mapping relation table comprises a plurality of statement mapping relations; each statement mapping relation characterizes the corresponding relation between the access operation type and the query statement identification;
determining a query statement identifier corresponding to the current access operation type based on the statement mapping relation table to obtain a target statement identifier;
determining the query statement indicated by the target statement identification in a plurality of query statements corresponding to the target database access interface to obtain an initial query statement;
the target query statement is generated based on the initial query statement and the target data feature.
4. The database access method of claim 3, wherein the executing the target query statement comprises:
Extracting a current access operation for the target query statement;
traversing the database indicated by the target database identifier, and determining the data matched with the target data characteristics as target data;
and executing the current access operation on the target data.
5. The database access method according to any one of claims 1 to 4, wherein the method further comprises:
acquiring a plurality of database identifiers;
for each database identifier, acquiring a plurality of query sentences corresponding to the database identifiers to obtain a plurality of query sentences corresponding to each database identifier;
for each database identifier, generating a database access interface corresponding to the database identifier based on a plurality of query sentences corresponding to the database identifier, and obtaining the plurality of database access interfaces;
the user access interface is generated based on the plurality of database access interfaces such that the user access interface accesses a database in response to the user request.
6. The method for accessing a database according to claim 5, wherein for each database identifier, obtaining a plurality of query sentences corresponding to the database identifier, and obtaining a plurality of query sentences corresponding to each database identifier, comprises:
Acquiring a file mapping relation table; the file mapping relation table comprises a plurality of file mapping relations; each file mapping relation characterizes the corresponding relation between the database identifier and the query statement configuration file identifier; the query statement configuration file indicated by the query statement configuration file identification comprises the plurality of query statements;
for each database identifier, determining a query statement configuration file identifier corresponding to the database identifier based on the file mapping relation table to obtain a query statement configuration file identifier corresponding to each database identifier;
determining the query statement configuration files indicated by the query statement configuration file identifiers corresponding to the database identifiers to obtain query statement configuration files corresponding to each database identifier;
extracting the plurality of query sentences in the query sentence configuration file corresponding to the database identifiers to obtain a plurality of query sentences corresponding to each database identifier.
7. A database access apparatus, the apparatus comprising:
the request receiving module is used for receiving a current user request based on the user access interface; the user access interface corresponds to a plurality of database access interfaces; each database access interface corresponds to a plurality of query sentences; the multiple query sentences corresponding to each database access interface respectively correspond to different access operation types;
The interface determining module is used for determining a database access interface corresponding to the current user request from the plurality of database access interfaces to obtain a target database access interface;
the statement determining module is used for determining a query statement matched with the current user request in a plurality of query statements corresponding to the target database access interface to obtain a target query statement;
and the statement executing module is used for executing the target query statement.
8. An electronic device comprising a processor and a memory, wherein the memory has stored therein at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the database access method of any of claims 1-6.
9. A computer readable storage medium having stored therein at least one instruction or at least one program loaded and executed by a processor to implement the database access method of any of claims 1-6.
10. A computer program comprising a computer program which, when executed by a processor, implements the database access method of any of claims 1 to 6.
CN202310248576.9A 2023-03-15 2023-03-15 Database access method and device, electronic equipment and storage medium Pending CN116414898A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310248576.9A CN116414898A (en) 2023-03-15 2023-03-15 Database access method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310248576.9A CN116414898A (en) 2023-03-15 2023-03-15 Database access method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116414898A true CN116414898A (en) 2023-07-11

Family

ID=87052440

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310248576.9A Pending CN116414898A (en) 2023-03-15 2023-03-15 Database access method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116414898A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117235107A (en) * 2023-11-10 2023-12-15 恒生电子股份有限公司 Data access processing method and device, electronic equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117235107A (en) * 2023-11-10 2023-12-15 恒生电子股份有限公司 Data access processing method and device, electronic equipment and storage medium
CN117235107B (en) * 2023-11-10 2024-01-26 恒生电子股份有限公司 Data access processing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN112559554B (en) Query statement optimization method and device
CN110502546B (en) Data processing method and device
CN106503008B (en) File storage method and device and file query method and device
CN104424263A (en) Data recording method and data recording device
CN107480260B (en) Big data real-time analysis method and device, computing equipment and computer storage medium
CN116414898A (en) Database access method and device, electronic equipment and storage medium
CN104750872A (en) Method and device for searching service object
CN111581234A (en) RAC multi-node database query method, device and system
KR101640733B1 (en) System for Managing data based In-Memory DataBase and method thereof
CN103902565A (en) Method and device for determining data access relation
CN114610516B (en) Application program repairing method and device, computer equipment and storage medium
CN109800273A (en) A kind of method, apparatus of data processing, computer storage medium and terminal
CN114706586A (en) Code compiling method, code running method, code compiling device, code running device, computer equipment and storage medium
CN114942781A (en) Data format adaptation method and device for data reading
CN110333883B (en) Method and device for updating persistent data
CN111159162B (en) Database configuration method and equipment
CN114238407A (en) Pre-compiling method and system based on sub-library and sub-table middleware
CN110222105B (en) Data summarization processing method and device
CN113342647A (en) Test data generation method and device
CN108614868B (en) Automatic database upgrading method
CN107463374B (en) Subset model extraction method and system based on inheritance and association automatic deduction
CN108780452A (en) A kind of storing process processing method and processing device
CN112100208A (en) Operation request forwarding method and device
CN116700840B (en) File execution method, device, electronic equipment and readable storage medium
CN116339717B (en) Data execution method, device, equipment and 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