← Back to Help

Cloudflare D1 Guide

Everything you need to connect to and work with Cloudflare D1 databases in SQLAgent.

Getting Started

How do I connect to Cloudflare D1?

Select D1 in the database picker, then enter:

Click Connect (or List Databases if no Database ID is set) and you're in. SQLAgent connects via Cloudflare's REST API — no wrangler CLI needed.

How do I create an API token?

Go to dash.cloudflare.com/profile/api-tokens and click Create Token. Select the Custom token template and add:

  • Permission: Account → D1 → Edit
  • Account resource: your account

Copy the token and paste it into SQLAgent. The token is only shown once — store it securely.

Can I browse all my D1 databases?

Yes. Leave the Database ID field empty and click List Databases. SQLAgent will auto-discover all D1 databases in your account and show them in the sidebar.

Is this a wrangler alternative?

For database management, yes. SQLAgent lets you browse, query, and manage your D1 databases visually without touching the terminal. You still need wrangler for deployments, bindings, and worker management — but for day-to-day database work, SQLAgent replaces the command line.

Security & Permissions

Connection security

All D1 connections use HTTPS — your data is always encrypted in transit. No SSL configuration needed, it's automatic.

Security banner

When you enter your API token, SQLAgent shows a security banner:

  • Valid token format (green) — confirms HTTPS encryption, REST API connection, and token authentication
  • Token too short (orange) — Cloudflare API tokens are typically 40+ characters
D1 permissions model

D1 uses token-scoped permissions. Your API token determines what you can do:

  • D1 Read — browse tables, run SELECT queries
  • D1 Edit — full read/write access (required for INSERT, UPDATE, DELETE, and DDL operations)

The security banner reminds you that D1 Edit is required for write operations.

Rate limits

Cloudflare allows 1,200 API requests per 5 minutes. SQLAgent batches operations to stay within limits, but heavy browsing or bulk operations may trigger rate limiting. If you see a rate limit error, wait a few minutes before retrying.

Troubleshooting

D1 authentication failed

Your API token is invalid or doesn't have D1 permissions. Go to the Cloudflare dashboard and verify your token has D1 Edit permissions.

Access denied

The API token exists but lacks the required D1 scope. Edit your token in Cloudflare and add the Account → D1 → Edit permission.

Database ID not found

The D1 database UUID doesn't match any database in your account. Copy the correct ID from Workers & Pages → D1 in your Cloudflare dashboard. Or leave the field empty to list all databases.

Cannot reach Cloudflare API

SQLAgent can't connect to api.cloudflare.com. Check your internet connection. If your network is up, check Cloudflare Status for outages.

Rate limit exceeded

You've hit the Cloudflare API rate limit (1,200 requests per 5 minutes). Wait a few minutes before making more requests. Consider batching your queries to reduce API calls.

D1 SQL Differences

D1 runs SQLite at the edge. If you're coming from MySQL, here are the key differences.

String concatenation

Use || instead of CONCAT():

first_name || ' ' || last_name

Date functions

D1 uses SQLite date functions:

  • datetime('now') instead of NOW()
  • date('now') instead of CURDATE()
  • strftime() instead of DATE_FORMAT()
Schema inspection

D1 doesn't have SHOW or DESCRIBE. Use:

  • Tables: SELECT name FROM sqlite_master WHERE type='table'
  • Columns: PRAGMA table_info('table_name')
  • Indexes: PRAGMA index_list('table_name')
TRUNCATE TABLE

D1 doesn't support TRUNCATE TABLE. Use DELETE FROM table_name instead.

See the full Error Reference for all error messages.