Actions5
- Database Actions
- Query Actions
Query → Execute
AI-generatedOverview
This node allows you to execute SQL queries against Cloudflare D1 serverless SQL databases via the Cloudflare API. It is designed for querying and managing D1 databases, with a focus here on executing SQL queries.
Typical use cases include:
- Running parameterized SQL queries on a Cloudflare D1 database.
- Retrieving query results in JSON format for further processing or automation workflows.
- Quickly testing SQL commands against your D1 database from within n8n.
For example, you might use this node to fetch user data by running a SELECT statement with parameters, or to update records using an UPDATE statement.
Properties
| Name | Meaning |
|---|---|
| Database ID | The unique identifier of the Cloudflare D1 database where the SQL query will be executed. |
| SQL Query | The SQL statement to run on the specified database. Supports multi-line input. |
| Query Parameters | A JSON array of parameters to safely inject into the SQL query (for parameterized queries). |
| Performance Warning | Notice that the D1 REST API is not optimized for performance; suggests using a proxy for production. |
Output
The node outputs an array of items, each containing a json property with the following structure:
results: An array containing the rows returned by the SQL query.meta: Optional metadata about the query execution (e.g., execution time, row count).success: Boolean indicating if the query was successful.
If the query fails, the output may contain error information instead.
The node does not output binary data.
Dependencies
- Requires a valid Cloudflare API key credential with permissions to access D1 databases.
- Needs the Cloudflare account ID associated with the D1 database.
- Uses the Cloudflare REST API endpoint:
https://api.cloudflare.com/client/v4.
Troubleshooting
- Invalid Parameters JSON: If the "Query Parameters" field contains invalid JSON or is not an array, the node will throw an error. Ensure the parameters are a valid JSON array.
- Database Not Found: If the provided Database ID is incorrect or the database does not exist, the request will fail.
- API Authentication Errors: Make sure the API token has the necessary permissions and is correctly configured in n8n credentials.
- Performance Issues: The node warns that the D1 REST API is not optimized for high-performance scenarios. For production workloads, consider routing queries through a Cloudflare Worker proxy to improve speed and reliability.
- Error Messages: Errors returned from the API are surfaced with their message. Common errors include authorization failures, malformed SQL, or network issues.