SQLite Connection String and File Path

Understand SQLite connection strings and file path formats. Covers relative paths, absolute paths, in-memory databases, and Prisma file: URI format.

Best Practices

Detailed Explanation

SQLite Connection Strings

SQLite is different from client-server databases — it reads and writes directly to a file on disk. The "connection string" is simply a file path, optionally prefixed with file:.

File Path Formats

Relative path (relative to the application's working directory):

./database.sqlite
file:./database.sqlite

Absolute path:

/var/lib/myapp/database.sqlite
file:///var/lib/myapp/database.sqlite

Windows absolute path:

C:\Users\dev\myapp\database.sqlite
file:///C:/Users/dev/myapp/database.sqlite

In-Memory Database

For testing or temporary data, SQLite can run entirely in memory:

:memory:
file::memory:

In-memory databases exist only for the lifetime of the connection. Once closed, all data is lost. This is perfect for unit tests.

Prisma Configuration

Prisma uses the file: prefix for SQLite:

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

Or via environment variable:

DATABASE_URL="file:./dev.db"

URI Parameters

The file: URI supports query parameters:

Parameter Purpose
mode=ro Open read-only
mode=rw Open read-write (no create)
mode=rwc Read-write, create if missing (default)
mode=memory In-memory database
cache=shared Shared cache mode

Example with parameters:

file:./app.db?mode=rwc&cache=shared

File Extensions

Common SQLite file extensions include .sqlite, .sqlite3, .db, and .s3db. The extension is purely conventional — SQLite does not enforce any particular extension.

Use Case

Setting up a local SQLite database for a development environment, a mobile application, an embedded system, or as a lightweight testing database in CI/CD pipelines.

Try It — Connection String Builder

Open full tool