Detailed Description
For a clearer understanding of the embodiments of the present application, some terms or techniques referred to in the embodiments of the present application are described below:
1) structured query Statement (SQL)
SQL is a special-purpose programming language, a database query and programming language, and is mainly used for accessing data, or for querying, updating, or managing relational database systems, etc.
2) Application Programming Interface (API)
An API is a predefined function. Typically, an application encapsulates its own service capabilities into an API so that the application can open the service capabilities for user invocation.
3) Other terms
In the embodiments of the present application, words such as "exemplary" or "for example" are used to mean serving as an example, instance, or illustration. Any embodiment or design described herein as "exemplary" or "e.g.," is not necessarily to be construed as preferred or advantageous over other embodiments or designs. Rather, use of the word "exemplary" or "such as" is intended to present concepts related in a concrete fashion.
In the embodiments of the present application, the terms "first", "second" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of the present application, "a plurality" means two or more unless otherwise specified.
The term "at least one" in this application means one or more, and the term "plurality" in this application means two or more, for example, the plurality of second messages means two or more second messages. The terms "system" and "network" are often used interchangeably herein.
It is to be understood that the terminology used in the description of the various described examples herein is for the purpose of describing particular examples only and is not intended to be limiting. As used in the description of the various described examples and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items. The term "and/or" is an associative relationship that describes an associated object, meaning that three relationships may exist, e.g., A and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" in the present application generally indicates that the former and latter related objects are in an "or" relationship.
It should also be understood that, in the embodiments of the present application, the size of the serial number of each process does not mean the execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
It should be understood that determining B from a does not mean determining B from a alone, but may also be determined from a and/or other information.
It will be further understood that the terms "comprises," "comprising," "includes," and/or "including," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also understood that the term "if" may be interpreted to mean "when" ("where" or "upon") or "in response to a determination" or "in response to a detection". Similarly, the phrase "if it is determined." or "if [ a stated condition or event ] is detected" may be interpreted to mean "upon determining.. or" in response to determining. "or" upon detecting [ a stated condition or event ] or "in response to detecting [ a stated condition or event ]" depending on the context.
It should be appreciated that reference throughout this specification to "one embodiment," "an embodiment," "one possible implementation" means that a particular feature, structure, or characteristic described in connection with the embodiment or implementation is included in at least one embodiment of the present application. Thus, the appearances of the phrases "in one embodiment" or "in an embodiment" or "one possible implementation" in various places throughout this specification are not necessarily all referring to the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
The embodiment of the application provides a method for generating an API, and the method can generate the API after automatically analyzing an executable SQL statement, so that the efficiency of generating the API is improved.
The embodiment of the present application further provides an apparatus for generating an API, where the apparatus may be an API development platform of a data resource provider, or the apparatus may be a public API development platform, and this is not specifically limited in this embodiment of the present application.
It should be understood that the embodiments of the present application do not specifically limit the types of data resources provided by data resource providers.
Specifically, the apparatus for generating the API may be a server. The server may be a physical server, such as a general purpose computer device. Alternatively, the server may be a cloud server, and the like, which is not specifically limited in this embodiment of the present application.
Optionally, the apparatus for generating the API may also be a terminal. The terminal may be a portable device such as a mobile phone, a tablet computer, and a wearable electronic device, or may be a computing device such as a Personal Computer (PC), a Personal Digital Assistant (PDA), a netbook, or any other terminal device capable of implementing the method according to the embodiment of the present application, which is not limited in this respect.
Referring to fig. 1, fig. 1 shows a hardware structural diagram of an apparatus 10 for generating an API provided by an embodiment of the present application. As shown in fig. 1, the apparatus 10 for generating an API includes a processor 11, a memory 12, a communication interface 13, and a bus 14. The processor 11, the memory 12 and the communication interface 13 may be connected by a bus 14.
The processor 11 is a control center of the apparatus 10 that generates the API, and may be a Central Processing Unit (CPU), another general-purpose processor, or the like. Wherein a general purpose processor may be a microprocessor or any conventional processor or the like.
As one example, processor 11 may include one or more CPUs, such as CPU 0 and CPU 1 shown in FIG. 1.
The memory 12 may be, but is not limited to, a read-only memory (ROM) or other type of static storage device that may store static information and instructions, a Random Access Memory (RAM) or other type of dynamic storage device that may store information and instructions, an electrically erasable programmable read-only memory (EEPROM), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer.
In one possible implementation, the memory 12 may exist independently of the processor 11. Memory 12 may be coupled to processor 11 via bus 14 for storing data, instructions, or program code. The method for generating the API provided by the embodiment of the present application can be implemented when the processor 11 calls and executes the instructions or program codes stored in the memory 12.
In another possible implementation, the memory 12 may also be integrated with the processor 11.
The communication interface 13 is configured to connect the apparatus 10 for generating the API with other devices (e.g., data provider devices, etc.) through a communication network, where the communication network may be an ethernet, a Radio Access Network (RAN), a Wireless Local Area Network (WLAN), or the like. The communication interface 13 may comprise a receiving unit for receiving data and a transmitting unit for transmitting data.
The bus 14 may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended ISA (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in FIG. 1, but it is not intended that there be only one bus or one type of bus.
It is noted that the structure shown in fig. 1 does not constitute a limitation of the API-generating apparatus 10, and that the API-generating apparatus 10 may include more or less components than those shown in fig. 1, or may combine some components, or a different arrangement of components, in addition to those shown in fig. 1.
Referring to fig. 2, an embodiment of the present application further provides a data access system 20. As shown in fig. 2, the data access system 20 includes a data provider 21, an API service platform 22, and a data consumer 23.
Alternatively, the API service platform 22 may be the API-generating device described above. As such, the API service platform 22 may generate APIs (e.g., API 221, API 222, …, API 22n, or the like) that may access data resources provided by the data provider 21 that allow open access to the outside. In this way, the data consumer 23 can access the data resource that the data provider 21 allows open access to the outside by calling these APIs.
Alternatively, the API service platform 22 may be pre-stored with APIs (e.g., API 221, API 222, …, or API 22n, etc.) for accessing data resources provided by the data provider 21, which are generated by the API generating means based on the data resources allowing open access to the outside. In this way, the data consumer 23 can access the data resource that the data provider 21 allows open access to the outside by calling these APIs.
The method for generating the API provided in the embodiments of the present application is described in detail below with reference to the accompanying drawings.
For simplicity of description, in the following, the above apparatus for generating the API is simply referred to as a generating apparatus.
Referring to fig. 3, fig. 3 is a schematic flowchart illustrating a method for generating an API provided by an embodiment of the present application. The method may comprise the steps of:
s101, the generating device obtains executable SQL used for inquiring data to be inquired.
The executable SQL may be SQL in a standard format, and is used for querying data to be queried. The data to be queried may be a data resource that the data provider shown in fig. 2 allows open access to the outside, which is not limited in this embodiment of the present application.
As an example, the data provider shown in fig. 2 may pre-build the executable SQL described above based on the data resources that allow open access to the outside. When the executable SQL is executed, the data resources that allow open access to the outside may be queried (or accessed). Here, the embodiment of the present application does not limit the specific process of constructing the executable SQL by the data provider.
It should be understood that in the executable SQL described above, at least one conditional statement unit is included. In each conditional statement unit, an attribute parameter and a condition parameter are included. The attribute parameter is used to indicate the attribute of the data to be queried, and typically, the attribute parameter includes a field. The condition parameter is used to indicate a query condition for querying the data to be queried with the attribute, and typically, the condition parameter includes a numerical value or a character string, i.e., the type of the condition parameter may be a numerical value or a character string.
It is easy to see that, for a conditional statement unit, the attribute parameters and the condition parameters included in the conditional statement unit are corresponding, and the corresponding attribute parameters and the corresponding condition parameters are used together to describe data to be queried, which has certain attributes and conditions.
Illustratively, the pre-built executable SQL may be:
select*from apple
- -apple color is red
where color='red'
-apple weight greater than 10 or less than 20
and(weight>10or weight<20);
Wherein the executable SQL is used for querying the data of the apples, which are red in color and 10-20 in weight, in the database. Wherein "apple color is red" and "apple weight is greater than 10 or less than 20" are the executable SQL annotation text. "where", "and", and "or" are conjunctions in the executable SQL.
The conjunction word "where" is used for leading out a conditional statement unit for limiting the query range of the data to be queried. Typically, at least one conditional statement unit is included after the conjunction "where". For example, "color" ═ red "is a conditional statement unit, in the conditional statement unit, the attribute parameter is the field" color ", and the conditional parameter is the character string" ", red". As another example. "weight > 10" is a conditional statement unit in which the attribute parameter is the field "weight" and the conditional parameter is the value "10". And will not be described in detail.
The conjunction "and the conjunction" or "are used to indicate a relationship between different conditional statement units among the plurality of conditional statement units. "and" represents a parallel relationship, and "or" represents an or relationship.
Optionally, the data provider may input the constructed executable SQL to the generating device through an input/output interface of the generating device. In response, the generating device retrieves the executable SQL.
For example, a developer of the data provider inputs the constructed executable SQL to the generating device through an input/output interface such as a keyboard, a mouse, or a touch screen of the generating device. In response, the generating device retrieves the executable SQL.
Alternatively, after the executable SQL is constructed, the data provider may send a request for generating the API to the generating device through a communication interface of the data provider device via a wired or wireless communication network. The request for generating the API comprises executable SQL constructed by a data provider. In response, the generating device receives the request to generate the API and obtains the executable SQL.
S102, the generating device generates first information based on the acquired executable SQL.
The first information comprises the name of the attribute parameter in the executable SQL and the type of the condition parameter in the executable SQL.
Specifically, the generating device may shield the annotation text in the executable SQL, and then parse the executable SQL into at least one conditional statement unit according to the conjunctions in the executable SQL.
For example, for the executable SQL exemplified in S101, the generating means may mask the annotation text "apple color is red" and "apple weight is greater than 10 or less than 20" in the executable SQL. Then, the generation device analyzes the executable SQL into three conditional statement units according to the conjunctions "where", "and", and "or" in the executable SQL:
color='red'
weight>10
weight<20
then, the generating device may extract the attribute parameters and the condition parameters in the at least one conditional statement unit according to the at least one conditional statement unit obtained by the parsing.
For example, the generating device obtains three conditional statement units based on the above example analysis, and can extract the condition parameters in the three conditional statement units:
'red'
10,20
as another example, the generation device obtains three conditional statement units based on the above example analysis, and can extract the attribute parameters in the three conditional statement units:
color,weight,weight
then, the generating means may generate at least one first information based on the extracted attribute parameters and condition parameters. Here, the at least one piece of first information corresponds to the at least one conditional statement unit obtained by the analysis one to one.
Specifically, the generating means may generate the first information corresponding to the conditional query statement according to the attribute parameter and the condition parameter extracted from the same conditional query statement (for example, conditional query statement 1). The first information includes the name of the attribute parameter in the conditional query statement 1 and the type of the condition parameter in the conditional query statement 1.
Alternatively, the generating means may use the attribute as the name of the attribute parameter in the first information according to the attribute represented by the attribute parameter extracted from the conditional query statement 1.
Alternatively, the generating means may use a custom name as the name of the attribute parameter in the first information according to the attribute parameter extracted from the conditional query statement 1. In this case, the generating means prestores the correspondence between the attribute parameters extracted from the conditional query statement 1 and the custom names.
For example, taking the case that the conditional query expression 1 is "color ═ red '", based on the conditional query expression, the generating device extracts the conditional parameter as "red'", and it can be seen that the type of the conditional parameter is a character string, and therefore the generating device can determine that the type of the conditional parameter in the first information is a character string.
Further, the attribute parameter extracted by the generation apparatus based on the conditional query statement 1 is "color". In this way, the generation apparatus can use the attribute color as the name of the attribute parameter in the first information, based on the attribute color indicated by the attribute parameter "color". In this way, the generating device may determine that the first information corresponding to the conditional query statement 1 is: the name color; a type string.
Alternatively, the attribute parameter extracted by the generation device based on the conditional query expression 1 is "color". In this way, the generating device can customize the name of the attribute parameter in the first information to be name 1. It should be understood that, in this case, the generation means prestores the correspondence between the custom name and the extracted attribute parameter, that is, prestores the correspondence between the custom name 1 and the extracted attribute parameter "color". In this way, the generating device may determine that the first information corresponding to the conditional query statement 1 is: name 1; a type string.
Similarly, taking the example that the conditional query statement 2 is "weight > 10", the generating device may determine that the first information corresponding to the conditional query statement 2 is: the name weight 1; a type value. Alternatively, the generating device may determine that the first information corresponding to the conditional query statement 2 is: name 2; a type value.
Similarly, taking the example that the conditional query statement 3 is "weight < 20", the generating means may determine that the conditional query statement 3 corresponds to the first information as: the name weight 2; a type value. Alternatively, the generating device may determine that the conditional query statement 3 corresponds to the first information as: name 3; a type value.
S103, the generating device generates second information based on the determined first information.
The second information is used for indicating the position of the condition parameter in the executable SQL and the mapping relation of the first information. It should be understood that the condition parameter is the condition parameter extracted by the generating device in step S102 for determining the first information.
Specifically, the generation means may generate the second information by:
step 1, the generating device marks the position of the condition parameter through the address identifier in the executable SQL.
Specifically, the generating means may replace the condition parameter in the executable SQL with an address identifier. In this way, it is realized that the position of the condition parameter in the executable SQL is marked by the address identifier.
Illustratively, in executable SQL with the annotation text masked, the address identifier is used to replace the condition parameter in the SQL, as exemplified above by the executable SQL:
select*from apple
where color=${1}
and(weight>${2}or weight<${3});
where "$ {1 }" is an address identifier for marking the condition parameter '"red'", "$ {2 }" is an address identifier for marking the condition parameter "10", and "$ {3 }" is an address identifier for marking the condition parameter "20".
It should be understood that the embodiment of the present application does not specifically limit the specific form of the address identifier.
Step 2, the generating device adds the address identifier to the first information determined based on the condition parameter of the position marked by the address identifier to generate second information.
After the generating device marks the position of the condition parameter in the executable SQL, an address identifier for marking the position may be added to the first information determined based on the condition parameter marking the position by the address identifier, thereby implementing mapping between the position of the condition parameter in the executable SQL and the first information.
For example, for the conditional query statement 1 "color ═ red '" in the executable SQL exemplified above, the generating device may add an address identifier "$ {1 }" for marking the position of the condition parameter ' "red '" in the conditional query statement 1 to the first information corresponding to the conditional query statement 1 to obtain the second information corresponding to the conditional query statement 1: the name color; a type string; position $ {1}, or obtaining second information corresponding to the conditional query statement 1: name 1; a type value; position $ {1 }.
Similarly, for the conditional query statement 2 "weight > 10" in the executable SQL exemplified above, the generating device may add an address identifier "$ {2 }" for marking the position of the condition parameter "10" in the conditional query statement 2 to the first information corresponding to the conditional query statement 2 to obtain the second information corresponding to the conditional query statement 2: the name weight 1; a type value; position $ {2}, or, obtaining second information corresponding to the conditional query statement 2: name 2; a type value; position $ {2 }.
Similarly, for the conditional query statement 3 "weight < 20" in the executable SQL exemplified above, the generating means may add an address identifier "$ {3 }" for marking the position of the condition parameter "20" in the conditional query statement 3 to the first information corresponding to the conditional query statement 3 to obtain the second information corresponding to the conditional query statement 3: the name weight 2; a type value; position $ {3}, or obtain second information corresponding to the conditional query statement 3: name 3; a type value; position $ {3 }.
It can be seen that the number of the first information corresponds to the number of the second information one to one, and a conditional query unit in SQL can be executed, corresponding to one piece of the first information and one piece of the second information.
S104, the generating device generates the SQL template capable of executing SQL according to the generated second information.
Specifically, the generating device may replace, according to the type of the condition parameter in the second information, the address identifier used for marking the position of the condition parameter with preset information, so as to generate the SQL template capable of executing SQL.
The generating device may determine, according to the type of the condition parameter in the second information, a format of the preset information for replacing the address identifier, which marks the position of the condition parameter, in the executable SQL.
Optionally, if the type of the condition parameter in the second information is a character string, when the generating device replaces the address identifier with the preset information, the format of the generating device may be: 'Preset information'. If the type of the condition parameter in the second information is a numerical value, the generating means may be configured to, when replacing the address identifier with the preset information: and presetting information. Of course, the embodiment of the present application is not particularly limited thereto.
It is to be understood that, in the embodiment of the present application, a determination manner of the preset information is not particularly limited.
For example, in one possible implementation, the preset information may be a name of an attribute parameter in the second information. In this case, the generating means may replace the address identifier for marking the location of the condition parameter with the name of the attribute parameter in the second information according to the type of the condition parameter in the second information, thereby generating the SQL template of the executable SQL.
For example, for the executable SQL exemplified above, the corresponding second information may include second information 1: the name color; a type string; position $ {1 }. In this case, the preset information may be a name color of the attribute parameter in the second information 1, and since the type of the condition parameter in the second information 1 is a character string, the format of the preset information when replacing the address identifier may be: 'color'. Thus, the generating device can replace the address identifier $ {1} marking the location of the conditional parameter in executable SQL with 'color'.
Similarly, the second information corresponding to the executable SQL exemplified above may include second information 2: the name weight 1; a type value; position $ {2 }. In this case, the preset information may be the name weight 1 of the attribute parameter in the second information 2, and since the type of the condition parameter in the second information 2 is a numerical value, the format of the preset information when replacing the address identifier may be: weight 1. Thus, the generating device can replace the address identifier $ {2} marking the location of the condition parameter in executable SQL with weight 1.
Similarly, the second information corresponding to the executable SQL exemplified above may include second information 3: the name weight 2; a type value; position $ {3 }. In this case, the preset information may be the name weight 2 of the attribute parameter in the second information 3, and since the type of the condition parameter in the second information 3 is a numerical value, the format of the preset information when replacing the address identifier may be: weight 2. Thus, the generating device can replace the address identifier $ {3} in executable SQL with weight 2, which marks the location of the condition parameter.
Namely, the SQL template capable of executing SQL obtained according to the above method is:
select*from apple
where color='color'
and(weight>weight 1or weight<weight 2);
in another possible implementation manner, the preset information may also be custom information. In this case, the generating means prestores a correspondence relationship between the names of the attribute parameters in the custom information and the second information.
For example, for the executable SQL exemplified above, the corresponding second information includes the following second information 1: the name color; a type string; position $ {1 }. In this case, the preset information may be a custom aaa, and in this case, the generating apparatus prestores a correspondence relationship between the aaa and the name color of the attribute parameter in the second information 1. Since the type of the condition parameter in the second information 1 is a character string, the format of the preset information when replacing the address identifier may be: 'aaa'. Thus, the generating device can then replace the address identifier $ {1} marking the location of the conditional parameter in executable SQL with 'aaa'.
Similarly, the second information corresponding to the executable SQL exemplified above may include second information 2: the name weight 1; a type value; position $ {2 }. In this case, the preset information may be a customized bbb, and in this case, the generating device prestores a correspondence between the name weight 1 of the attribute parameter in the second information 2 and the bbb. Since the type of the condition parameter in the second information 2 is a numerical value, the format of the preset information when replacing the address identifier may be: bbb. Thus, the generating device can then replace the address identifier $ {2} marking the location of the conditional parameter in executable SQL with bbb.
Similarly, the second information corresponding to the executable SQL exemplified above may include second information 3: the name weight 2; a type value; position $ {3 }. In this case, the above-mentioned preset information may be a customized ccc, and in this case, the generating means prestores a correspondence between the ccc and the name weight 2 of the attribute parameter in the second information 3. Since the type of the condition parameter in the second information 3 is a numerical value, the format of the preset information when replacing the address identifier may be: ccc. Thus, the generating device can replace the address identifier $ {3} in executable SQL, which marks the location of the conditional parameter, with ccc.
Namely, the SQL template of the SQL obtained according to the above method is:
select*from apple
where color='aaa'
and(weight>bbb or weight<ccc)。
s105, the generating device generates an API according to the generated SQL template.
The generation device generates an API including the SQL template based on the generated SQL template.
It should be understood that this API is the API that is ultimately generated by the embodiments of the present application.
It should be understood that the API generated by the embodiment of the present application includes the SQL template generated by the generating device in the above steps. Therefore, when a data user develops an application, the specific executable SQL can be obtained by citing the API and replacing the preset information in the SQL template in the API by using the specific condition parameters according to the use specification of the API. When the particular executable SQL is executed, it queries (or accesses) the data resource within the range defined by the particular condition parameter. In this way, access (or invocation) of the data resources of the data provider by the data consumer is achieved.
The API usage specification may be an API usage specification that the data consumer previously acquired from the data provider. The use description records the corresponding relation between the preset information in the SQL template in the API and the attribute of the data to be queried (or accessed).
It can be seen that in the above S101 to S105, the generating means generates the API based on all the attribute parameters in the acquired executable SQL. In this case, it means that the data provider allows the data to be queried indicated by all the attribute parameters in the executable SQL to be accessed (or invoked). That is, the data provider allows the data to be queried indicated by all the attribute parameters in the executable SQL to be accessed (or called) in an open manner, that is, the data provider does not fix the condition parameters corresponding to all the attribute parameters, that is, the condition parameters are specified by the data consumer.
As an example, when the generating apparatus is called by executing the method described in S101 to S105, the API generated based on the executable SQL exemplified in S101 to S105, the data consumer may specify that the condition parameter of any color is used to replace the preset information corresponding to the data resource attribute color in the SQL template in the API, and may specify that the condition parameter of any numerical value is used to replace the preset information corresponding to the data resource attribute weight in the SQL template in the API.
However, in some embodiments, after the data provider constructs the executable SQL, for the data to be queried corresponding to a part of attribute parameters in the SQL, the data provider does not allow the data to be accessed (or invoked) in an open manner, and only allows the data to be queried within a range defined by the condition parameters corresponding to the part of attribute parameters to be accessed (or invoked). That is, the data provider requires that the condition parameters corresponding to the part of the attribute parameters are fixed, i.e., the data consumer is not allowed to autonomously specify the condition parameters.
As an example, when the generating apparatus executes the method described in S101 to S105, in the API generated based on the executable SQL illustrated in S101 to S105, the data to be queried corresponding to the attribute parameter weight does not allow the data user to have open access (or call). That is, when the API is called, the data user may specify that the condition parameter of any color is used to replace the preset information corresponding to the data resource attribute color in the SQL template in the API. However, for the data to be queried corresponding to the attribute parameter weight, the data user can only access the data resource within the range defined by the condition parameter corresponding to the attribute parameter weight in the executable SQL for generating the API, that is, the data user can only access the data resource of which the apple weight is greater than 10 or less than 20.
In this case, in the process executed by the generating device in steps S101 to S105, the generating device may execute the following steps to enable the generating device to determine the target attribute parameter, so that the generating device may further generate an API for accessing (or calling) the data to be queried corresponding to the target attribute parameter according to the determined target attribute parameter. The data resource with the attribute indicated by the target attribute parameter is a data resource which is allowed to be accessed in an open mode by a data resource provider.
In a possible implementation manner, referring to fig. 4, after S102, the method in the embodiment of the present application may further include S1021, in which case, S103 may use S1031 instead of:
s1021, the generation device specifies the first information corresponding to the target attribute parameter, among the first information specified in S102.
Since the first information includes the name of the attribute parameter in the executable SQL, which is used to indicate the attribute of the data to be queried, the generating device may cause the data provider to determine the first information corresponding to the target attribute parameter in the at least one first information by presenting the at least one first information corresponding to the SQL generated in S102 to the data provider.
Optionally, the generating device may display the at least one first information to the data provider through a display module (e.g., a display screen) of the generating device after determining the at least one first information. Thus, the data provider can determine the first information corresponding to the target attribute parameter according to the attribute parameter name in the at least one first information displayed by the generating device.
Then, the data provider may select first information corresponding to the target attribute parameter from the at least one first information displayed by the generating device, and input the selected first information to the generating device through an input/output interface (e.g., a mouse, a keyboard, a touch screen, or the like) of the generating device, or input identification information (e.g., a number of the first information or the like) indicating the selected first information, and the like, which is not particularly limited in this embodiment of the application.
In response, the generating device can determine the first information corresponding to the target attribute parameter.
Optionally, the generating means may send the at least one first information to the data provider device after determining the at least one first information. In this way, the data provider may receive the at least one first information and present the at least one first information to the data provider via a display module (e.g., a display screen) of the data provider device.
In this way, the data provider may determine the first information corresponding to the target attribute parameter according to the attribute parameter name in the at least one first information displayed by the data provider device.
Then, the data provider may select first information corresponding to the target attribute parameter from the at least one first information presented by the data provider device, and input the selected first information to the data provider device through an input/output interface (e.g., a mouse, a keyboard, a touch screen, or the like) of the data provider device, or input identification information (e.g., a number of the first information or the like) indicating the selected first information, or the like, which is not particularly limited.
The data provider device may determine the first information corresponding to the target attribute parameter and send the first information to the generating device, or send identification information (for example, a number of the first information) indicating the first information to the generating device, and the like, which is not particularly limited.
In response, the generating device can determine the first information corresponding to the target attribute parameter.
And S1031, the generating device generates corresponding second information based on the first information corresponding to the determined target attribute parameters.
Specifically, the generating device may mark, in the executable SQL, the position of the condition parameter corresponding to the determined target attribute parameter by the address identifier. Then, the generating means adds the address identifier to the first information including the name of the target attribute parameter, thereby generating the second information.
The generating device marks the position of the condition parameter corresponding to the determined target attribute parameter through the address identifier, and adds the address identifier to the first information including the name of the target attribute parameter, so as to generate a specific description of the second information, which may refer to the related description in S103 and is not described herein again.
In this way, after the generating device has executed step S1031, the generating device executes the API generated in step S104 and step S105, in which the data resource corresponding to the target attribute parameter is allowed to be accessed (or called) in an open manner, and the data resource corresponding to the non-target attribute parameter is not allowed to be accessed (or called) in an open manner, that is, the condition parameter corresponding to the non-target attribute parameter is fixed in the SQL template in the API.
Therefore, by the method, the data provider can flexibly select the data resources which are opened and called, and the flexibility of opening the data resources is improved.
In another possible implementation manner, referring to fig. 5, after S103 described above, the method in the embodiment of the present application may further include S1032, in which case S104 may use S1041 instead of:
s1032, the generating device determines the second information corresponding to the target attribute parameter from the second information generated in S103.
As can be seen from the above, the second information includes the name of the attribute parameter in SQL, which is used to indicate the attribute of the data to be queried, and therefore, the generating apparatus may display the at least one piece of second information corresponding to the SQL generated in S103 to the data provider, so that the data provider determines the second information corresponding to the target attribute parameter in the at least one piece of second information.
Optionally, the generating device may display the at least one second information to the data provider through a display module (e.g., a display screen) of the generating device after the at least one second information is generated. Thus, the data provider can determine the second information corresponding to the target attribute parameter according to the attribute parameter name in the at least one second information displayed by the generating device.
Then, the data provider may select second information corresponding to the target attribute parameter from the at least one second information displayed by the generating device, and input the selected second information to the generating device through an input/output interface (e.g., a mouse, a keyboard, a touch screen, or the like) of the generating device, or input identification information (e.g., a number of the second information or the like) indicating the selected second information, or the like, which is not particularly limited.
In response, the generating device may determine second information corresponding to the target attribute parameter.
Alternatively, the generating means may transmit the at least one second information to the data provider device after generating the at least one second information. In this way, the data provider may receive the at least one second information and present the at least one second information to the data provider via a display module (e.g., a display screen) of the data provider device.
In this way, the data provider may determine the second information corresponding to the target attribute parameter according to the attribute parameter name in the at least one second information displayed by the data provider device.
Then, the data provider may select second information corresponding to the target attribute parameter from at least one second information presented by the data provider device, and input the selected second information to the data provider device through an input/output interface (e.g., a mouse, a keyboard, a touch screen, or the like) of the data provider device, or input identification information (e.g., a number of the second information, or the like) indicating the selected second information, or the like, which is not particularly limited.
The data provider device may determine the second information corresponding to the target attribute parameter and send the second information to the generating device, or send identification information (for example, a number of the second information) indicating the second information to the generating device, and the like, which is not particularly limited.
In response, the generating device may determine second information corresponding to the target attribute parameter.
And S1041, generating the SQL template capable of executing SQL by the generating device according to the second information corresponding to the determined target attribute parameters.
Specifically, the generating device replaces the address identifier used for marking the position of the condition parameter with preset information according to the type of the condition parameter in the second information corresponding to the determined target attribute parameter, so as to generate the SQL template capable of executing SQL.
The generating device replaces the address identifier used for marking the position of the condition parameter with the preset information according to the type of the condition parameter in the second information corresponding to the determined target attribute parameter, so as to generate the specific process of the SQL template capable of executing SQL, which may refer to the related description in S104 above and is not described here again.
In this way, after the generating device has executed step S1041, the generating device executes the API generated in step S105, in which the data resource corresponding to the target attribute parameter is allowed to be accessed (or called) in an open manner, and the data resource corresponding to the non-target attribute parameter is not allowed to be accessed (or called) in an open manner, that is, the condition parameter corresponding to the non-target attribute parameter is fixed in the SQL template in the API.
Therefore, by the method, the data provider can flexibly select the data resources which are opened and called, and the flexibility of opening the data resources is improved.
In summary, an embodiment of the present application provides a method for generating an API, where based on the method, a generating device parses an executable SQL and generates an SQL template of the executable SQL, and generates an API for accessing data to be queried indicated by the executable SQL based on the SQL template. Compared with the prior art, the method for generating the API simplifies the process of manually configuring the parameters and greatly improves the efficiency of generating the API.
In addition, due to the method provided by the embodiment of the application, the data provider can flexibly control the range of allowing the data resources to be opened to the outside, namely, the flexibility of opening the data resources is improved.
The scheme provided by the embodiment of the application is mainly introduced from the perspective of a method. To implement the above functions, it includes hardware structures and/or software modules for performing the respective functions. Those of skill in the art would readily appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as hardware or combinations of hardware and computer software. Whether a function is performed as hardware or computer software drives hardware depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiment of the present application, the generating device may be divided into the functional modules according to the method example, for example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. It should be noted that, in the embodiment of the present application, the division of the module is schematic, and is only one logic function division, and there may be another division manner in actual implementation.
As shown in fig. 6, fig. 6 is a schematic structural diagram of a generating device 60 provided in an embodiment of the present application. The generating means 60 may be adapted to perform the above-described method of generating an API, for example to perform the method shown in fig. 3, 4 or 5. The generating device 60 may include an acquiring unit 61 and a generating unit 62.
The obtaining unit 61 is configured to obtain an executable structured query statement SQL, where the executable SQL is used to query data to be queried. The generating unit 62 is configured to generate first information according to the executable SQL, where the first information includes a name of an attribute parameter in the executable SQL and a type of a condition parameter in the executable SQL, the attribute parameter is used to indicate an attribute of the data to be queried, and the condition parameter is used to indicate a query condition for querying the data to be queried with the attribute. And the generating unit 62 is further configured to generate second information based on the first information, where the second information is used to indicate a mapping relationship between the position of the condition parameter in the SQL and the first information. The generating unit 62 is further configured to generate an SQL template capable of executing SQL according to the second information. The generating unit 62 is further configured to generate an API for accessing the data to be queried according to the SQL template.
As an example. In conjunction with fig. 3, 4 or 5, the obtaining unit 61 may be configured to execute S101. In conjunction with fig. 3, the generation unit 62 may be configured to perform S102 to S105.
Optionally, the attribute parameter includes a field, and the condition parameter includes a numerical value or a character string.
Optionally, the generating device 60 further includes: the parsing unit 63 is configured to parse the executable SQL into at least one conditional statement unit, where the conditional statement unit includes an attribute parameter and a condition parameter. And an extracting unit 64, configured to extract the attribute parameters and the condition parameters in the at least one conditional statement unit. The generating unit 62 is specifically configured to generate at least one piece of first information based on the attribute parameters and the condition parameters extracted by the extracting unit 64, where the at least one piece of first information corresponds to the at least one conditional statement unit one to one.
As an example. With reference to fig. 3, 4 or 5, the parsing unit 63, the extracting unit 64 and the generating unit 62 may be configured to execute S102.
Optionally, the generating device 60 further includes: a marking unit 65, configured to mark a position of a condition parameter for generating the first information in the executable SQL. The generating unit 62 is further specifically configured to generate the second information based on the address identifier marked in the executable SQL and the first information. Here, the second information corresponds to the first information.
As an example. In conjunction with fig. 3 and 5, the marking unit 65 and the generating unit 62 may be configured to perform S103. In connection with fig. 4, the marking unit 65 and the generating unit 62 may be configured to perform S1031.
Optionally, the generating unit 62 is further specifically configured to replace, according to the second information, the address identifier used for marking the position of the condition parameter in the executable SQL with preset information, so as to obtain the SQL template.
As an example. In conjunction with fig. 3 and 4, the generating unit 62 may be configured to execute S104. In conjunction with fig. 5, the generating unit 62 may be configured to execute S1041.
Optionally, the generating device 60 further includes: a determining unit 66, configured to determine the target attribute parameters allowed to be openly accessed based on the attribute parameters in the executable SQL before the generating unit 62 generates the SQL template of the executable SQL according to the second information. The generating unit 62 is further specifically configured to replace, according to the second information corresponding to the target attribute parameter, the address identifier used for marking the position of the condition parameter corresponding to the target attribute parameter in the executable SQL with preset information, so as to obtain the SQL template.
As an example. In conjunction with fig. 4, the determining unit 66 may be configured to perform S1021, and the generating unit 62 may be configured to perform S104. With reference to fig. 5, the determining unit 66 may be configured to perform S1032, and the generating unit 62 may be configured to perform S1041.
For the detailed description of the above alternative modes, reference may be made to the foregoing method embodiments, which are not described herein again. In addition, for any explanation and beneficial effect description of the generating device 60 provided above, reference may be made to the corresponding method embodiment described above, and details are not repeated.
As an example, in conjunction with fig. 1, the functions implemented by the acquiring unit 61, the generating unit 62, the parsing unit 63, the extracting unit 64, the marking unit 65, and the determining unit 66 in the generating device 60 may be implemented by the processor 11 in fig. 1 executing the program code in the memory 12 in fig. 1.
The embodiment of the present application further provides a chip system 70, as shown in fig. 7, where the chip system 70 includes at least one processor and at least one interface circuit. By way of example, when the system-on-chip 70 includes one processor and one interface circuit, then the one processor may be the processor 71 shown in solid line block in fig. 7 (or the processor 71 shown in dashed line block), and the one interface circuit may be the interface circuit 72 shown in solid line block in fig. 7 (or the interface circuit 72 shown in dashed line block). When the system-on-chip 70 includes two processors and two interface circuits, then the two processors include the processor 71 shown in solid line block in fig. 7 and the processor 71 shown in dashed line block, and the two interface circuits include the interface circuit 72 shown in solid line block in fig. 7 and the interface circuit 72 shown in dashed line block. This is not limitative.
The processor 71 and the interface circuit 72 may be interconnected by wires. For example, the interface circuitry 72 may be used to receive signals (e.g., retrieve executable SQL, etc.). As another example, the interface circuit 72 may be used to send signals to other devices, such as the processor 71. Illustratively, the interface circuit 72 may read instructions stored in the memory and send the instructions to the processor 71. The instructions, when executed by the processor 71, may cause the generating means to perform the various steps in the embodiments described above. Of course, the chip system 70 may also include other discrete devices, which is not specifically limited in this embodiment.
Another embodiment of the present application further provides a computer-readable storage medium, which stores instructions that, when executed on a generating device, perform the steps performed by the generating device in the method flow shown in the foregoing method embodiment.
In some embodiments, the disclosed methods may be implemented as computer program instructions encoded on a computer-readable storage medium in a machine-readable format or encoded on other non-transitory media or articles of manufacture.
Fig. 8 schematically illustrates a conceptual partial view of a computer program product comprising a computer program for executing a computer process on a computing device provided by an embodiment of the application.
In one embodiment, the computer program product is provided using a signal bearing medium 80. The signal bearing medium 80 may include one or more program instructions that, when executed by one or more processors, may provide the functions or portions of the functions described above with respect to fig. 3, 4, or 5. Thus, for example, one or more features described with reference to S101-S105 in FIG. 3 may be undertaken by one or more instructions associated with the signal bearing medium 80. Further, the program instructions in FIG. 8 also describe example instructions.
In some examples, signal bearing medium 80 may comprise a computer readable medium 81, such as, but not limited to, a hard disk drive, a Compact Disc (CD), a Digital Video Disc (DVD), a digital tape, a memory, a read-only memory (ROM), a Random Access Memory (RAM), or the like.
In some embodiments, signal bearing medium 80 may comprise a computer recordable medium 82 such as, but not limited to, memory, read/write (R/W) CDs, R/W DVDs, and the like.
In some implementations, the signal bearing medium 80 may include a communication medium 83, such as, but not limited to, a digital and/or analog communication medium (e.g., a fiber optic cable, a waveguide, a wired communications link, a wireless communication link, etc.).
The signal bearing medium 80 may be communicated by a wireless form of communication medium 83, such as a wireless communication medium conforming to the IEEE 802.11 standard or other transmission protocol. The one or more program instructions may be, for example, computer-executable instructions or logic-implementing instructions.
In some examples, a generating device such as described with respect to fig. 3, 4, or 5 may be configured to provide various operations, functions, or actions in response to one or more program instructions via computer-readable medium 81, computer-recordable medium 82, and/or communication medium 83.
It should be understood that the arrangements described herein are for illustrative purposes only. Thus, those skilled in the art will appreciate that other arrangements and other elements (e.g., machines, interfaces, functions, orders, and groupings of functions, etc.) can be used instead, and that some elements may be omitted altogether depending upon the desired results. In addition, many of the described elements are functional entities that may be implemented as discrete or distributed components or in conjunction with other components, in any suitable combination and location.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented using a software program, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. The processes or functions according to the embodiments of the present application are generated in whole or in part when the instructions are executed on and by a computer. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored on a computer readable storage medium or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wire (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). Computer-readable storage media can be any available media that can be accessed by a computer or can comprise one or more data storage devices, such as servers, data centers, and the like, that can be integrated with the media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.