How to access the D1 without the Wrangler ?
I create the Worker via Cloudflare API and it is not possible to create wrangler.toml
The code contains:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
...
But how can I access the D1 database ?2 Replies
I don't believe D1 works on service workers. You would have to switch to module workers
Would I need the wrangler.toml file ?
If so, there is no way to create this file via the API
I used this code for testing and it gives me the following error
Unexpected token 'export' at worker.js
export default {
async fetch(request, env, ctx) {
const res = await env.DB.prepare("SELECT 1;").all();
return new Response(JSON.stringify(res, null, 2));
},
};