Skip to content

feat(d1): add IntoFuture and #[must_use] to D1PreparedStatement#1007

Merged
guybedford merged 3 commits into
cloudflare:mainfrom
eyupcanakman:feat/d1-prepared-statement-must-use
Jun 19, 2026
Merged

feat(d1): add IntoFuture and #[must_use] to D1PreparedStatement#1007
guybedford merged 3 commits into
cloudflare:mainfrom
eyupcanakman:feat/d1-prepared-statement-must-use

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

D1PreparedStatement holds a query that has not run yet. With no terminal call it compiles fine and does nothing, e.g. query!(&db, "DELETE FROM users WHERE id = ?", id)?;. Adding #[must_use] to the type makes that a compile warning, matching the KV builders (GetOptionsBuilder, PutOptionsBuilder).

#774 also asks for impl IntoFuture so a statement runs when you .await it. That would be the first IntoFuture in the crate, and await stmt has to pick one terminal method. I can follow up with one delegating to run() to match the JS stmt.run(), or all() if you'd prefer.

Part of #774.

A statement that never runs compiles fine but does nothing. Mark the type
#[must_use] so that case is a compile warning, matching the KV builders.
@guybedford

Copy link
Copy Markdown
Collaborator

For the must_use I'm open to either way on this one. Formally it's not a correctness issue if it isn't used though.

For the IntoFuture on the query itself that would be great though definitely.

Awaiting a prepared statement now runs it through run(), so callers can
write `stmt.await?` instead of `stmt.run().await?`. Update the must_use
note to mention await.
@eyupcanakman eyupcanakman changed the title feat(d1): add #[must_use] to D1PreparedStatement feat(d1): add IntoFuture and #[must_use] to D1PreparedStatement Jun 16, 2026
@eyupcanakman

Copy link
Copy Markdown
Contributor Author

Added the IntoFuture impl so awaiting a statement runs it through run(). Kept the must_use alongside it, but can drop it if you'd rather this PR stay scoped to just IntoFuture.

@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 2 untouched benchmarks


Comparing eyupcanakman:feat/d1-prepared-statement-must-use (c3ec02f) with main (cc174db)

Open in CodSpeed

@guybedford guybedford merged commit f163894 into cloudflare:main Jun 19, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants