𝗧𝘂𝗿𝘀𝗼 𝗹𝗶𝗯𝗦𝗤𝗟 𝘃𝘀 𝗖𝗹𝗼𝘂𝗱𝗳𝗹𝗮𝗿𝗲 𝗗𝟭

Choosing a database for an Astro monorepo is about your workflow.

I recently built a shared database for three Astro SSG sites. I had two choices: Turso (libSQL) or Cloudflare D1.

I chose Turso.

Here is why the practical difference mattered.

Cloudflare D1 is built for Cloudflare Workers. If you use Workers for server-side rendering, D1 is the winner. It lives where your code runs.

My setup is different. My sites are static Astro 5 SSG on Cloudflare Pages. I do not use Workers. My ETL pipeline runs in GitHub Actions.

Using D1 from GitHub Actions is hard. You must use the Cloudflare API or the Wrangler CLI. Neither gives you a local SQLite file to query during development. You end up hitting a remote database for every test.

Turso solves this with the @libsql/client package. It accepts a URL. That URL can be a remote link or a local file path.

My code looks like this:

The URL is a remote Turso link in CI. On my laptop, the client opens a local file. The package, the queries, and the schema stay the same.

The code path is identical.

This allows me to:

  • Run ETL scripts locally.
  • Inspect the database with any SQLite viewer.
  • Run migrations with the same function used in production.

I do not need Docker. I do not need special flags. The same SQL works everywhere.

I use an idempotent approach for migrations. My code checks if a table exists before creating it. This makes it safe to run repeatedly.

When should you choose D1? If you use Cloudflare Workers for search or API routes, D1 is better. The connection is faster because it stays inside the same datacenter.

My architecture is fully static. Since I do not use Workers, D1 loses its main advantage.

Current trade-offs:

  • Write performance: My ETL runs tasks one by one. I have not tested high-speed concurrent writes.
  • Schema changes: Adding columns is easy. Renaming columns requires more care.
  • Pricing: Both have generous free tiers. For three sites, my cost is zero.

The database choice was not the main goal. The local file fallback was the reason I chose Turso. It makes development simple.

Source: https://dev.to/morinaga/turso-libsql-vs-cloudflare-d1-for-an-astro-monorepo-the-practical-difference-3c9