Overview
Pre/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.
Getting started
Here are the steps to use database operations.
SELECT * FROM User where username = '{{name}}'
The SELECT statement retrieves an array of results where each row represents an element in the array. For example, using the JSONPath $[0].uid
would extract the value of the "uid" field from the first row of the results.
Click Send to execute the request. You can view the database operation's results in the Console.
:::tip[]
Apidog supports standard SQL queries but does not accommodate complex SQL operations like stored procedures.
:::
Database connections
Apidog Free supports connections to the following types of databases:
- MySQL
- SQLServer(Supports versions above SQL Server 2014)
- Oracle
- PostgreSQL
After upgrading to the paid version, Apidog also supports connectivity to the following databases in addition:
- Clickhouse
- MongoDB
- Redis
:::tip[]
Connecting to an Oracle database in Apidog requires installing the Oracle Client separately.
:::
To set up a database connection in Apidog, follow the steps:
:::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.
:::
:::tip[MySQL Tips]
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'
Please replace username and password above manually.
:::
Using database operations in multiple environments
When working with multiple environments such as testing and production environments, they often have different databases configured. If you are using database operations in your workflows, it implies that these operations need to switch along with the environment changes.
In such scenarios, you can configure multiple database connections under the "Database Connections" settings in Apidog. By setting up database connections for each environment, you can ensure that when switching between environments using the dropdown menu in the top right corner, the database queries will automatically be directed to the corresponding database connection associated with that environment.
Using NoSQL databases
For operations on MongoDB, refer to MongoDB operations.
For operations on Redis, refer to Redis operations.
Using database operations in Apidog CLI
Apidog supports executing test scenarios on any platform using the Command Line Interface (CLI). By utilizing the CLI, you can fetch test scenario configurations from the server in real-time and run them efficiently.
However, since database operations are locally stored, it means that the CLI cannot dynamically access your database configurations.
In such cases, you need to export your database operations as configuration files and place them on the machine where the CLI is being run. Learn more about Apidog CLI.
FAQ
Q: Can I combine multiple SQL queries into a single database operation in Apidog?
A: Each database operation in Apidog can only execute one SQL query. If you have multiple SQL queries to run, they need to be divided into separate database operations for execution.