Skip to content

Commit 3619875

Browse files
AmanVarshney01aidankmcalister
authored andcommitted
update turso guide (#7274)
1 parent b1543d7 commit 3619875

File tree

1 file changed

+26
-52
lines changed

1 file changed

+26
-52
lines changed

content/200-orm/050-overview/500-databases/900-turso.mdx

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
---
22
title: 'Turso'
3-
metaTitle: 'Turso (Early Access)'
3+
metaTitle: 'Turso'
44
metaDescription: 'Guide to Turso'
55
tocDepth: 3
66
---
77

88
This guide discusses the concepts behind using Prisma ORM and Turso, explains the commonalities and differences between Turso and other database providers, and leads you through the process for configuring your application to integrate with Turso.
99

10-
Prisma ORM support for Turso is currently in [Early Access](/orm/more/releases#early-access). We would appreciate your feedback in this [GitHub discussion](https://github.com/prisma/prisma/discussions/21345).
10+
::::note[Preview feature]
11+
There's a Turso preview feature that integrates with Prisma CLI workflows. See the [GitHub discussion](https://github.com/prisma/prisma/discussions/21345) and share feedback there.
12+
::::
1113

1214
## What is Turso?
1315

1416
[Turso](https://turso.tech/) is an edge-hosted, distributed database that's based on [libSQL](https://turso.tech/libsql), an open-source and open-contribution fork of [SQLite](https://sqlite.org/), enabling you to bring data closer to your application and minimize query latency. Turso can also be hosted on a remote server.
1517

16-
:::warning
17-
Support for Turso is available in [Early Access](/orm/more/releases#early-access) from Prisma ORM versions 5.4.2 and later.
18-
:::
19-
2018
## Commonalities with other database providers
2119

2220
libSQL is 100% compatible with SQLite. libSQL extends SQLite and adds the following features and capabilities:
@@ -104,68 +102,44 @@ const prisma = new PrismaClient({ adapter })
104102

105103
You can use Prisma Client as you normally would with full type-safety in your project.
106104

107-
## Using Prisma Migrate via a driver adapter in Prisma Config
108-
109-
As of [Prisma v6.6.0](https://github.com/prisma/prisma/releases/tag/6.6.0) we added support for the Prisma Config file. You can use the Prisma Config file to perform `prisma db push` and make changes to your database schema. You can learn more about [the Prisma Config file in our reference page](/orm/reference/prisma-config-reference).
110-
111-
### 1. Install the LibSQL driver adapter
112-
113-
Run this command in your terminal:
114-
115-
```termina
116-
npm install @prisma/adapter-libsql
117-
```
118-
119-
### 2. Set environment variables
120-
121-
In order to set up the LibSQL adapter, you'll need to add a few secrets to a `.env` file:
105+
## Manage schema changes with Turso
122106

123-
- `LIBSQL_DATABASE_URL`: The connection URL of your Turso database instance.
124-
- `LIBSQL_DATABASE_TOKEN`: The token of your Turso database instance.
107+
Prisma CLI commands such as `prisma migrate dev` or `prisma db push` require a local SQLite connection. To roll out schema changes to Turso, use this workflow:
125108

126-
You can then add these to your `.env` file or use them directly if they are stored in a different secret store:
109+
1. **Configure Prisma CLI to target a local SQLite file.**
110+
Update `.env` and `prisma.config.ts` so Prisma CLI commands write to the local file instead of your remote Turso database:
127111

128-
```bash file=.env
129-
LIBSQL_DATABASE_URL="..."
130-
LIBSQL_DATABASE_TOKEN="..."
112+
```bash file=.env showLineNumbers
113+
LOCAL_DATABASE_URL="file:./dev.db"
131114
```
132115

133-
### 3. Set up Prisma Config file
134-
135-
Make sure that you have a [`prisma.config.ts`](/orm/reference/prisma-config-reference) file for your project. Then, set up the [migration driver adapter](/orm/reference/prisma-config-reference#adapter-removed) to use `PrismaLibSQL`:
136-
137-
```ts file=prisma.config.ts
138-
import path from 'node:path'
139-
import { defineConfig } from 'prisma/config'
140-
import { PrismaLibSQL } from '@prisma/adapter-libsql'
141-
142-
// import your .env file
116+
```ts file=prisma.config.ts showLineNumbers
143117
import 'dotenv/config'
118+
import { defineConfig, env } from 'prisma/config'
144119

145120
export default defineConfig({
146-
experimental: {
147-
adapter: true,
121+
schema: 'prisma/schema.prisma',
122+
migrations: {
123+
path: 'prisma/migrations',
124+
},
125+
datasource: {
126+
url: env('LOCAL_DATABASE_URL'),
148127
},
149-
schema: path.join('prisma', 'schema.prisma'),
150-
async adapter() {
151-
return new PrismaLibSQL({
152-
url: process.env.LIBSQL_DATABASE_URL,
153-
authToken: process.env.LIBSQL_DATABASE_TOKEN,
154-
})
155-
}
156128
})
157129
```
158130

159-
### 4. Migrate your database
160-
161-
Prisma Migrate now will run migrations against your remote Turso database based on the configuration provided in `prisma.config.ts`.
131+
2. **Generate migrations locally.**
132+
Run `prisma migrate dev --name <migration-name>` to update the local SQLite database and produce SQL files in `prisma/migrations`.
162133

163-
To create your first migration with this workflow, run the following command:
134+
3. **Apply the generated SQL using the Turso CLI.**
135+
Use the [`turso db shell` command](https://docs.turso.tech/cli/introduction) to run the SQL against your remote database (replace `test` with your database name):
164136

165-
```terminal
166-
npx prisma db push
137+
```bash showLineNumbers
138+
turso db shell test < ./prisma/migrations/20251118131940_init/migration.sql
167139
```
168140

141+
Replace the database name (`test`) and migration folder (`20251118131940_init`) with the values produced by `prisma migrate dev`.
142+
169143
## Embedded Turso database replicas
170144

171145
Turso supports [embedded replicas](https://turso.tech/blog/introducing-embedded-replicas-deploy-turso-anywhere-2085aa0dc242). Turso's embedded replicas enable you to have a copy of your primary, remote database _inside_ your application. Embedded replicas behave similarly to a local SQLite database. Database queries are faster because your database is inside your application.

0 commit comments

Comments
 (0)