Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/content/docs/d1/best-practices/local-development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ You can then use the `getD1Database()` method to retrieve the simulated database
const db = await mf.getD1Database("DB");

const stmt = db.prepare("SELECT name, age FROM users LIMIT 3");
const { results } = await stmt.all();
const { results } = await stmt.run();

console.log(results);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Use the following Worker script to verify that the Worker has access to the boun
```js
export default {
async fetch(request, env, ctx) {
const res = await env.DB.prepare("SELECT 1;").all();
const res = await env.DB.prepare("SELECT 1;").run();
return new Response(JSON.stringify(res, null, 2));
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/d1/examples/d1-and-hono.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ app.get("/query/users/:id", async (c) => {
"SELECT * FROM users WHERE user_id = ?",
)
.bind(userId)
.all();
.run();
return c.json(results);
} catch (e) {
return c.json({ err: e.message }, 500);
Expand Down Expand Up @@ -76,7 +76,7 @@ app.get("/query/users/:id", async (c) => {
"SELECT * FROM users WHERE user_id = ?",
)
.bind(userId)
.all();
.run();
return c.json(results);
} catch (e) {
return c.json({ err: e.message }, 500);
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/d1/examples/d1-and-remix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface Env {
export const loader: LoaderFunction = async ({ context, params }) => {
let env = context.cloudflare.env as Env;

let { results } = await env.DB.prepare("SELECT * FROM users LIMIT 5").all();
let { results } = await env.DB.prepare("SELECT * FROM users LIMIT 5").run();
return json(results);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def on_fetch(request, env):
# Do anything else you'd like on request here!

# Query D1 - we'll list all tables in our database in this example
results = await env.DB.prepare("PRAGMA table_list").all()
results = await env.DB.prepare("PRAGMA table_list").run()
# Return a JSON response
return Response.json(results)

Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/d1/get-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ After you have set up your database, run an SQL query from within your Worker.
"SELECT * FROM Customers WHERE CompanyName = ?",
)
.bind("Bs Beverages")
.all();
.run();
return Response.json(results);
}

Expand Down Expand Up @@ -387,7 +387,7 @@ You can query your D1 database using your Worker.
"SELECT * FROM Customers WHERE CompanyName = ?"
)
.bind("Bs Beverages")
.all();
.run();
return new Response(JSON.stringify(results), {
headers: { 'Content-Type': 'application/json' }
});
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/d1/sql-api/sql-statements.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const { results } = await env.DB.prepare(
"SELECT * FROM Customers WHERE CompanyName LIKE ?",
)
.bind("%eve%")
.all();
.run();
console.log("results: ", results);
```
```js output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ app.get("/api/posts/:slug/comments", async (c) => {
`,
)
.bind(slug)
.all();
.run();
return c.json(results);
});
```

The above code makes use of the `prepare`, `bind`, and `all` functions on a D1 binding to prepare and execute a SQL statement. Refer to [D1 Workers Binding API](/d1/worker-api/) for a list of all methods available.
The above code makes use of the `prepare`, `bind`, and `run` functions on a D1 binding to prepare and execute a SQL statement. Refer to [D1 Workers Binding API](/d1/worker-api/) for a list of all methods available.

In this function, you accept a `slug` URL query parameter and set up a new SQL statement where you select all comments with a matching `post_slug` value to your query parameter. You can then return it as a JSON response.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const findAllEmployees = async (db: D1Database) => {
JOIN locations ON employees.location_id = locations.location_id
JOIN departments ON employees.department_id = departments.department_id
`;
const { results } = await db.prepare(query).all();
const { results } = await db.prepare(query).run();
const employees = results;
return employees;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ app.get("/api/products", async (c) => {

try {
return await withRetry(async () => {
const { results } = await session.prepare("SELECT * FROM products").all();
const { results } = await session.prepare("SELECT * FROM products").run();

const latestBookmark = session.getBookmark();

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/d1/worker-api/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default {
const { pathname } = new URL(request.url);
// if (pathname === "/api/beverages") {
// // If you did not use `DB` as your binding name, change it here
// const { results } = await env.DB.prepare("SELECT * FROM Customers WHERE CompanyName = ?",).bind("Bs Beverages").all();
// const { results } = await env.DB.prepare("SELECT * FROM Customers WHERE CompanyName = ?",).bind("Bs Beverages").run();
// return Response.json(results);
// }
const companyName1 = `Bs Beverages`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const loader: LoaderFunction = async ({ context, params }) => {
const { env, cf, ctx } = context.cloudflare;
let { results } = await env.DB.prepare(
"SELECT * FROM products where id = ?1"
).bind(params.productId).all();
).bind(params.productId).run();
return json(results);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ app.get("/", async (c) => {
let notes = [];
if (vecId) {
const query = `SELECT * FROM notes WHERE id = ?`;
const { results } = await c.env.DB.prepare(query).bind(vecId).all();
const { results } = await c.env.DB.prepare(query).bind(vecId).run();
if (results) notes = results.map((vec) => vec.text);
}

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/workers/languages/python/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def on_fetch(request, env):
from workers import Response

async def on_fetch(request, env):
results = await env.DB.prepare("PRAGMA table_list").all()
results = await env.DB.prepare("PRAGMA table_list").run()
# Return a JSON response
return Response.json(results)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class UserEntrypoint extends WorkerEntrypoint {
"SELECT title FROM tasks WHERE user_id = ?"
)
.bind(userId)
.all();
.run();
}

async createTask(userId, title) {
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/workflows/examples/send-invoices.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class cartInvoicesWorkflow extends WorkflowEntrypoint<Env, Params> {
`SELECT * FROM cart WHERE id = ?`,
)
.bind(event.payload.cartId)
.all();
.run();
// should return { checkedOut: true, amount: 250 , account: { email: "[email protected]" }};
if (results[0].checkedOut === false) {
throw new Error("cart hasn't been checked out yet");
Expand Down