Skip to content

Commit 535185a

Browse files
committed
docs: add Cloudflare D1 documentation (en, vi, zh)
1 parent 444ef2e commit 535185a

3 files changed

Lines changed: 659 additions & 0 deletions

File tree

docs/databases/cloudflare-d1.mdx

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
---
2+
title: Cloudflare D1
3+
description: Connect to Cloudflare D1 databases with TablePro
4+
---
5+
6+
# Cloudflare D1 Connections
7+
8+
TablePro supports Cloudflare D1, a serverless SQLite-compatible database. TablePro connects via the Cloudflare REST API using your API token - no direct database connections or SSH tunnels needed.
9+
10+
## Install Plugin
11+
12+
The Cloudflare D1 driver is available as a downloadable plugin. When you select Cloudflare D1 in the connection form, TablePro will prompt you to install it automatically. You can also install it manually:
13+
14+
1. Open **Settings** > **Plugins** > **Browse**
15+
2. Find **Cloudflare D1 Driver** and click **Install**
16+
3. The plugin downloads and loads immediately - no restart needed
17+
18+
## Quick Setup
19+
20+
<Steps>
21+
<Step title="Open Connection Form">
22+
Click **New Connection** from the Welcome screen or **File** > **New Connection**
23+
</Step>
24+
<Step title="Select Cloudflare D1">
25+
Choose **Cloudflare D1** from the database type selector
26+
</Step>
27+
<Step title="Enter Connection Details">
28+
Fill in your database name (or UUID), Cloudflare Account ID, and API token
29+
</Step>
30+
<Step title="Test and Connect">
31+
Click **Test Connection**, then **Create**
32+
</Step>
33+
</Steps>
34+
35+
## Connection Settings
36+
37+
### Required Fields
38+
39+
| Field | Description |
40+
|-------|-------------|
41+
| **Name** | Connection identifier |
42+
| **Database** | D1 database name or UUID |
43+
| **Account ID** | Your Cloudflare account ID |
44+
| **API Token** | Cloudflare API token with D1 permissions |
45+
46+
<Tip>
47+
You can use either the database name (e.g., `my-app-db`) or the database UUID. If you use a name, TablePro resolves it to the UUID automatically via the Cloudflare API.
48+
</Tip>
49+
50+
## Getting Your Credentials
51+
52+
### Account ID
53+
54+
Find your Account ID on the [Cloudflare dashboard](https://dash.cloudflare.com) right sidebar, or run:
55+
56+
```bash
57+
npx wrangler whoami
58+
```
59+
60+
### API Token
61+
62+
1. Go to [Cloudflare API Tokens](https://dash.cloudflare.com/profile/api-tokens)
63+
2. Click **Create Token**
64+
3. Select **Custom token** template
65+
4. Add permission: **Account** > **D1** > **Edit**
66+
5. Save and copy the token
67+
68+
<Warning>
69+
Store your API token securely. TablePro saves it in the macOS Keychain, but the token grants access to all D1 databases in your account.
70+
</Warning>
71+
72+
### Create a D1 Database
73+
74+
If you don't have a D1 database yet:
75+
76+
```bash
77+
# Install Wrangler CLI
78+
npm install -g wrangler
79+
80+
# Login to Cloudflare
81+
wrangler login
82+
83+
# Create a database
84+
wrangler d1 create my-app-db
85+
86+
# Seed with test data
87+
wrangler d1 execute my-app-db --remote \
88+
--command "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)"
89+
wrangler d1 execute my-app-db --remote \
90+
--command "INSERT INTO users VALUES (1, 'Alice', 'alice@example.com')"
91+
```
92+
93+
You can also create databases directly from TablePro using the **Create Database** button in the database switcher.
94+
95+
## Example Configuration
96+
97+
```
98+
Name: My D1 Database
99+
Database: my-app-db
100+
Account ID: abc123def456
101+
API Token: (your Cloudflare API token)
102+
```
103+
104+
## Features
105+
106+
### Database Browsing
107+
108+
After connecting, use the database switcher in the toolbar to list and switch between all D1 databases in your Cloudflare account. The sidebar shows tables and views in the selected database.
109+
110+
### Table Browsing
111+
112+
For each table, TablePro shows:
113+
114+
- **Structure**: Columns with SQLite data types, nullability, default values, and primary key info
115+
- **Indexes**: B-tree indexes with column details
116+
- **Foreign Keys**: Foreign key constraints with referenced tables
117+
- **DDL**: The full CREATE TABLE statement
118+
119+
### Query Editor
120+
121+
Write and execute SQL queries using SQLite syntax:
122+
123+
```sql
124+
-- Query data
125+
SELECT name, email FROM users WHERE id > 10 ORDER BY name;
126+
127+
-- Create tables
128+
CREATE TABLE posts (
129+
id INTEGER PRIMARY KEY AUTOINCREMENT,
130+
user_id INTEGER REFERENCES users(id),
131+
title TEXT NOT NULL,
132+
content TEXT,
133+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
134+
);
135+
136+
-- Aggregations
137+
SELECT user_id, COUNT(*) as post_count
138+
FROM posts
139+
GROUP BY user_id
140+
HAVING post_count > 5;
141+
```
142+
143+
### EXPLAIN Query Plan
144+
145+
Analyze query execution plans using the Explain button in the query editor. TablePro uses `EXPLAIN QUERY PLAN` to show how SQLite processes your queries.
146+
147+
### Data Editing
148+
149+
Edit cell values, insert rows, and delete rows directly in the data grid. Changes are submitted as standard INSERT, UPDATE, and DELETE statements via the D1 API.
150+
151+
### Database Management
152+
153+
- **List Databases**: View all D1 databases in your Cloudflare account
154+
- **Switch Database**: Switch between databases without reconnecting
155+
- **Create Database**: Create new D1 databases directly from TablePro
156+
157+
### Export
158+
159+
Export query results or table data to CSV, JSON, SQL, and other formats.
160+
161+
## SQL Dialect
162+
163+
D1 uses SQLite's SQL syntax. Key points:
164+
165+
- **Identifier quoting**: Double quotes (`"column_name"`)
166+
- **String literals**: Single quotes (`'value'`)
167+
- **Auto-increment**: `INTEGER PRIMARY KEY AUTOINCREMENT`
168+
- **Type affinity**: SQLite's flexible type system applies
169+
- **PRAGMA support**: Most SQLite PRAGMAs work (`PRAGMA table_info`, `PRAGMA foreign_key_list`, etc.)
170+
171+
## Troubleshooting
172+
173+
### Authentication Failed
174+
175+
**Symptoms**: "Authentication failed. Check your API token and Account ID."
176+
177+
**Solutions**:
178+
179+
1. Verify your API token has **D1 Edit** permissions
180+
2. Check that the Account ID matches your Cloudflare account
181+
3. Ensure the token has not expired or been revoked
182+
4. Try creating a new API token
183+
184+
### Database Not Found
185+
186+
**Symptoms**: "Database 'name' not found in account"
187+
188+
**Solutions**:
189+
190+
1. Verify the database name or UUID is correct
191+
2. Check that the database exists: `wrangler d1 list`
192+
3. Ensure your API token has access to the account containing the database
193+
194+
### Rate Limited
195+
196+
**Symptoms**: "Rate limited by Cloudflare"
197+
198+
**Solutions**:
199+
200+
1. Wait for the retry period indicated in the error message
201+
2. Reduce query frequency
202+
3. Use pagination for large result sets instead of fetching all rows
203+
204+
### Connection Timeout
205+
206+
**Symptoms**: Queries take too long or time out
207+
208+
**Solutions**:
209+
210+
1. Check your internet connection
211+
2. Verify the Cloudflare API is operational at [Cloudflare Status](https://www.cloudflarestatus.com)
212+
3. Simplify complex queries that may exceed D1's execution limits
213+
214+
## Known Limitations
215+
216+
- **No persistent connections.** Each query is an independent HTTP request to the Cloudflare API. There is no connection pooling or session state between requests.
217+
- **No transactions.** D1 does not support multi-statement transactions across API calls. Each SQL statement executes independently and auto-commits.
218+
- **No SSH or SSL configuration.** D1 is accessed exclusively via HTTPS through the Cloudflare API. No custom SSL certificates or SSH tunnels are needed or supported.
219+
- **No schema editing UI.** Table structure changes must be done via SQL (ALTER TABLE, etc.) in the query editor.
220+
- **10 GB database limit.** Each D1 database is capped at 10 GB. For larger datasets, consider sharding across multiple databases.
221+
- **API rate limits.** The Cloudflare API has rate limits that may affect heavy usage. TablePro surfaces rate limit errors with retry timing.
222+
- **No import.** Bulk data import is not supported through the plugin. Use `wrangler d1 execute` with SQL files for bulk loading.
223+
224+
## Next Steps
225+
226+
<CardGroup cols={2}>
227+
<Card title="SQL Editor" icon="code" href="/features/sql-editor">
228+
Master the query editor features
229+
</Card>
230+
<Card title="Data Grid" icon="table" href="/features/data-grid">
231+
Browse and edit data in the data grid
232+
</Card>
233+
<Card title="Export" icon="file-export" href="/features/import-export">
234+
Export D1 data to various formats
235+
</Card>
236+
<Card title="Keyboard Shortcuts" icon="keyboard" href="/features/keyboard-shortcuts">
237+
Speed up your workflow
238+
</Card>
239+
</CardGroup>

0 commit comments

Comments
 (0)