Skip to content

Example application showing how to build data-driven apps with D1 and Cloudflare Workers

Notifications You must be signed in to change notification settings

kristianfreeman/d1-movie-example

Repository files navigation

d1-movie-example

Example application used in the Workers 201 video course, "Managing Data in your Workers Application".

Usage

This example application shows how to set up three routes in an application, backed by D1:

  1. GET /movies: get all movies from the database as JSON.
  2. POST /movies/:id: update a movie in the database. In the tutorial, we enable just the rating field to be updated.
  3. GET /favorites: get the three highest-rated movies from the database as JSON.

Configuration

  1. Create a new d1 database:
$ npx wrangler d1 create movie-example
  1. Deploy your application:
$ npx wrangler deploy
  1. Add the output of that command to your wrangler.toml file.

  2. Execute both SQL files against your D1 database:

$ npx wrangler d1 execute movie-example movie-example --file scripts/001_create_db.sql --remote
$ npx wrangler d1 execute movie-example movie-example --file scripts/002_insert_movies.sql --remote

Note that the --remote flag will execute this against your remote database. You can remove this flag to execute against your local database.

About

Example application showing how to build data-driven apps with D1 and Cloudflare Workers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published