Cloudflare d1 #114
-
Hello, The project is compatible with Sqlite, is it also compatible with Cloudflare d1 which is based on Sqlite? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
In theory, it should work as long as you run cloudflare with nodejs compatability flag (because it needs nodejs domain) |
Beta Was this translation helpful? Give feedback.
-
thank you very much for your fast answer and the project in general. Are you planning on building an adapter for d1? I see quite a long list of adapters in the roadmap drafts. |
Beta Was this translation helpful? Give feedback.
-
Cloudflare is now supported from v.4.5.0 name = "d1-tutorial"
main = "src/index.ts"
compatibility_date = "2025-02-04"
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
[[d1_databases]]
binding = "DB"
database_name = "<your-name-for-the-database>"
database_id = "<your-guid-for-the-database>" 📄 src/index.ts import map from './map';
export interface Env {
// Must match the binding name in wrangler.toml
DB: D1Database;
}
export default {
async fetch(request, env): Promise<Response> {
const db = map.d1(env.DB);
const customers = await db.customer.getAll();
return Response.json(customers);
},
} satisfies ExportedHandler<Env>; |
Beta Was this translation helpful? Give feedback.
Cloudflare is now supported from v.4.5.0
📄 wrangler.toml
📄 src/index.ts