[go: up one dir, main page]

CN114153864A - Method and device for generating API - Google Patents

Method and device for generating API Download PDF

Info

Publication number
CN114153864A
CN114153864A CN202010931464.XA CN202010931464A CN114153864A CN 114153864 A CN114153864 A CN 114153864A CN 202010931464 A CN202010931464 A CN 202010931464A CN 114153864 A CN114153864 A CN 114153864A
Authority
CN
China
Prior art keywords
information
sql
parameter
generating
executable
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
CN202010931464.XA
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.)
Huawei Cloud Computing Technologies Co Ltd
Original Assignee
Huawei Cloud Computing Technologies 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 Huawei Cloud Computing Technologies Co Ltd filed Critical Huawei Cloud Computing Technologies Co Ltd
Priority to CN202010931464.XA priority Critical patent/CN114153864A/en
Priority to PCT/CN2021/116824 priority patent/WO2022048676A1/en
Publication of CN114153864A publication Critical patent/CN114153864A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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 OR CALCULATING; 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
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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 OR CALCULATING; 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
    • G06F16/252Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Stored Programmes (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请公开了一种生成API的方法及装置,涉及计算机领域,该方法能够提高生成API的效率。该方法包括:获取用于查询待查询数据的可执行结构化查询语句SQL;根据该可执行SQL确定第一信息;基于该第一信息生成第二信息;根据该第二信息生成该可执行SQL的SQL模板;根据该SQL模板,生成API,该API用于访问待查询数据;其中,第一信息包括可执行SQL中属性参数的名称和该可执行SQL中条件参数的类型,该属性参数用于指示待查询数据的属性,该条件参数用于指示查询具有属性的待查询数据的查询条件;第二信息用于指示条件参数在SQL中的位置,与第一信息的映射关系。

Figure 202010931464

The present application discloses a method and apparatus for generating an API, relating to the field of computers, and the method can improve the efficiency of generating an API. The method includes: acquiring an executable structured query statement SQL for querying data to be queried; determining first information according to the executable SQL; generating second information based on the first information; generating the executable SQL according to the second information The SQL template; according to the SQL template, generate an API, and the API is used to access the data to be queried; wherein, the first information includes the name of the attribute parameter in the executable SQL and the type of the conditional parameter in the executable SQL, and the attribute parameter uses For indicating the attribute of the data to be queried, the condition parameter is used to indicate the query condition for querying the data to be queried with the attribute; the second information is used to indicate the position of the condition parameter in SQL and the mapping relationship with the first information.

Figure 202010931464

Description

Method and device for generating API
Technical Field
The present application relates to the field of computers, and in particular, to a method and an apparatus for generating an Application Programming Interface (API).
Background
The application based on the internet is becoming more and more popular, and more application providers open own data resources to other developers for calling, so that the data resources are opened, and a higher value is obtained.
Typically, application providers enable the opening of data resources by creating and opening APIs on an API service platform. That is, the application provider can open the API to other developers, so that the other developers can integrate the data resources provided by the open API into their own application services. That is, other developers may call the opened data resources through the opened API.
However, in the conventional API creation process, the API is generated mainly by means of parameters manually configured by a developer of an application provider and a Structured Query Language (SQL) template, and the flow of the development process is usually long. Moreover, when the SQL related to the developed API is very complex, the workload of the developer is very large, and the error probability is high.
Disclosure of Invention
The application provides a method and a device for generating an API, which can improve the efficiency of generating the API.
In order to achieve the above purpose, the present application provides the following technical solutions:
in a first aspect, the present application provides a method for generating an application programming interface API, the method comprising: and acquiring an executable structured query statement SQL for querying data to be queried. First information is generated from the executable SQL. Second information is generated based on the first information. And generating an SQL template capable of executing SQL according to the second information. And generating an API for accessing the data to be queried according to the SQL template. The first information comprises the name of an attribute parameter in the executable SQL and the type of a condition parameter in the executable SQL, wherein the attribute parameter is used for indicating the attribute of the data to be queried, and the condition parameter is used for indicating the query condition for querying the data to be queried with the attribute. The second information is used for indicating the position of the condition parameter in the SQL and the mapping relation with the first information.
Based on the method for generating the API provided by the application, the device for generating the API generates the SQL template of the executable SQL by processing the attribute parameters and the condition parameters of the executable SQL, and then the device for generating the API can generate the API for accessing the 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 flow of manual configuration parameters and greatly improves the efficiency of generating the API.
In one possible design, the attribute parameter includes a field, and the condition parameter includes a numerical value or a character string.
In another possible design, the "determining the first information according to the executable SQL" includes: the executable SQL is analyzed into at least one conditional statement unit, and the conditional statement unit comprises an attribute parameter and a condition parameter. And extracting the attribute parameters and the condition parameters in the at least one conditional statement unit. And generating at least one piece of first information on the basis of the extracted attribute parameters and the extracted condition parameters, wherein the at least one piece of first information is in one-to-one correspondence with the at least one conditional statement unit.
In another possible design, the "generating the second information based on the first information" includes: the location of the condition parameter for generating the first information is marked in the executable SQL described above. And generating second information based on the address identifier marked in the executable SQL and the first information, wherein the second information corresponds to the first information.
In another possible design, the "generating an SQL template capable of executing SQL according to the second information" includes: and replacing the address identifier for marking the position of the condition parameter in the executable SQL with preset information according to the second information to obtain the SQL template.
In another possible design, before the "generating an SQL template capable of executing SQL according to the second information" mentioned above, the method further includes: target property parameters that are allowed to be openly accessed are determined based on the property parameters in the executable SQL. The "generating the SQL template capable of executing SQL according to the second information" includes: and replacing the address identifier for marking the position of the condition parameter corresponding to the target attribute parameter in the executable SQL by preset information according to the second information corresponding to the determined target attribute parameter so as to obtain the SQL template.
Through the possible design mode, the data provider can flexibly control the range of data resources allowed to be opened to the outside, namely, the flexibility of data resource opening is improved.
In a second aspect, the present application provides an apparatus for generating an application programming interface API.
In one possible design, the apparatus for generating an API is configured to perform any one of the methods provided in the first aspect. The present application may divide the functional modules of the apparatus for generating API according to any one of the methods provided in the first aspect. For example, the functional blocks may be divided for the respective functions, or two or more functions may be integrated into one processing block. For example, the apparatus for generating the API may be divided into an obtaining unit and a generating unit according to functions. The above description of possible technical solutions and beneficial effects executed by each divided functional module may refer to the technical solutions provided by the first aspect or the corresponding possible designs thereof, and will not be described herein again.
In another possible design, the means for generating the API includes: the memory is coupled to the one or more processors. The memory is for storing computer instructions which the processor is adapted to invoke in order to perform any of the methods as provided by the first aspect and any of its possible designs.
In a third aspect, the present application provides a computer-readable storage medium, such as a computer non-transitory readable storage medium. Having stored thereon a computer program (or instructions) which, when run on an apparatus for generating an API, causes the apparatus for generating an API to perform any of the methods provided by any of the possible implementations of the first aspect described above.
In a fourth aspect, the present application provides a computer program product enabling any of the methods provided by any of the possible implementations of the first aspect to be performed when the product is run on an apparatus that generates an API.
In a fifth aspect, the present application provides a chip system, comprising: and the processor is used for calling and running the computer program stored in the memory from the memory and executing any one of the methods provided by the implementation mode in the first aspect.
It is understood that any one of the apparatuses, computer storage media, computer program products, or chip systems provided above can be applied to the corresponding methods provided above, and therefore, the beneficial effects achieved by the apparatuses, the computer storage media, the computer program products, or the chip systems can refer to the beneficial effects in the corresponding methods, and are not described herein again.
In the present application, the names of the above-mentioned apparatuses for generating APIs do not limit the devices or functional modules themselves, and in actual implementation, the devices or functional modules may appear by other names. Insofar as the functions of the respective devices or functional modules are similar to those of the present application, they fall within the scope of the claims of the present application and their equivalents.
These and other aspects of the present application will be more readily apparent from the following description.
Drawings
Fig. 1 is a schematic hardware structure diagram of an apparatus for generating an API according to an embodiment of the present application;
fig. 2 is a schematic diagram of a data access system according to an embodiment of the present application;
fig. 3 is a first flowchart illustrating a method for generating an API according to an embodiment of the present application;
fig. 4 is a second flowchart illustrating a method for generating an API according to an embodiment of the present application;
fig. 5 is a third flowchart illustrating a method for generating an API according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of an apparatus for generating an API according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a chip system according to an embodiment of the present disclosure;
fig. 8 is a schematic structural diagram of a computer program product according to an embodiment of the present application.
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.

Claims (14)

1.一种生成应用程序编程接口API的方法,其特征在于,包括:1. a method for generating application programming interface API, is characterized in that, comprises: 获取可执行结构化查询语句SQL,所述可执行SQL用于查询待查询数据;Obtaining executable structured query statement SQL, the executable SQL is used to query data to be queried; 根据所述可执行SQL生成第一信息,所述第一信息包括所述可执行SQL中属性参数的名称和所述可执行SQL中条件参数的类型,所述属性参数用于指示所述待查询数据的属性,所述条件参数用于指示查询具有所述属性的待查询数据的查询条件;Generate first information according to the executable SQL, the first information includes the name of the attribute parameter in the executable SQL and the type of the condition parameter in the executable SQL, the attribute parameter is used to indicate the to-be-queried the attribute of the data, the condition parameter is used to indicate a query condition for querying the data to be queried with the attribute; 基于所述第一信息生成第二信息,所述第二信息用于指示所述条件参数在所述SQL中的位置,与所述第一信息的映射关系;generating second information based on the first information, where the second information is used to indicate the position of the condition parameter in the SQL and the mapping relationship with the first information; 根据所述第二信息生成所述可执行SQL的SQL模板;Generate the SQL template of the executable SQL according to the second information; 根据所述SQL模板,生成所述API,所述API用于访问所述待查询数据。The API is generated according to the SQL template, and the API is used to access the data to be queried. 2.根据权利要求1所述的方法,其特征在于,所述属性参数包括字段,所述条件参数包括数值或字符串。2 . The method according to claim 1 , wherein the attribute parameter comprises a field, and the condition parameter comprises a numerical value or a character string. 3 . 3.根据权利要求1或2所述的方法,其特征在于,所述根据所述可执行SQL确定第一信息,具体包括:3. The method according to claim 1 or 2, wherein the determining the first information according to the executable SQL specifically comprises: 将所述可执行SQL解析为至少一个条件语句单元,一个所述条件语句单元包括一个属性参数和一个条件参数;Parse the executable SQL into at least one conditional statement unit, and one of the conditional statement units includes an attribute parameter and a conditional parameter; 提取所述至少一个条件语句单元中的属性参数和条件参数;extracting attribute parameters and condition parameters in the at least one conditional statement unit; 基于所提取的属性参数和条件参数,生成至少一个第一信息,所述至少一个第一信息和所述至少一个条件语句单元一一对应。Based on the extracted attribute parameters and condition parameters, at least one piece of first information is generated, and the at least one piece of first information is in one-to-one correspondence with the at least one conditional statement unit. 4.根据权利要求1-3中任一项所述的方法,其特征在于,所述基于所述第一信息生成第二信息,具体包括:4. The method according to any one of claims 1-3, wherein the generating the second information based on the first information specifically comprises: 在所述可执行SQL中对用于生成所述第一信息的条件参数的位置进行标记;marking the position of the conditional parameter for generating the first information in the executable SQL; 基于在所述可执行SQL中所标记的地址标识和所述第一信息,生成所述第二信息,所述第二信息和所述第一信息对应。The second information is generated based on the address identifier marked in the executable SQL and the first information, and the second information corresponds to the first information. 5.根据权利要求1-4中任一项所述的方法,其特征在于,所述根据所述第二信息生成所述可执行SQL的SQL模板,具体包括:5. The method according to any one of claims 1-4, wherein the generating the SQL template of the executable SQL according to the second information specifically comprises: 根据所述第二信息,将用于标记所述可执行SQL中条件参数位置的地址标识替换为预设信息,以得到所述SQL模板。According to the second information, the address identifier used to mark the position of the conditional parameter in the executable SQL is replaced with preset information, so as to obtain the SQL template. 6.根据权利要求1-4中任一项所述的方法,其特征在于,在所述根据所述第二信息生成所述可执行SQL的SQL模板之前,所述方法还包括:6. The method according to any one of claims 1-4, characterized in that, before the generating the SQL template of the executable SQL according to the second information, the method further comprises: 基于所述可执行SQL中的属性参数,确定允许被开放式访问的目标属性参数;Based on the attribute parameters in the executable SQL, determine the target attribute parameters that are allowed to be openly accessed; 所述根据所述第二信息生成所述可执行SQL的SQL模板,具体包括:The generating the SQL template of the executable SQL according to the second information specifically includes: 根据所述目标属性参数对应的第二信息,将用于标记所述可执行SQL中的所述目标属性参数对应条件参数位置的地址标识,替换为预设信息,以得到所述SQL模板。According to the second information corresponding to the target attribute parameter, the address identifier used to mark the position of the condition parameter corresponding to the target attribute parameter in the executable SQL is replaced with preset information to obtain the SQL template. 7.一种生成应用程序编程接口API的装置,其特征在于,所述装置包括:7. A device for generating an application programming interface API, wherein the device comprises: 获取单元,用于获取可执行结构化查询语句SQL,所述可执行SQL用于查询待查询数据;an obtaining unit, configured to obtain executable structured query statement SQL, where the executable SQL is used to query data to be queried; 生成单元,用于根据所述可执行SQL生成第一信息,所述第一信息包括所述可执行SQL中属性参数的名称和所述可执行SQL中条件参数的类型,所述属性参数用于指示所述待查询数据的属性,所述条件参数用于指示查询具有所述属性的待查询数据的查询条件;以及,用于基于所述第一信息生成第二信息,所述第二信息用于指示所述条件参数在所述SQL中的位置,与所述第一信息的映射关系;以及,用于根据所述第二信息生成所述可执行SQL的SQL模板;以及,用于根据所述SQL模板,生成所述API,所述API用于访问所述待查询数据。A generating unit, configured to generate first information according to the executable SQL, where the first information includes the name of the attribute parameter in the executable SQL and the type of the condition parameter in the executable SQL, the attribute parameter is used for Indicates the 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, for generating second information based on the first information, and the second information uses for indicating the position of the conditional parameter in the SQL, the mapping relationship with the first information; and for generating the SQL template of the executable SQL according to the second information; The SQL template is used to generate the API, and the API is used to access the data to be queried. 8.根据权利要求7所述的装置,其特征在于,所述属性参数包括字段,所述条件参数包括数值或字符串。8. The apparatus according to claim 7, wherein the attribute parameter comprises a field, and the condition parameter comprises a numerical value or a character string. 9.根据权利要求7或8所述的装置,其特征在于,所述装置还包括:9. The device according to claim 7 or 8, wherein the device further comprises: 解析单元,用于将所述可执行SQL解析为至少一个条件语句单元,一个所述条件语句单元包括一个属性参数和一个条件参数;a parsing unit, configured to parse the executable SQL into at least one conditional statement unit, and one of the conditional statement units includes an attribute parameter and a conditional parameter; 提取单元,用于提取所述至少一个条件语句单元中的属性参数和条件参数;an extraction unit for extracting attribute parameters and conditional parameters in the at least one conditional statement unit; 所述生成单元,具体用于基于所述提取单元提取的属性参数和条件参数,生成至少一个第一信息,所述至少一个第一信息和所述至少一个条件语句单元一一对应。The generating unit is specifically configured to generate at least one first piece of information based on the attribute parameter and the conditional parameter extracted by the extracting unit, and the at least one first piece of information is in one-to-one correspondence with the at least one conditional statement unit. 10.根据权利要求7-9中任一项所述的装置,其特征在于,所述装置还包括:10. The device according to any one of claims 7-9, wherein the device further comprises: 标记单元,用于在所述可执行SQL中对用于生成所述第一信息的条件参数的位置进行标记;a marking unit, configured to mark the position of the conditional parameter used to generate the first information in the executable SQL; 所述生成单元,还具体用于基于在所述可执行SQL中所标记的地址标识和所述第一信息,生成所述第二信息,所述第二信息和所述第一信息对应。The generating unit is further specifically configured to generate the second information based on the address identifier marked in the executable SQL and the first information, where the second information corresponds to the first information. 11.根据权利要求7-10中任一项所述的装置,其特征在于,11. The device according to any one of claims 7-10, characterized in that, 所述生成单元,还具体用于根据所述第二信息,将用于标记所述可执行SQL中条件参数位置的地址标识替换为预设信息,以得到所述SQL模板。The generating unit is further specifically configured to, according to the second information, replace the address identifier used to mark the position of the conditional parameter in the executable SQL with preset information, so as to obtain the SQL template. 12.根据权利要求7-10中任一项所述的装置,其特征在于,所述装置还包括:12. The device according to any one of claims 7-10, wherein the device further comprises: 确定单元,用于在所述生成单元根据所述第二信息生成所述可执行SQL的SQL模板之前,基于所述可执行SQL中的属性参数,确定允许被开放式访问的目标属性参数;a determining unit, configured to, before the generating unit generates the SQL template of the executable SQL according to the second information, based on the attribute parameters in the executable SQL, determine the target attribute parameters that are allowed to be openly accessed; 所述生成单元,还具体用于根据所述目标属性参数对应的第二信息,将用于标记所述可执行SQL中的所述目标属性参数对应条件参数位置的地址标识,替换为预设信息,以得到所述SQL模板。The generating unit is further specifically configured to, according to the second information corresponding to the target attribute parameter, replace the address identifier used to mark the position of the condition parameter corresponding to the target attribute parameter in the executable SQL with preset information , to get the SQL template. 13.一种生成应用程序编程接口API的装置,其特征在于,所述装置包括:存储器和一个或多个处理器,所述存储器用于存储计算机指令,所述处理器用于调用所述计算机指令,以执行如权利要求1-6中任一项所述的方法。13. An apparatus for generating an application programming interface (API), wherein the apparatus comprises: a memory and one or more processors, wherein the memory is used to store computer instructions, and the processor is used to invoke the computer instructions , to perform the method of any one of claims 1-6. 14.一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有计算机程序,当所述计算机程序在计算机上运行时,使得所述计算机执行权利要求1-6中任一项所述的方法。14. A computer-readable storage medium, characterized in that, a computer program is stored on the computer-readable storage medium, and when the computer program runs on a computer, the computer is made to execute any one of claims 1-6. one of the methods described.
CN202010931464.XA 2020-09-07 2020-09-07 Method and device for generating API Pending CN114153864A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202010931464.XA CN114153864A (en) 2020-09-07 2020-09-07 Method and device for generating API
PCT/CN2021/116824 WO2022048676A1 (en) 2020-09-07 2021-09-07 Api generation method and apparatus

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010931464.XA CN114153864A (en) 2020-09-07 2020-09-07 Method and device for generating API

Publications (1)

Publication Number Publication Date
CN114153864A true CN114153864A (en) 2022-03-08

Family

ID=80461603

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010931464.XA Pending CN114153864A (en) 2020-09-07 2020-09-07 Method and device for generating API

Country Status (2)

Country Link
CN (1) CN114153864A (en)
WO (1) WO2022048676A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116233251B (en) * 2022-12-12 2025-08-22 中国联合网络通信集团有限公司 Information prompt method, device, electronic device and storage medium
CN116610693B (en) * 2023-04-28 2026-01-13 兴业银行股份有限公司 Method and device for generating structured query statement and computer equipment

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130054630A1 (en) * 2011-08-30 2013-02-28 International Business Machines Corporation Pre-generation of structured query language (sql) from application programming interface (api) defined query systems
CN103473306A (en) * 2013-09-10 2013-12-25 北京思特奇信息技术股份有限公司 Method and system for adopting structured query language (SQL) mark substitution method to achieve data self-extraction
CN109857756A (en) * 2019-01-14 2019-06-07 中国联合网络通信集团有限公司 Generation method, device, equipment and the readable storage medium storing program for executing of Database Report

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100456237C (en) * 2007-01-31 2009-01-28 华为技术有限公司 Database access method and device
WO2015155561A1 (en) * 2014-04-10 2015-10-15 Siemens Aktiengesellschaft . Accessing non-relational data stores using structured query language queries
CN108170426B (en) * 2018-01-15 2020-06-05 浙江大学 RESTful API code automatic generation method based on body
CN108388622B (en) * 2018-02-12 2020-02-28 平安科技(深圳)有限公司 API interface dynamic generation method and device, computer equipment and storage medium
CN110392068B (en) * 2018-04-17 2022-06-21 阿里巴巴集团控股有限公司 Data transmission method, device and equipment
CN109144512B (en) * 2018-08-22 2022-05-03 杭州数澜科技有限公司 Method and system for generating API
CN111381820A (en) * 2018-12-29 2020-07-07 北京数聚鑫云信息技术有限公司 Method and device for automatically generating API based on GUI

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130054630A1 (en) * 2011-08-30 2013-02-28 International Business Machines Corporation Pre-generation of structured query language (sql) from application programming interface (api) defined query systems
CN103473306A (en) * 2013-09-10 2013-12-25 北京思特奇信息技术股份有限公司 Method and system for adopting structured query language (SQL) mark substitution method to achieve data self-extraction
CN109857756A (en) * 2019-01-14 2019-06-07 中国联合网络通信集团有限公司 Generation method, device, equipment and the readable storage medium storing program for executing of Database Report

Also Published As

Publication number Publication date
WO2022048676A1 (en) 2022-03-10

Similar Documents

Publication Publication Date Title
CN113065656B (en) A rule engine configuration method, device, server and readable storage medium
US11670288B1 (en) Generating predicted follow-on requests to a natural language request received by a natural language processing system
US11645471B1 (en) Determining a relationship recommendation for a natural language request
US12282500B1 (en) Providing completion recommendation variations for a partial natural language request
US11288319B1 (en) Generating trending natural language request recommendations
CN111538651B (en) Interface testing method, device, server and storage medium
CN109343983B (en) Information interaction method, device, equipment and storage medium between function modules
CN108959294B (en) A method and apparatus for accessing a search engine
CN110019080A (en) Data access method and device
CN109739872B (en) Implementation method, system and operation method for SQL sentence processing
CN114238459A (en) A method, device and system for integrated management of heterogeneous data sources
CN114996554A (en) Database query method, device, storage medium and electronic device
CN111563218A (en) Page repairing method and device
CN114356991A (en) Data query method, data aggregation method, device, equipment and medium
CN113055410B (en) Cloud resource management method, device, equipment, system and readable storage medium
CN116303542A (en) SQL statement execution method and device, computer equipment, storage medium
CN114153864A (en) Method and device for generating API
CN107515866B (en) Data operation method, device and system
CN112130860B (en) JSON object analysis method and device, electronic equipment and storage medium
CN112883088B (en) Data processing method, device, equipment and storage medium
CN112015497A (en) Skin changing method and device
CN115878860A (en) Method, device, server device and medium for generating a menu
CN111694586A (en) Program initialization method, program initialization device, terminal device, and storage medium
CN116049493A (en) Multi-level enterprise relationship graph generation method, system and electronic equipment
CN112925655B (en) Decoupled system and method for dividing services

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