[Feature] Expose D1 Sessions API (`withSession`) in `worker` / `worker-sys`
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Description
## Summary
Please expose Cloudflare D1 Sessions API in `worker` and `worker-sys`, so Rust users can use `withSession()` with
typed bindings instead of JS reflection interop.
## Current behavior
In `worker = 0.7.5` (and `worker-sys = 0.7.5`), D1 currently exposes:
- `prepare`
- `dump`
- `batch`
- `exec`
But there is no typed API for:
- `D1Database.withSession(...)`
- `D1DatabaseSession.prepare(...)`
- `D1DatabaseSession.batch(...)`
- session bookmark methods (if available in runtime API)
## Problem
Without typed Sessions support, users must call `withSession` through `js_sys::Reflect` / dynamic JS calls.
This has downsides:
- no compile-time type safety
- more verbose/error-prone code
- harder to maintain and review
- weaker discoverability for D1 consistency features
## Why it matters
For real workloads, Sessions are important for read-after-write consistency and routing behavior (e.g. `first-
primary` / bookmark flow).
Typed support would make this safe and ergonomic in Rust Workers.
## Proposed API (example)
- Add `D1Database::with_session(constraint: Option<&str>) -> Result<D1DatabaseSession>`
- Add `D1DatabaseSession::prepare(...)`
- Add `D1DatabaseSession::batch(...)`
- (Optional) expose bookmark getter/setter if runtime supports it.
## Environment
- `worker`: `0.7.5`
- `worker-sys`: `0.7.5`
- Rust target: `wasm32-unknown-unknown`
关闭于 2026-04-01 0 条评论