This project will build a web API that allows you to read and write to Cloudflare D1's DB from a browser.
DEMO: Cloudflare D1 Proxy Playground
D1 is a cloud RDB service provided by Cloudflare that uses SQLite.
As of January 25, 2023, it is currently in open alpha and is completely free.
With this project, you can build your own D1 API with just screen operations.
Let's make the most of Cloudflare D1 😆
Warning
Because it is open alpha, there is a possibility that it may become unavailable due to sudden changes in specifications.
Please use it only within the scope of risk that you can tolerate.
- Detailed screen operations are omitted.
-
Register on Cloudflare
-
Create a database on Cloudflare D1
-
Fork this project
-
Connect the forked Git repository to Cloudflare Pages and create a project
- The following settings are required.
Environment variables > Production
Environment variables > PreviewVariable Name Value NODE_VERSION
16 Functions > D1 Database Binding
Variable Name Value D1DB
Database created in step 2 -
Deploy the production environment again
-
Opening the deployed URL will display the Playground screen.
-
Enter the SQL you want to execute in the
SQL
field and the Javascript code will be displayed in thefetch
field.
If you execute it in a browser, the SQL will be executed.
You can also execute it from the screen with therun
button. -
You can download the current state of the DB as a SQLite file with the
dump
button. -
Use of
SQLite Command
query
: Basic operations such asinsert
,update
,delete
,select
execute
: Definition change operations such asCreate Table
- batch is not supported (I missed its existence 💦)
It's dangerous to be able to operate without authentication or to be able to do things like Drop Table 😅
This project is written in Sveltekit and most of the API's Request/Response is in routes/[...path]/+server.ts
.
The codebase is also very small, so please feel free to try customizing it!