SeaQL / SeaQL/sea-orm

feat: Add native Cloudflare D1 database driver support

Open
#2,928 0 comments 0 reactions 0 assignees View on GitHub

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::D1 binding
  • 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.