Cloudflare D1 Data Connector for Dify
A Dify plugin that allows you to connect to Cloudflare D1 databases, execute SQL queries, and integrate database operations into your AI applications.
Overview
Cloudflare D1 is a serverless SQL database with SQLite semantics, offering:
- Built-in disaster recovery
- Worker and HTTP API access
- Horizontal scaling across multiple smaller databases
- Time Travel for point-in-time recovery
This connector enables seamless integration with Dify's AI workflow, allowing your AI agents to directly query and retrieve data from your D1 databases.
Features
- SQL Query Execution: Execute SQL queries against Cloudflare D1 databases
- Token Verification: Verify Cloudflare API token validity
- Parameterized Queries: Support for secure parameterized SQL queries
- Error Handling: Comprehensive error reporting and handling
Setup Requirements
Prerequisites
- A Cloudflare account
- At least one D1 database created
- API token with D1 access permissions
Required Credentials
-
Cloudflare API Token:
-
Cloudflare Account ID:
Database Information
For each query, you'll need:
- Database ID: The unique identifier of your D1 database
- SQL Query: The query to execute
- Parameters (optional): Values for parameterized queries
Response Format
The connector has two types of responses:
-
Success Response: Returns a JSON object with:
- : Boolean value true
- : Complete Cloudflare D1 execution result that may containing:
- Query results
- Execution metadata
- Status information
-
Error Response:
- Raises an exception start with error type
- Includes with error information
- Stops execution and triggers Dify's error handling
Example Success Response:
Error Handling
The connector provides detailed error information when queries fail:
- API Errors: Returns specific Cloudflare API error codes and messages
- HTTP Errors: Returns status codes and error details
- Connection Errors: Provides relevant connection error information
Since it might fail, it is recommended to enable Dify's retry and error handling.
Best Practices
- Use Parameterized Queries: Always use parameter placeholders () for dynamic values
- Verify Tokens: Test API token validity with the verification tool before executing queries
- Handle Errors: Always implement proper error handling in your applications
Limitations
Additional Resources