DEV Community

Alex Spinov
Alex Spinov

Posted on

Turso Has a Free API: The SQLite-Based Database That Gives You Edge Replicas in 35 Locations for $0

Your users in Tokyo wait 200ms for every database query because your Postgres is in us-east-1. A managed database with global replicas costs $500/mo. Turso gives you SQLite at the edge — your data replicated to 35 locations worldwide, with a generous free tier that handles most indie projects.

What Turso Actually Does

Turso is a distributed database built on libSQL (their open-source fork of SQLite). Each database can have replicas in multiple regions. Reads hit the nearest replica (sub-10ms latency from anywhere), writes go to the primary and propagate to replicas.

The magic: it's still SQLite. Your existing SQLite queries, ORMs, and tools work. But now your single-file database has multi-region replication, point-in-time recovery, and an HTTP API you can call from edge functions.

Free tier: 500 databases, 9GB storage, 1 billion row reads/month. SDKs for JavaScript/TypeScript, Python, Go, Rust, PHP. Open-source client libraries.

Quick Start

# Install CLI
curl -sSfL https://get.tur.so/install.sh | bash
turso auth login

# Create a database with replicas
turso db create my-app --group default
turso db replicate my-app nrt  # Tokyo
turso db replicate my-app lhr  # London
turso db replicate my-app gru  # Sao Paulo
Enter fullscreen mode Exit fullscreen mode

Get connection URL:

turso db show my-app --url
# libsql://my-app-yourname.turso.io

turso db tokens create my-app
# Returns auth token
Enter fullscreen mode Exit fullscreen mode

Use from JavaScript:

import { createClient } from '@libsql/client';

const db = createClient({
  url: 'libsql://my-app-yourname.turso.io',
  authToken: 'your-token'
});

// Create table
await db.execute(`
  CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    email TEXT UNIQUE NOT NULL,
    name TEXT NOT NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
  )
`);

// Insert
await db.execute({
  sql: 'INSERT INTO users (email, name) VALUES (?, ?)',
  args: ['alice@example.com', 'Alice']
});

// Query
const result = await db.execute('SELECT * FROM users');
console.log(result.rows);
Enter fullscreen mode Exit fullscreen mode

3 Practical Use Cases

1. Per-User Databases (Multi-Tenancy)

// Each user gets their own SQLite database
async function createUserDB(userId) {
  const db = createClient({
    url: `libsql://user-${userId}-yourname.turso.io`,
    authToken: process.env.TURSO_TOKEN
  });
  await db.execute(`CREATE TABLE notes (id INTEGER PRIMARY KEY, content TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP)`);
  return db;
}
Enter fullscreen mode Exit fullscreen mode

500 free databases = 500 users with isolated data.

2. Edge Function with Local Data

// Cloudflare Worker / Vercel Edge
export default {
  async fetch(request) {
    const db = createClient({
      url: process.env.TURSO_URL,
      authToken: process.env.TURSO_TOKEN
    });

    const { rows } = await db.execute(
      'SELECT * FROM products WHERE category = ? ORDER BY rating DESC LIMIT 10',
      [new URL(request.url).searchParams.get('category')]
    );

    return new Response(JSON.stringify(rows), {
      headers: { 'Content-Type': 'application/json' }
    });
  }
};
Enter fullscreen mode Exit fullscreen mode

Edge function + edge database = sub-50ms response worldwide.

3. Embedded Replicas (Offline-First)

import { createClient } from '@libsql/client';

const db = createClient({
  url: 'file:local-replica.db',          // Local SQLite file
  syncUrl: 'libsql://my-app.turso.io',   // Sync with cloud
  authToken: 'your-token'
});

// Works offline using local file
const result = await db.execute('SELECT * FROM products');

// Sync when online
await db.sync();
Enter fullscreen mode Exit fullscreen mode

Why This Matters

Turso makes globally-distributed data accessible to indie developers. The SQLite foundation means zero learning curve. The edge replication means your users get fast responses regardless of location. And the free tier is generous enough for real applications, not just demos.


Need custom data extraction or web scraping solutions? I build production-grade scrapers and data pipelines. Check out my Apify actors or email me at spinov001@gmail.com for custom projects.

Follow me for more free API discoveries every week!

Top comments (0)