Skip to main content

Database Operations

Pre Processors and Post Processors support adding databases. After selecting and connecting to a database, you can perform CRUD and more on the data tables. The results of these operations can be printed in the console or extracted as variables. These variables can then be used in various scenarios, such as parameters for other endpoint requests, assertions, custom scripts, and interacting with other databases.

The following SQL relational databases are supported:

The following NoSQL databases are supported:

  • MongoDB
  • Redis

Creating a Database

  1. Navigate to "Pre Processors/Post Processors", click on "Add PreProcessor" or "Add PostProcessor", and select "Database Operation". Then, create a new database connection. By default, different environments share the same database connection configuration, but you can also set up separate and independent configurations for each environment.

  1. Click on "Database Connections", then select "Manage Database Connections" on the dropdown menu and click the new button in the upper right corner.

  1. Select database type and then fill in the connection information for the database.

  1. In addition to connecting to a database locally using a username and password, you can also connect database through an SSH tunnel for enhanced security.

tip

Apidog values your data security. Database address, port, username, password, and database name are only stored on the client side locally and are not synced to the cloud. Even within the same team, members do not sync their database connection information with each other, and each team member needs to manually set up their database.

Operating Databases

NoSQL Databases

For operations on NoSQL databases (MongoDB), please refer to this document.

Relational Databases

If you are connected to a relational database, you can directly enter SQL commands in the command box to perform operations.

For example:

  1. Enter the command SELECT * FROM user LIMIT 2, then check the "Console Log", and the corresponding results will appear in the console at the bottom.
  2. Extract the query as three variables: allUser,user,userName.

If the SQL query result is as follows,

[
{
id: 1,
name: "jack",
},
{
id: 2,
name: "peter",
},
];

the extracted value of the variables will be the following:

  1. The value of allUser(temporary array variable) is:
[
{
id: 1,
name: "jack",
},
{
id: 2,
name: "peter",
},
];
  1. The value of user(object variable) is:
{
"id": 1,
"name": "jack",
}
  1. The value of userName(string variable) is:
jack;

MySQL FAQ

Currently, the latest mysql modules do not fully support the caching_sha2_password encryption method of MySQL8, where caching_sha2_password is the default encryption method.

Please use the method that requires you to specify the mysql_native_password mode to change the MySQL account password, use another tool to connect to MySQL, and then run the following SQL to change the password of the corresponding account.

ALTER USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY '123456'
tip

Please replace username and password above manually.