Skip to content

DongTin/super-dust-5ceb

Repository files navigation

Worker + D1 Database

Worker + D1 Template Preview

D1 is Cloudflare's native serverless SQL database (docs). This project demonstrates using a Worker with a D1 binding to execute a SQL statement. A simple frontend displays the result of this query:

SELECT * FROM comments LIMIT 3;

The D1 database is initialized with a comments table and this data:

INSERT INTO comments (author, content)
VALUES
    ('Kristian', 'Congrats!'),
    ('Serena', 'Great job!'),
    ('Max', 'Keep up the good work!')
;

Important

When using C3 to create this project, select "no" when it asks if you want to deploy. You need to follow this project's setup steps before deploying.

Getting Started

Outside of this repo, you can start a new project with this template using C3 (the create-cloudflare CLI):

npm create cloudflare@latest -- --template=cloudflare/templates/super-dust-5ceb

A live public deployment of this template is available at https://super-dust-5ceb.templates.workers.dev

Setup Steps

  1. Install the project dependencies with a package manager of your choice:
    npm install
  2. Create a D1 database with the name "late-dew-364c-d1":
    npx wrangler d1 create late-dew-364c-d1
    ...and update the database_id field in wrangler.json with the new database ID.
  3. Run the following db migration to initialize the database (notice the migrations directory in this project):
    npx wrangler d1 migrations apply --remote late-dew-364c-d1
  4. Deploy the project!
    npx wrangler deploy

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published