{"id":34761223,"url":"https://github.com/ohkami-rs/sqlx-d1","last_synced_at":"2026-04-24T05:02:37.782Z","repository":{"id":279853276,"uuid":"937522912","full_name":"ohkami-rs/sqlx-d1","owner":"ohkami-rs","description":"SQLx for Cloudflare D1","archived":false,"fork":false,"pushed_at":"2026-04-23T14:30:10.000Z","size":220,"stargazers_count":48,"open_issues_count":5,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-23T15:18:11.335Z","etag":null,"topics":["cloudflare","cloudflare-d1","cloudflare-worker","cloudflare-workers","rust","sqlx"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ohkami-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-23T09:09:35.000Z","updated_at":"2026-04-23T13:21:51.000Z","dependencies_parsed_at":"2025-02-28T04:26:07.014Z","dependency_job_id":"d14aab3b-8438-4082-9acd-9c337dde0d93","html_url":"https://github.com/ohkami-rs/sqlx-d1","commit_stats":null,"previous_names":["ohkami-rs/sqlx-d1"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/ohkami-rs/sqlx-d1","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohkami-rs%2Fsqlx-d1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohkami-rs%2Fsqlx-d1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohkami-rs%2Fsqlx-d1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohkami-rs%2Fsqlx-d1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ohkami-rs","download_url":"https://codeload.github.com/ohkami-rs/sqlx-d1/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohkami-rs%2Fsqlx-d1/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32209897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T03:15:14.334Z","status":"ssl_error","status_checked_at":"2026-04-24T03:15:11.608Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","cloudflare-d1","cloudflare-worker","cloudflare-workers","rust","sqlx"],"created_at":"2025-12-25T06:30:17.603Z","updated_at":"2026-04-24T05:02:37.771Z","avatar_url":"https://github.com/ohkami-rs.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003eSQLx-D1\u003c/h1\u003e\n    \u003ca href=\"https://github.com/launchbadge/sqlx\"\u003eSQLx\u003c/a\u003e for \u003ca href=\"https://developers.cloudflare.com/d1\"\u003eCloudflare D1\u003c/a\u003e.\n\u003c/div\u003e\n\n\u003cbr\u003e\n\nSQLx-D1 realizes \"SQLx for Cloudflare D1\" _**with compile-time SQL verification**_ in Rust Cloudflare development !\n\n\u003cdiv align=\"right\"\u003e\n    \u003ca href=\"https://github.com/ohkami-rs/sqlx-d1/blob/main/LICENSE\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/crates/l/sqlx-d1.svg\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/ohkami-rs/sqlx-d1/actions\"\u003e\u003cimg alt=\"build check status\" src=\"https://github.com/ohkami-rs/sqlx-d1/actions/workflows/CI.yml/badge.svg\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/sqlx-d1\"\u003e\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/sqlx-d1\" /\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n## Compatible `worker` version\n\n| `sqlx-d1` | `worker` |\n| :-------: | :------: |\n|   0.2.*   |   0.6.*  |\n|   0.3.*   |   0.7.*  |\n|   0.4.*   |   0.8.*  |\n\n## Background\n\n*Miniflare's local D1 emulator is, essentially, just a `.sqlite` file.*\n\nThis fact has been brought a lot of Rustaceans trying `sqlx` with `sqlite` feature for D1, but it's impossible because:\n\n- `sqlx-sqlite` contains a *native dependency* of SQLite driver.\n- actual D1 itself doesn't expose raw database interface.\n\nSQLx-D1 works around them by loading `sqlx-sqlite` **only in macro context** and just providing a conversion layer between D1 and SQLx **in library context**.\n\n## Features\n\n- SQLx interface for Cloudflare D1\n- Batteries included, `sqlx` is not needed in dependencies\n- Compile-time SQL verification\n    - by miniflare's local D1 emulator ( internally using `sqlx-sqlite` )\n    - by query caches in `.sqlx` directory ( offline mode; `cargo sqlx prepare` )\n- No environment variable or `.env` file is needed\n    - D1 emulator's location is fixed to `.wrangler/state/v3/d1/miniflare-D1DatabaseObject`\n    - falling back to offline mode when it doesn't exist and `.sqlx` directory exists\n\n## Unsupported features\n\n- Transaction\n    - Let's wait for Cloudflare's side to support transation on D1 !\n- Connection pool ( `sqlx::Pool` internally requires Rust async runtime (tokio / asycn-std) and time implemetation of WASM runtime which is not done on Cloudflare Workers )\n    - alternatively, `\u0026sqlx_d1::D1Connection` implements `Executor`, not only `\u0026mut` one.\n- derive `Type`, `Encode`, `Decode`\n    - maybe added if requested\n    - workaround if needed: add `sqlx` to dependencies and use its ones\n\n## Example\n\n```toml\n# Cargo.toml\n\n[dependencies]\nsqlx-d1 = { version = \"0.4\", features = [\"macros\"] }\nworker = { version = \"0.8\", features = [\"d1\"] }\nserde = { version = \"1.0\", features = [\"derive\"] }\n```\n```sh\nwrangler d1 create \u003cDATABASE_NAME\u003e # prints \u003cDATABASE_ID\u003e\n```\n```jsonc\n// wrangler.jsonc\n\n{\n  \"d1_databases\": [\n    {\n      \"binding\": \"DB\",\n      \"database_name\": \"DATABASE_NAME\",\n      \"database_id\": \"\u003cDATABASE_ID\u003e\"\n    }\n  ]\n}\n```\n```sh\nwrangler d1 migrations create DB 'schema'\n```\n```sql\n-- migrations/0001_schema.sql\n\nCREATE TABLE users (\n    id   INTEGER NOT NULL PRIMARY KEY,\n    name TEXT NOT NULL,\n    age  INTEGER\n);\n```\n```sh\nwrangler d1 migrations apply DB --local\n```\n```rust\n// src/lib.rs\n\n#[worker::event(fetch)]\nasync fn main(\n    mut req: worker::Request,\n    env: worker::Env,\n    _ctx: worker::Context,\n) -\u003e worker::Result\u003cworker::Response\u003e {\n    let d1 = env.d1(\"DB\")?;\n    let conn = sqlx_d1::D1Connection::new(d1);\n\n    #[derive(serde::Deserialize)]\n    struct CreateUser {\n        name: String,\n        age: Option\u003cu8\u003e,\n    }\n\n    let req = req.json::\u003cCreateUser\u003e().await?;\n\n    let id = sqlx_d1::query!(\n        \"\n        INSERT INTO users (name, age) VALUES (?, ?)\n        RETURNING id\n        \",\n            req.name,\n            req.age\n        )\n        .fetch_one(\u0026conn)\n        .await\n        .map_err(|e| worker::Error::RustError(e.to_string()))?\n        .id;\n\n    worker::Response::ok(format!(\"Your id is {id}!\"))\n}\n```\n\n## License\n\nSQLx-D1 is licensed under MIT LICENSE ( [LICENSE](https://github.com/ohkami-rs/sqlx-d1/blob/main/LICENSE) or https://opensource.org/licenses/MIT ) .\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohkami-rs%2Fsqlx-d1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fohkami-rs%2Fsqlx-d1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohkami-rs%2Fsqlx-d1/lists"}