Disclosure of Invention
The invention aims to provide a method, a device and a system for accessing a postman tool to a database, aiming at the defects of the prior art, and the aim is realized by the following technical scheme.
The invention provides a method for accessing a postman tool to a database in a first aspect, which comprises the following steps:
compiling a database request containing a database operation statement through a postman tool, and sending the database request to a data cloud plug-in;
and the data cloud plug-in acquires database data according to the database operation statement and returns the database data to the postman tool.
In some embodiments of the present application, writing a database request containing a database operation statement by a postman tool includes:
acquiring a database operation statement and a required return data type by a postman tool; the database request is generated by the postman tool using the static service address, the application service address, the database interface function path, and the retrieved database operation statements and return data types.
In some embodiments of the present application, the data cloud plug-in includes an application service and a static service, and the sending of the database request to the data cloud plug-in via a postman tool includes:
sending, by a postman tool, the database request to a static service to which the static service address points; and sending the database request to the application service pointed by the application service address through the static service.
In some embodiments of the present application, the obtaining, by the data cloud plug-in, database data according to the database operation statement includes:
inputting the database operation statement and the return data type as input parameters into a database interface function pointed by the database interface function path by the application service; and acquiring database data according to the database operation statement and the returned data type through the database interface function.
In some embodiments of the present application, obtaining database data according to the database operation statement and the return data type through the database interface function includes:
establishing connection with a database by using preset database configuration; acquiring data in the database by using the database operation statement through the connection; and converting the acquired data according to the type of the returned data to obtain database data.
In some embodiments of the present application, before establishing a connection with a database using a preset database configuration, the method further comprises:
judging whether the database operation statement is a query statement; if yes, executing the step of establishing connection with the database by using preset database configuration.
In some embodiments of the present application, the database configuration includes a connection address, a username, and a password for the database.
In some embodiments of the present application, after the data cloud plug-in returns the database data to the postman tool, the method further comprises:
utilizing, by the postman tool, the database data to assert an interface return value.
A second aspect of the invention provides a postman tool access database apparatus, the apparatus comprising: the data acquisition module on the data request module and the cloud server on the electronic equipment:
the data request module is used for compiling a database request containing database operation statements through a postman tool and sending the database request to the cloud server;
and the data acquisition module is used for acquiring database data by using the database operation statements and returning the database data to the postman tool.
A third aspect of the present invention provides a postman tool access database system, comprising: the system comprises an electronic device and a cloud server;
the electronic equipment is used for generating a database request containing a database operation statement through a postman tool and sending the database request to the cloud server;
and the cloud server is used for acquiring database data by using the database operation statements and returning the database data to the postman tool.
Based on the method, the device and the system for the postman tool to access the database in the first aspect and the third aspect, the method, the device and the system have at least the following advantages or advantages:
the data cloud plug-in for providing the database query service is built between the Postman tool and the database, and the data cloud plug-in realizes the acquisition of dynamic data in the database, so that other plug-in software does not need to be installed for the Postman tool, database operation statements are compiled on the Postman tool by using a common database management language, the dynamic data of the database returned by the data cloud plug-in can be received, and the problem that the Postman tool does not support the access of the database is broken through.
Compared with a jmeter tool with an access database plug-in, the method does not need to be reused after previous configuration is carried out each time, and the database request can be written on the postman tool for permanent use only by once configuration and construction.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the invention, as detailed in the appended claims.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in this specification 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.
It is to be understood that although the terms first, second, third, etc. may be used herein to describe various information, these information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present invention. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
Compared with a jmeter tool, the Postman tool has more complete functions and is often used in the field of software development, but the Postman tool does not support access to a database, so that dynamic data cannot be used for asserting interface return values in the process of using the Postman tool for interface testing, and the coverage of interface testing is limited.
In the prior art, some postmans use an xmysql component to read data in a remote database, that is, by installing a node service on a device and installing the xmysql component, after configuring an environment variable, starting the node service and the xmysql component to connect with the database, and writing a database query statement in a postman tool according to the syntax of the xmysql component.
However, the process of using the xmysql component to access the database postman is cumbersome, requires installation of a plug-in on the device, and also requires writing a database query statement using the syntax of the xmysql component, which also requires the user to spend time learning such syntax to write.
Based on the method, the novel method for accessing the postman tool to the database is provided, namely, the database request containing the database operation statement is compiled through the postman tool, and the database request is sent to the data cloud plug-in, so that the data cloud plug-in acquires the database data by using the database operation statement, and returns the database data to the postman tool, and the function of accessing the postman tool to the database is achieved.
The technical effects that can be achieved based on the above description are:
the data cloud plug-in for providing the database query service is built between the Postman tool and the database, and the data cloud plug-in realizes the acquisition of dynamic data in the database, so that any component service does not need to be installed for the Postman tool, database operation statements are compiled on the Postman tool by using a common database management language, the dynamic data of the database returned by the data cloud plug-in can be received, and the problem that the Postman tool does not support the access of the database is broken through.
Compared with a jmeter tool with an access database plug-in, the method does not need to be reused after previous configuration is carried out each time, and the database request can be written on the postman tool for permanent use only by once configuration and construction.
In order to make the technical solutions better understood by those skilled in the art, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application.
The first embodiment is as follows:
fig. 1 is a flowchart of an embodiment of a method for accessing a database by a postman tool according to an exemplary embodiment of the present invention, in this embodiment, a data cloud plug-in for providing a database query service is set up in advance on a cloud server, so that a postman tool installed on any electronic device can acquire database data through the data cloud plug-in. As shown in fig. 1, the method for accessing a database by a postman tool includes the following steps:
step 101: and compiling a database request containing a database operation statement through a postman tool, and sending the database request to the data cloud plug-in.
In this embodiment, an interface test module (tests module) is provided in the postman tool, and an interface return value can be obtained through an interface request in the interface test module, and if the interface return value needs to be asserted by using dynamic data in the database, a database operation statement needs to be written, so as to generate a database request including the database operation statement and send the database request to the data cloud plug-in.
When a user writes a database operation statement in an interface test module of the postman tool, the database operation statement is written only by using a commonly-used database management Language-Structured Query Language (SQL), so that the method is simple and easy, and compared with the prior art that the database operation statement is written by using the syntax of the xmysql component, a certain learning cost can be saved.
It should be noted that when a data cloud plug-in is built, different languages are used to provide database query services, different application services need to be selected, if a Python language is used, a uWSGI application service needs to be selected, and if a PHP language is used, a PHP-fpm application service needs to be selected. The uWSGI application service can only use an http communication mode for providing external services, but the http communication mode of the uWSGI application service is not stable, so in order to increase the communication stability, a layer of static service is added between the application service and the postman tool to provide http communication for the external services, and the application service is communicated with the external services through a socket.
Based on the static service, a static service can be established between the postman tool and the application service, the static service address and the application service address are preset in the postman tool, and the request forwarding service is provided.
The static service specifically can use nginx static service and is used for forwarding the database request to the data cloud plug-in, and the static service address is composed of an ip address and a port.
The application service is provided with a database interface service for realizing database data acquisition, and the application service address is the api address of the application service.
Therefore, the data cloud plug-in built by the method comprises the application service and the static service, and the data cloud plug-in can be built on a cloud server device so as to reduce the cost of the built hardware.
In an optional specific embodiment, for the specific generation process of the database request, the postman tool obtains the database operation statement and the required return data type, so that the postman tool can generate the database request by using the static service address, the application service address, the database interface function path, and the obtained database operation statement and the obtained return data type.
The database operation statement (SQL statement) and the required return data type (format) are two parameters specified by a user, and the return data type can determine the type of database data returned by the data cloud plug-in.
In one example, the return data types may include an array type (All), an object type (Row), and a string type (Scalar).
All data are acquired from data returned by the database and are combined into database data in an array type; row represents that a piece of data is obtained from data returned by the database, and the data is formed into database data according to the object type; scalar means that a single field is obtained from data returned by a database, and field values of the field are combined into database data in a character string type.
For example, assuming that the database operation statement is to query All student data of a class, if the format is All, All the student data is converted into array type data, if the format is Row, one student data is selected from All the student data and converted into an object type, and if the format is Scalar, a field value of a single field (such as age) is obtained from All the student data and converted into a character string type.
In an optional specific embodiment, when the database request includes a static service address and an application service address, aiming at the process that the postman tool sends the database request to the data cloud plug-in, the postman tool can send the database request to the static service pointed by the static service address through a pre-established http connection, and then the static service sends the database request to the application service pointed by the application service address through a pre-established socket connection, so that stable communication between the postman tool and the application service is realized.
The technical personnel in the field can understand that the built data cloud plug-in can also only comprise an application service, the postman tool directly uses an http communication service provided by the application service to the outside, establishes an http connection with the application service, and directly sends the database request to the application service through the http connection.
Step 102: the data cloud plug-in obtains database data using the database operation statements and returns the database data to the postman tool.
The database data acquired by the data cloud plug-in is dynamic data required by the interface test module on the postman tool for performing assertion operation on the interface return value.
In an optional specific embodiment, in the process of acquiring database data by the data cloud plug-in, the application service inputs a database operation statement and a returned data type as input parameters into a database interface function pointed by a database interface function path, and then acquires the database data according to the database operation statement and the returned data type through the database interface function.
In addition to deploying the database interface service, other services may be deployed in the application service, so that a database interface function path provided by the application service needs to be indicated in the database request, so as to navigate the database request to the database interface function, and implement parameter input.
In a specific embodiment, in a process of acquiring database data according to a database operation statement and a returned data type through a database interface function, a preset database configuration is first used to establish a connection with a database, then through the connection, data in the database is acquired through the database operation statement, and the acquired data is converted according to the returned data type to obtain database data.
For example, if the returned data type is an array type, the acquired data needs to be converted into database data of the array type, if the returned data type is an object type, the acquired data needs to be converted into database data of the object type, and if the returned data type is a character string type, the acquired data needs to be converted into database data of the character string type.
It is noted that the file format of the database data is json format regardless of the type of the database data.
Further, in order to implement the connection of the database, a database configuration needs to be preset, and the database configuration includes a connection address, a user name, and a password of the database.
For example, the connection with the database may be established by ODBC, JDBC, or any other suitable connection.
ODBC (Open Database Connectivity, Open Database interconnection) is an interface standard for realizing communication between an application program and a relational Database, which is introduced by microsoft corporation, and a Database conforming to the standard can operate the Database through a command written in SQL language, but only aims at the relational Database, such as SQL Server, Oracle, Access, Excel, and the like. JDBC (Java Data Base Connectivity) is a class interface written by a group of Java languages developed by Java Soft company and used for connecting and operating databases, and can provide a uniform access mode for multiple relational databases. The connection address of the database may be an ODBC connection address or a JDBC connection address.
In some optional embodiments, the operation types of the database operation statements include a query type (select), an update type (update), a delete type (delete), and an add type (insert intro), so as to avoid a user's misoperation, and make a false change to the database data. The database operation statements may be restricted prior to establishing a connection with the database.
Based on this, before the connection is established with the database by using the preset database configuration, whether the database operation statement is the query statement or not can be judged, if the query statement is the query statement, the connection is established with the database by using the preset database configuration, and if the query statement is not the query statement, the connection with the database is forbidden, so that the misoperation of a user can be effectively avoided by only querying the database data.
It should be noted that after the data cloud plug-in returns the database data to the postman tool, the postman tool can use the database data to perform an assertion operation on the interface return value.
So far, accomplish the access flow that above-mentioned figure 1 shows, through set up a data cloud plug-in that provides database inquiry service between Postman instrument and database, the acquisition of dynamic data in the database is realized by data cloud plug-in to need not for Postman instrument installation other plug-in software, compile database operation statement through using commonly used database management language on the Postman instrument, alright in order to receive the database dynamic data that data cloud plug-in returned, broken through the problem that the Postman instrument does not support the access database.
Compared with a jmeter tool with an access database plug-in, the method does not need to be reused after previous configuration is carried out each time, and the database request can be written on the postman tool for permanent use only by once configuration and construction.
Example two:
fig. 2 is a schematic view of an interaction flow of a postman tool accessing a database according to the embodiment shown in fig. 1, on the basis of the embodiment shown in fig. 1, in this embodiment, an interaction among the postman tool, a data cloud plug-in and the database is taken as an example for detailed description, the data cloud plug-in may only include an application service, as shown in fig. 2, and the interaction flow includes the following steps:
step 201: the postman tool sends a database request containing a database operation statement and a return data type to the data cloud plug-in.
Step 202: and the data cloud plug-in inputs the database operation statement and the returned data type as input parameters into the database interface function.
Step 203: and in the database interface function, establishing connection with the database by using preset database configuration.
Step 204: and in the database interface function, acquiring data in the database by using the database operation statement through the connection.
Step 205: and in the database interface function, converting the acquired data according to the type of the returned data to obtain database data.
Step 206: the data cloud plug-in returns the database data to the postman tool.
For the related description of the above steps 201 to 206, refer to the related description of the embodiment shown in fig. 1, which is not repeated herein.
So far, accomplish the interactive flow that above-mentioned fig. 2 shows, through set up a data cloud plug-in that provides database inquiry service between Postman instrument and database, the acquisition of dynamic data in the database is realized by data cloud plug-in to need not for Postman instrument installation other plug-in software, compile database operation statement through using commonly used database management language on the Postman instrument, alright receive the database dynamic data that data cloud plug-in returned, broken through the problem that the Postman instrument does not support the access database.
Compared with a jmeter tool with an access database plug-in, the method does not need to be reused after previous configuration is carried out each time, and the database request can be written on the postman tool for permanent use only by once configuration and construction.
Example three:
fig. 3 is a schematic view of an interaction flow of another postman tool accessing a database according to the embodiment shown in fig. 1, where on the basis of the embodiment shown in fig. 1, this embodiment takes an example that a data cloud plug-in includes a static service and an application service, and as shown in fig. 3, the interaction flow includes the following steps:
step 301: the postman tool sends a database request containing a database operation statement and a return data type to the static service.
Step 302: the static service forwards the database request containing the database operation statement and the return data type to the application service.
Step 303: the application service inputs the database operation statement and the return data type as input parameters into a database interface function pointed by the database interface function path.
Step 304: and in the database interface function, establishing connection with the database by using preset database configuration.
Step 305: and in the database interface function, acquiring data in the database by using the database operation statement through the connection.
Step 306: and in the database interface function, converting the acquired data according to the type of the returned data to obtain database data.
Step 307: the application service sends the database data to the static service.
Step 308: the static service forwards the database data to the postman tool.
For the related description of the above steps 301 to 308, refer to the related description of the embodiment shown in fig. 1, which is not repeated herein.
So far, accomplish the interactive flow that above-mentioned fig. 3 shows, through set up a data cloud plug-in that provides database inquiry service between Postman instrument and database, the acquisition of dynamic data in the database is realized by data cloud plug-in to need not for Postman instrument installation any subassembly service, compile database operation statement through using the database management language that commonly uses on the Postman instrument, alright in order to receive the database dynamic data that data cloud plug-in returned, broken through the problem that the Postman instrument does not support the access database.
Further, by adding a static service as middleware between the postman tool and the application service, stable communication between the postman tool and the application service is realized.
Example four:
fig. 4 is a schematic structural diagram of a postman tool access database system according to an exemplary embodiment of the present invention, and based on the above embodiment, as shown in fig. 4, the system includes an electronic device 410 and a cloud server 420;
the electronic device 410 is configured to compile a database request including a database operation statement through a postman tool, and send the database request to the cloud server 420;
and the cloud server 420 is configured to obtain database data by using the database operation statements, and return the database data to the postman tool on the electronic device 410.
Specifically, a data cloud plug-in is deployed on the cloud server, and is used for acquiring database data by using a database operation statement and returning the database data to the postman tool on the electronic device 410.
Corresponding to the embodiment of the method for accessing the database by the postman tool, the invention also provides an embodiment of a device for accessing the database by the postman tool.
Fig. 5 is a schematic structural diagram illustrating a postman tool access database apparatus according to an exemplary embodiment of the present invention, the apparatus is configured to execute the postman tool access database method provided in any of the above embodiments, as shown in fig. 5, the postman tool access database apparatus includes a data request module 510 on an electronic device and a data obtaining module 520 on a cloud server;
the data request module 510 is configured to generate a database request including a database operation statement through a postman tool, and send the database request to a cloud server;
the data obtaining module 520 is configured to obtain database data by using the database operation statements, and return the database data to the postman tool.
The implementation process of the functions and actions of each unit in the above device is specifically described in the implementation process of the corresponding step in the above method, and is not described herein again.
For the device embodiments, since they substantially correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the invention. One of ordinary skill in the art can understand and implement it without inventive effort.
Other embodiments of the invention will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the invention and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the invention being indicated by the following claims.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.