The d1-worker is the data routing hub of the Hoox trading platform. Deployed as an isolated, private micro-worker, it acts as a centralized SQL execution proxy. By encapsulating database interactions behind secure Service Bindings, it allows other lightweight compute workers to execute parameterized queries, trigger transactional batch operations, and retrieve structured dashboard telemetry without direct database driver overhead.
⚡ 1. Declared Wrangler Configurations & Bindings
The d1-worker binds directly to the production SQLite database (trade-data-db) and does not expose any public endpoints:
🔌 2. Internal REST API Specification
Note: For the canonical endpoint directory with full request/response examples across all workers, see /docs/devops/api/endpoints.
Every endpoint is secured via requireInternalAuth and expects the X-Internal-Auth-Key header.
A. Execute Single SQL Query
- Endpoint:
/query
- Method:
POST
- JSON Payload:
- SELECT Success Response (200 OK):
- Write Success Response (200 OK) (INSERT/UPDATE/DELETE/REPLACE):
B. Execute Transactional Batch Operations
Allows running multiple statements atomically in a single network trip, reducing latency.
- Endpoint:
/batch
- Method:
POST
- JSON Payload:
- Success Response (200 OK):
C. Dashboard Telemetry Statistics
Calculates aggregated win ratios, active positions size, and time-series P&L.
- Endpoint:
/api/dashboard/stats
- Method:
GET
- Success Response (200 OK):
🛡️ 3. Security & SQL Injection Protection
To protect financial transaction ledgers and portfolios against SQL injection attacks, d1-worker enforces strict development rules:
- Parameterized Bindings: All inputs must utilize parameterized placeholders (
? or ?1) mapped to env.DB.prepare().bind(). Never concatenate raw request strings directly into SQL statements.
- Access Isolation: The database does not exist publicly. By binding D1 solely to this worker and accessing it via V8 Service Bindings, you prevent external crawlers or bots from querying database nodes directly.
If you are extending schemas or adding tables, generate migration scripts
locally using Drizzle: hoox db migrate --remote. This keeps edge schema
histories atomic and securely tracked.
🔗 Next Steps