Cloudflare D1 icon

Cloudflare D1

Query and manage Cloudflare D1 serverless SQL databases

Actions5

Overview

This node allows users to interact with Cloudflare D1 serverless SQL databases by executing raw SQL queries directly against a specified database. It is particularly useful for advanced users who want full control over their SQL commands, including complex queries or operations not covered by higher-level abstractions.

Common scenarios include:

  • Running custom SELECT, INSERT, UPDATE, DELETE, or other SQL statements on a Cloudflare D1 database.
  • Executing parameterized queries to safely inject variables into SQL commands.
  • Retrieving raw query results and metadata for further processing or integration.

For example, a user might execute a raw SQL query to fetch all records from a table with specific filtering conditions or perform batch updates using parameterized inputs.

Properties

Name Meaning
Database ID The unique identifier of the Cloudflare D1 database where the SQL query will be executed.
SQL Query The actual SQL statement to run against the database. Supports multiline SQL editing.
Query Parameters JSON array of parameters to safely substitute into the SQL query (for parameterized queries).
Performance Warning Notice that the D1 REST API is not optimized for high performance; suggests using a proxy for production.

Output

The node outputs an array of items, each containing a json object with the following structure when executing queries:

  • 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 operation is not a query (not applicable here since only "Execute Raw" under Query resource is considered), it would output the raw result or success status.

No binary data output is produced by this node.

Dependencies

  • Requires a valid Cloudflare API key credential with permissions to access D1 databases.
  • Needs the Cloudflare account ID associated with the API key.
  • Uses Cloudflare's REST API endpoint: https://api.cloudflare.com/client/v4.
  • n8n must be configured with the appropriate credentials to authenticate requests.

Troubleshooting

  • Invalid Parameters JSON: If the "Query Parameters" field contains invalid JSON or is not an array, the node throws an error. Ensure the parameters are a valid JSON array.
  • Database Not Found: If the provided Database ID does not exist or is incorrect, the request will fail.
  • API Authentication Errors: Missing or invalid API tokens will cause authentication failures.
  • Performance Issues: The node warns that the D1 REST API is not optimized for performance. For heavy or production workloads, consider using a Cloudflare Worker as a proxy to improve speed and reliability.
  • Error Messages: The node surfaces error messages returned by the Cloudflare API. Common errors include syntax errors in SQL, permission issues, or malformed requests. Review the error message for details and adjust accordingly.

Links and References

Discussion