SvelteKit and Cloudflare D1
This guide will provide a step-by-step process for building and deploying a SvelteKit application with Cloudflare D1 and TypeSQL.
-
Setting up a new project
See: https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-site/
Install wrangler and TypeSQL as dev dependencies:
Create the typesql.json config file:
Change the typesql.json
:
After you have installed the project dependencies, start the application:
-
Create the d1 Database
Paste the result in the wrangle.toml file:
-
Update src/app.d.ts
to expand the Platform interface to the below:
- Create a migration:
- Create the database schema:
PS: If you are using VSCode and want to have autocompletion for SQL, install the TypeSQL Language Server extension.
- Apply the migrations locally:
- Change the
databaseUri
in the typesql.json
:
- Write your queries:
- Generate the code with TypeSQL:
- Show the data:
- Deploy: