Moving a Hono API from Postgres or D1 to SurrealDB Earth
Blog post from SurrealDB
A Hono API running on Cloudflare Workers can move from Postgres or D1 to SurrealDB Earth by using one Earth instance with a separate database for each tenant, provided tenants share the same instance-level settings; tenants with different residency or network requirements may need separate instances. The migration uses the SurrealDB JavaScript SDK, with a client opened and closed for each request, tied to the request’s abort signal, and authenticated through a namespace-level user whose password is stored as a Worker secret. Tenant databases are defined on first use, while an authenticated operator route can provision each tenant’s schema using repeatable `DEFINE` statements grouped in a transaction. The example API implements note creation, reading, updating, and deletion, and illustrates record IDs, schema validation, bound query parameters, and explicit sorting. SurrealDB records take the place of rows, record links replace foreign keys, and SDK transactions replace D1 batches or explicit Postgres transaction blocks when several operations must succeed together. Earth scales compute to demand and can scale to zero when idle, while data residency and other instance-wide settings determine whether a shared instance is suitable for all tenants.
| Trend | Post Mentions | Total Month Mentions | Posts | Companies | MoM |
|---|---|---|---|---|---|
| Secrets Management | 2 | 2,876 | 539 | 148 | -7% |
| Serverless | 2 | 833 | 236 | 92 | -40% |
| AI Agents | 1 | 6,233 | 1,230 | 245 | -11% |
Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.