can i read d1 from a plain node script or does everything have to go through a worker
i have a nightly reporting script that runs on a small vm and produces a csv for the finance side. the data it needs lives in d1 and right now i've got an undocumented worker endpoint with a shared secret in a header purely so the script can get at it, which feels like a hack i'll regret. is there a supported way to query d1 from outside the workers runtime?
@migration_marek · 3mo ago
Yes — there's an HTTP API. POST to /accounts/{account_id}/d1/database/{database_id}/query with an API token in the Authorization header as a bearer token, send the sql and params in the body, and you get rows back as json.
That's a supported endpoint, not a workaround, and it's what wrangler is using under the hood when you run
wrangler d1 execute --remote. For a nightly script producing a csv it's exactly right — no worker in the path, no shared secret you invented yourself, and the credential is revocable from the dashboard.Reply
Report