How to use LibSql with Prisma 7.0.0?

this is how I used to do it but now that adapter and studio configs are deprecated and datasource doesn't allow me to set DATABASE_TOKEN, how should i do it?
export default defineConfig({
experimental: {
adapter: true,
studio: true,
},
schema: './prisma',
migrations: {
path: 'prisma/migrations',
seed: 'tsx ./prisma/seed.ts',
},
typedSql: {
path: 'prisma/sql',
},
studio: {
async adapter() {
return new PrismaLibSql({
url: env("DATABASE_URL"),
authToken: env("DATABASE_TOKEN"),
})
},
},
async adapter() {
return new PrismaLibSql({
url: env("DATABASE_URL"),
authToken: env("DATABASE_TOKEN"),
})
},
engine: "js",
})
export default defineConfig({
experimental: {
adapter: true,
studio: true,
},
schema: './prisma',
migrations: {
path: 'prisma/migrations',
seed: 'tsx ./prisma/seed.ts',
},
typedSql: {
path: 'prisma/sql',
},
studio: {
async adapter() {
return new PrismaLibSql({
url: env("DATABASE_URL"),
authToken: env("DATABASE_TOKEN"),
})
},
},
async adapter() {
return new PrismaLibSql({
url: env("DATABASE_URL"),
authToken: env("DATABASE_TOKEN"),
})
},
engine: "js",
})
3 Replies
Prisma AI Help
You've gone full bot mode! Let me fetch that AI answer for you ASAP. As of Prisma 7.0.0, the adapter and studio config options in the Prisma config file are deprecated. The new approach is to use the built-in datasource block in your Prisma schema for configuration, but this block does not support passing an auth token (like DATABASE_TOKEN) directly. How to use LibSQL with Prisma 7.0.0: - You should now provide your LibSQL (Turso) connection details—including the auth token—directly in your application code when instantiating the Prisma Client, not in the Prisma config or schema. - The recommended way is to use the @prisma/adapter-libsql package and pass both the url and authToken to the adapter in your application code. Example:
import { PrismaClient } from '@prisma/client'
import { PrismaLibSQL } from '@prisma/adapter-libsql'

const adapter = new PrismaLibSQL({
url: process.env.DATABASE_URL,
authToken: process.env.DATABASE_TOKEN,
})

const prisma = new PrismaClient({ adapter })
import { PrismaClient } from '@prisma/client'
import { PrismaLibSQL } from '@prisma/adapter-libsql'

const adapter = new PrismaLibSQL({
url: process.env.DATABASE_URL,
authToken: process.env.DATABASE_TOKEN,
})

const prisma = new PrismaClient({ adapter })
- In your schema.prisma, you still need a datasource block, but the url can be a placeholder (e.g., env("DATABASE_URL")). The actual connection and authentication are handled in your application code, not in the schema or config file. Note:
- For migrations and CLI commands, you may need to ensure your environment variables are set so the CLI can connect using the url in your schema. The authToken is not used by the CLI, so migrations may not work with protected databases unless support is added in future Prisma versions. - If you need to use migrations with authentication, you may need to wait for further updates or use workarounds, as the knowledge sources do not provide a solution for passing authToken to the CLI in Prisma 7.0.0. References:
- Prisma Turso docs - Driver adapters API changes If you need CLI support for migrations with an auth token, the knowledge sources do not provide a clear solution for Prisma 7.0.0.
identity
identityOP2w ago
i still want to see what the config file should look like. Also, avoiding the config file means that I won't be able to use studio and potentially have issues with generation.
Prisma AI Help
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.

Did you find this page helpful?