-
-
Notifications
You must be signed in to change notification settings - Fork 661
Open
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
Metadata
Metadata
Assignees
Labels
No labels