SQL (Relational)
Single query
Section titled “Single query”curl -X POST https://magnusdb.dev/api/sql/query \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "sql": "SELECT * FROM users WHERE created_at > ?", "params": ["2024-01-01"] }'Batch queries
Section titled “Batch queries”curl -X POST https://magnusdb.dev/api/sql/batch \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "statements": [ {"sql": "INSERT INTO logs (msg) VALUES (?)", "params": ["start"]}, {"sql": "INSERT INTO logs (msg) VALUES (?)", "params": ["end"]} ] }'Automatic routing
Section titled “Automatic routing”Magnus routes SQL to D1 or Hyperdrive (Postgres) based on syntax detection:
| Trigger | Routes to |
|---|---|
Window functions (ROW_NUMBER, RANK, LAG, etc.) | Hyperdrive |
ILIKE | Hyperdrive |
::type casts | Hyperdrive |
RETURNING clause | Hyperdrive |
LATERAL joins | Hyperdrive |
JSON operators (->, ->>, #>, #>>) | Hyperdrive |
JSONB type | Hyperdrive |
WITH RECURSIVE | Hyperdrive |
GENERATE_SERIES | Hyperdrive |
| Array syntax | Hyperdrive |
| Everything else | D1 |