Db

codemode-gatewaysourcetypescript
Path: codemode-gateway/src/providers/db.tsRelative: src/providers/db.tsSubproject: codemode-gatewayCategory: codemode-gateway
Lines: 148Bytes: 5,353Imports: 1Exports: 2

Content Preview

  1. import type { Env } from "../types";
  2. /**
  3. * `db` namespace tools — generic SQL over the bound D1 database `env.DB`.
  4. *
  5. * Unlike the REST `cf.d1_*` path (which calls the Cloudflare API and needs a
  6. * D1-scoped `CF_API_TOKEN`), a D1 binding needs NO API token — the binding is
  7. * authorized at deploy time. This is the primary, always-available SQL path.
  8. *
  9. * Two tools, each with a parse-side SQL guard:
  10. * - `query({ sql, params? })` → SELECT rows only (rejects non-SELECT).
  11. * - `exec({ sql,