In this guide, we walk through how to set up and use Payload with a SQLite database, specifically how to set up a remote SQLite database with Turso.
In this guide, I’m going to show you how you can set up and use Payload with a SQLite database. I’ll cover why you might want to choose SQLite over other database options, discuss some deployment scenarios, and walk you through integrating with Turso to enable a serverless environment like Vercel.
Let’s dive in!
When starting a new Payload project, you have three main database options:
In this video and guide, we’re focusing on SQLite.
SQLite is a pretty simple option. Here’s why you might choose it over something like MongoDB:
There are two scenarios where SQLite really shines:
Another option is to use a docker-based deployment (for instance, with Coolify) where you can mount the database file as persistent storage.
Let’s get started by creating a fresh Payload project using SQLite:
When prompted for the project name, type something like sqlite-payload
.
For the project template, choose “blank”.
When asked for the database, select SQLite (instead of MongoDB).
Leave the SQLite connection string as-is for now.
cd sqlite-payload
npm run dev
localhost:3000
./admin
to your URL (for example, localhost:3000/admin
).Once you log in successfully, your new Payload application is fully functioning. Notice that the first time you run the server, Payload automatically generates the SQLite database file usually something like sqlite-payload.db
.
For production deployments on platforms like Vercel, you can’t rely on a local file since containers are ephemeral. That’s where Turso comes in.
Turso provides a remote SQLite database, which means you can use SQLite even in serverless environments. I’m going to show you how to set up Turso with your Payload project.
turso auth signup
This will open a browser window where you can sign up with GitHub or your email.
Once the CLI is set up:
turso db create sqlite-payload
(or whatever name you want to give it)sqlite-payload
.Turso will create your database in the nearest data center (for me, that might be in Europe West or another region based on your location).
In Turso's Quickstart guide, you'll want to go to step 5 and select TypeScript/JavaScript. You’ll need the connection URL to hook up your Payload application to Turso.
It asks us to run: turso db show --url <database-name>
. In this case, it'll be turso db show --url sqlite-payload
This command returns the connection URL—copy it!
Next, return to the codebase and paste this URL into your environment variables. Look for the environment variable that Payload uses for the database URI (usually something like DATABASE_URI
). Replace the default local file URI with your Turso connection URL.
In addition to the connection URL, you need an authentication token to secure your connection to Turso.
payload.config.ts
)We also need to return to the environment variables and add:
Next, create that token. In your terminal, run: turso db tokens create sqlite-payload
This command will return an authentication token—copy it and add it as DATABASE_TOKEN
in your environment variables.
With the connection string and the authentication token in place:
npm run dev
localhost:3000/admin
).I hope you now see how incredibly easy it is to set up Payload with a SQLite database and even connect it to a remote service like Turso. To recap: