feat: Add native Cloudflare D1 database driver support
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 734
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
Description
Summary
This issue tracks the implementation of a native D1 driver for Sea-ORM that enables seamless integration with Cloudflare Workers D1 databases.
Key Features
- D1Connector & D1Connection: Types wrapping
worker::D1binding - Full SQL execution: Support for
execute,query_one,query_all - D1QueryExecutor trait: Entity query support (works around wasm-bindgen Send bound limitation)
- D1Row & D1ExecResult: Result types for D1 query handling
- TryGetable support: D1-specific type conversions
Example Usage
use worker::{Env, event};
#[event(fetch)]
async fn fetch(req: Request, env: Env, _ctx: Context) -> Result<Response> {
let d1 = env.d1("DB")?;
let db = sea_orm::Database::connect_d1(d1).await?;
// Entity queries work!
let cakes = cake::Entity::find().all(&db).await?;
// Direct SQL also works
db.execute(statement).await?;
Ok(Response::ok("Hello")?)
}
Technical Notes
The implementation uses a custom D1QueryExecutor trait with impl Future return type to work around wasm-bindgen's requirement that futures be Send. This allows Entity queries without requiring the full ConnectionTrait implementation.
Related PR
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the related pull request, Add native D1 driver support, and review the proposed D1Connector, D1Connection, D1QueryExecutor, D1Row, and D1ExecResult types. Verify the example paths for Database::connect_d1, direct SQL execution, and entity queries. Done means the listed D1 operations, result conversions, and entity-query support work for Cloudflare Workers D1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100