Course lesson 15 · Smart Routing Service

Connecting our database

One study unit · Read, recall, then practice · Original video 00:08:08

The data service reuses the existing Data Ops get-link query to read the same configuration created through the dashboard. The lesson connects that reusable code to this Worker’s own D1 binding and initializes the shared database accessor in the WorkerEntrypoint constructor. It also demonstrates how a missing await can hide the real error by returning before the asynchronous query finishes.

Primary source: course video 15 · Supplied English subtitles · 00:08:08.

Understand the idea

What the course does

  1. Read the ID through Hono’s request-param helper and call the imported get-link query.
  2. Copy the intended D1 configuration into the data service and regenerate Cloudflare environment types.
  3. Run locally against a link ID that already exists in the user application’s database.
  4. Add the missing await so failures occur in the request’s actual control flow.
  5. Diagnose database-not-initialized and initialize the Data Ops accessor from the constructor’s D1 environment binding.
  6. Repeat the request and confirm that the returned JSON contains the stored link configuration.

Watch for

Recall before revealing

Why did importing a working query from the dashboard package not make it immediately work in the data service?

Reveal the explanation

The separate Worker still needed its D1 resource binding and the shared database accessor initialized for its own execution path.

Try it

Use a link created through the dashboard to retrieve its configuration through the data-service ID route.

Check your result

The returned name and destinations match D1, and you can explain the binding and initialization steps that made the shared query work.

Practice prompts and answer checks are added teaching material. Answer from memory first, then compare and explain any difference.

Rewatch only what you need

Open this lesson in your original course library and seek to the times below. Videos are not hosted on this site.

Companion primary documentation: Cloudflare resource bindings. For recorded API names, commands, limits, and prices, check the version you use.

← Previous   Next →