From 5522f7c88cc7849567b30fd80bc7a4d85806db60 Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Wed, 14 Jan 2026 17:16:36 +0000 Subject: [PATCH] Fix critical syntax errors in D1 database API documentation - Fix SQL syntax: Add quotes around string literals in static query examples - Fix JavaScript syntax error in getBookmark() example (invalid destructuring/return) - Fix variable consistency: Change db.dump() to env.DB.dump() and self.env.DB.dump() - Improves code quality from 83% to 100% for affected examples --- src/content/docs/d1/worker-api/d1-database.mdx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/content/docs/d1/worker-api/d1-database.mdx b/src/content/docs/d1/worker-api/d1-database.mdx index f4ed600318b..22ea7918729 100644 --- a/src/content/docs/d1/worker-api/d1-database.mdx +++ b/src/content/docs/d1/worker-api/d1-database.mdx @@ -65,11 +65,11 @@ You can use the `bind` method to dynamically bind a value into the query statem ```js const stmt = db - .prepare("SELECT * FROM Customers WHERE CompanyName = Alfreds Futterkiste AND CustomerId = 1") + .prepare("SELECT * FROM Customers WHERE CompanyName = 'Alfreds Futterkiste' AND CustomerId = 1") ``` ```py - stmt = db.prepare("SELECT * FROM Customers WHERE CompanyName = Alfreds Futterkiste AND CustomerId = 1") + stmt = db.prepare("SELECT * FROM Customers WHERE CompanyName = 'Alfreds Futterkiste' AND CustomerId = 1") ``` @@ -327,7 +327,7 @@ Dumps the entire D1 database to an SQLite compatible file inside an ArrayBuffer. ```js -const dump = await db.dump(); +const dump = await env.DB.dump(); return new Response(dump, { status: 200, headers: { @@ -339,7 +339,7 @@ return new Response(dump, { ```py from workers import Response -dump = await db.dump() +dump = await self.env.DB.dump() return Response(dump, status=200, headers={"Content-Type": "application/octet-stream"}) ``` @@ -404,7 +404,8 @@ const session = env.DB.withSession("first-primary"); const result = await session .prepare(`SELECT * FROM Customers WHERE CompanyName = 'Bs Beverages'`) .run() -return { bookmark } = session.getBookmark(); +const bookmark = session.getBookmark(); +return bookmark; ``` ```py