Dify-Plugin-Tools-DBQuery Supported Database Types: Complete Guide
The dify-plugin-tools-dbquery plugin supports five database types: MySQL, Oracle (including Oracle 11g), PostgreSQL, and Microsoft SQL Server, configured via the db_type parameter in db_query/tools/sql_query.yaml.
The dify-plugin-tools-dbquery plugin enables Dify workflows to execute arbitrary SQL queries against external databases. Understanding which database engines are supported and how they are configured in the source code is essential for implementing secure, efficient database integrations.
Supported Database Types in Dify-Plugin-Tools-DBQuery
The plugin defines supported databases as enumerated options in the tool configuration file db_query/tools/sql_query.yaml (lines 16-38). When invoking the tool, the db_type parameter accepts one of five specific values that map to distinct database drivers.
MySQL
Value: mysql
The plugin connects to MySQL databases using the pymysql driver. This supports standard MySQL 5.7+ and MySQL 8.0 installations, including compatible variants like MariaDB and Percona Server.
Oracle and Oracle 11g
Values: oracle, oracle11g
The plugin distinguishes between generic Oracle installations and Oracle 11g specifically. Both use the cx_Oracle driver, but the oracle11g value allows for version-specific connection string formatting and compatibility adjustments handled in db_query/tools/sql_query.py.
PostgreSQL
Value: postgresql
PostgreSQL connections utilize the psycopg2 driver. The plugin supports PostgreSQL 10 through 16, including managed services like Amazon RDS, Azure Database for PostgreSQL, and Google Cloud SQL.
Microsoft SQL Server
Value: mssql
Microsoft SQL Server connectivity is implemented via the pyodbc driver. This supports SQL Server 2016+ and Azure SQL Database, with connection string parameters automatically formatted for ODBC compliance.
How Database Selection Works in the Source Code
The database type selection flows through three critical files in the dify-plugin-tools-dbquery repository.
Tool Definition Configuration
The db_query/tools/sql_query.yaml file declares the db_type parameter as a select field with the five enumerated options:
db_type:
type: select
options:
- value: mysql
label: MySQL
- value: oracle
label: Oracle
- value: oracle11g
label: Oracle11g
- value: postgresql
label: PostgreSQL
- value: mssql
label: Microsoft SQL Server
Provider Registration
The db_query/provider/db_query.yaml file registers the provider and links the sql_query tool, making the database options available to Dify workflows.
Runtime Implementation
The db_query/tools/sql_query.py file implements the runtime logic. It imports the specific DB-API driver based on the db_type value provided in the request:
def _get_connection(self, db_type, host, port, username, password, database):
if db_type == "mysql":
import pymysql
return pymysql.connect(host=host, port=port, user=username, password=password, database=database)
elif db_type == "postgresql":
import psycopg2
return psycopg2.connect(host=host, port=port, user=username, password=password, dbname=database)
elif db_type == "oracle" or db_type == "oracle11g":
import cx_Oracle
dsn = f"{host}:{port}/{database}"
return cx_Oracle.connect(user=username, password=password, dsn=dsn)
elif db_type == "mssql":
import pyodbc
conn_str = f"DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={host},{port};DATABASE={database};UID={username};PWD={password}"
return pyodbc.connect(conn_str)
The driver is imported only when needed, minimizing the runtime footprint and avoiding unnecessary dependencies.
Configuration Examples for Each Database Type
When invoking the dify-plugin-tools-dbquery plugin via the Dify HTTP API, the db_type parameter determines the connection behavior.
MySQL Example
{
"tool_name": "sql_query",
"parameters": {
"db_type": "mysql",
"db_host": "mysql.example.com",
"db_port": 3306,
"db_username": "app_user",
"db_password": "secure_password",
"db_name": "production_db",
"query_sql": "SELECT id, name FROM users WHERE active = 1 LIMIT 100;",
"output_format": "json"
}
}
PostgreSQL Example
{
"tool_name": "sql_query",
"parameters": {
"db_type": "postgresql",
"db_host": "postgres.internal",
"db_port": 5432,
"db_username": "readonly",
"db_password": "pg_secret",
"db_name": "analytics",
"query_sql": "SELECT date_trunc('day', created_at) as day, count(*) FROM events GROUP BY 1 ORDER BY 1 DESC LIMIT 30;",
"output_format": "markdown"
}
}
Oracle 11g Example
{
"tool_name": "sql_query",
"parameters": {
"db_type": "oracle11g",
"db_host": "oracle.legacy.corp",
"db_port": 1521,
"db_username": "SYSTEM",
"db_password": "oracle_pass",
"db_name": "ORCL",
"query_sql": "SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 10;",
"output_format": "json"
}
}
Summary
The dify-plugin-tools-dbquery plugin provides native support for five major relational database systems:
- MySQL via
pymysql - Oracle (generic and 11g-specific) via
cx_Oracle - PostgreSQL via
psycopg2 - Microsoft SQL Server via
pyodbc
Database types are defined in db_query/tools/sql_query.yaml and implemented with lazy-loaded drivers in db_query/tools/sql_query.py, ensuring efficient resource usage while maintaining broad compatibility with enterprise database environments.
Frequently Asked Questions
What database types are supported by the dify-plugin-tools-dbquery plugin?
The plugin supports MySQL, Oracle (including Oracle 11g), PostgreSQL, and Microsoft SQL Server. These options are hard-coded in the db_query/tools/sql_query.yaml configuration file as selectable values for the db_type parameter.
How do I configure the connection for Oracle 11g specifically?
Use the oracle11g value for the db_type parameter instead of the generic oracle option. This ensures the plugin uses connection string formatting compatible with Oracle 11g's specific networking requirements, as implemented in the connection factory within db_query/tools/sql_query.py.
Are database drivers bundled with the plugin or installed separately?
The plugin uses lazy loading for database drivers. The Python implementation in db_query/tools/sql_query.py imports the specific driver (such as pymysql, psycopg2, cx_Oracle, or pyodbc) only when that database type is selected. This minimizes the runtime footprint, but you must ensure the appropriate driver is installed in your Python environment.
Can I connect to cloud-managed databases like Amazon RDS or Azure SQL Database?
Yes. The dify-plugin-tools-dbquery plugin connects to any database endpoint accessible via standard TCP/IP networking. For Amazon RDS MySQL or PostgreSQL, use the standard mysql or postgresql db_type values with the RDS endpoint as the host. For Azure SQL Database, use the mssql db_type with the Azure SQL Server FQDN as the host.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →