Databases

Working with databases in your matt-init project


Turso (SQLite)

What is Turso?

Turso is a distributed SQLite platform that brings SQLite to the edge. It's compatible with standard SQLite but adds features like replication, backups, and global distribution.

Why SQLite/Turso?

  • Fast: SQLite is incredibly fast for most use cases
  • Simple: No complex setup or configuration
  • Portable: Database is just a file, easy to backup and move
  • Edge-compatible: Works in serverless environments
  • Cost-effective: Generous free tier, pay-as-you-go pricing

Local Development

Pre-requisites

Starting the Database

When you run pnpm dev with backend enabled, two things happen:

pnpm dev
# [0] sqld listening on port 8080
# [1] ▲ Next.js ready at http://localhost:3000
  • [0] - Turso local server (sqld) on port 8080
  • [1] - Next.js development server on port 3000

Database File

Your local database is stored as local.db in your project root. This file contains all your data and can be:

  • Backed up by copying the file
  • Reset by deleting the file (will be recreated on next pnpm dev)
  • Shared with teammates (though not recommended for sensitive data)

Environment Variables

# Local development
TURSO_DATABASE_URL=http://127.0.0.1:8080
TURSO_AUTH_TOKEN=  # Empty for local development

Database Operations

Database operations are handled using Drizzle ORM, which provides a type-safe way to interact with your SQLite database. Check the documentation for Drizzle ORM to learn how to define schemas, run queries, and manage migrations.

Future Database Options

Coming Soon

  • Neon (Postgres) - Serverless Postgres with modern features
  • Docker Postgres - Local Postgres development with Docker
  • Supabase - Full-stack Postgres with auth and storage

Resources