P
Prisma•7mo ago
Faith

Error validating datasource `db`: the URL must start with the protocol `prisma://`

Hello everyone! Im currently getting this problem that i descriped in the title. where when i try to run Prisma on cloudflare workers i tried the soultion from here "https://www.prisma.io/docs/orm/reference/prisma-client-reference#programmatically-override-a-datasource-url" but cant seem to get it to work .dev.vars DATABASE_URL="DATABASE_URL=postgresql://postgres:@localhost:5432/postgres?schema=test" this is my prisma client
import { PrismaClient } from "@prisma/client/edge";

export const db = new PrismaClient({
datasources: {
db: {
url: 'file:../src/dev.vars',
},
},
})
import { PrismaClient } from "@prisma/client/edge";

export const db = new PrismaClient({
datasources: {
db: {
url: 'file:../src/dev.vars',
},
},
})
my schema.prisma
generator client {
provider = "prisma-client-js"
engineType = "binary"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
engineType = "binary"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
and when i try to add "prisma://" in the front it says "api key needed"
Prisma Client API | Prisma Documentation
API reference documentation for Prisma Client.
10 Replies
jonfanz
jonfanz•7mo ago
hmm I don't think that will work. DATABASE_URL="DATABASE_URL=postgresql://postgres:@localhost:5432/postgres?schema=test" isn't a valid string, it should just be something like DATABASE_URL=postgresql://postgres:@localhost:5432/postgres?schema=test but even then, there is no PostgreSQL database hosted at localhost on cloudflare workers. This documentation (specific to Cloudflare) might help.
Deploy to Cloudflare Workers & Pages | Prisma Documentation
Learn the things you need to know in order to deploy an app that uses Prisma Client for talking to a database to a Cloudflare Worker or to Cloudflare Pages.
Faith
FaithOP•7mo ago
Hey i done this and still dont work i still get "the URL must start with the protocol prisma://" i did prisma generate also im trying to set it up locally first or is that not going to work at all? i have now tried this way aswell
fetch: async (request: Request, env: Environment, ctx: ExecutionContext) => {
var prisma = await db(env.DATABASE_URL)

env = { ...env, prisma }

await app.fetch(request, env, ctx);
},
fetch: async (request: Request, env: Environment, ctx: ExecutionContext) => {
var prisma = await db(env.DATABASE_URL)

env = { ...env, prisma }

await app.fetch(request, env, ctx);
},
and then i tried to call it in my router like this
async (data: any, prisma: PrismaClient) => {
const result = await prisma.search.create({
data: {
results: data.results,
createdAt: data.createdAt,
currentCycleIsDone: data.currentCycleIsDone,
noMoreResults: data.noMoreResults,
availableCycles: data.availableCycles,
searchInput: data.searchInput
}
})

console.log('Search created:', result)

return result
}
async (data: any, prisma: PrismaClient) => {
const result = await prisma.search.create({
data: {
results: data.results,
createdAt: data.createdAt,
currentCycleIsDone: data.currentCycleIsDone,
noMoreResults: data.noMoreResults,
availableCycles: data.availableCycles,
searchInput: data.searchInput
}
})

console.log('Search created:', result)

return result
}
im using cloudflare workers + hono btw also updated the db that i export like this
export const db = (databaseUrl: string) => new PrismaClient({
datasources: {
db: {
url: databaseUrl,
},
},
})
export const db = (databaseUrl: string) => new PrismaClient({
datasources: {
db: {
url: databaseUrl,
},
},
})
jonfanz
jonfanz•7mo ago
This is happening locally? What command are you running to start your app? What version of @prisma/client are you using?
Faith
FaithOP•7mo ago
@Jon Harrell To start it wrangler dev src/index.ts and "@prisma/client": "5.12.1", i think im just going to use cloudflare d1
jonfanz
jonfanz•7mo ago
That will work a lot better. I'm not sure if there's a way to test a local DB against wrangler. Some will work: https://developers.cloudflare.com/workers/databases/connecting-to-databases/ but in general, I'd say that D1 will be the most straightforward 🙂
Cloudflare Docs
Connect to databases · Cloudflare Workers docs
Learn about the different kinds of database integrations Cloudflare supports.
Faith
FaithOP•7mo ago
Alright thank you so much!
Aladin El-Khalil
Aladin El-Khalil•2mo ago
Hello @Jon Harrell, I'm having the same issue error when deploying my Next application to Vercel. Everything works fine locally. I have triple-checked env variables on Vercel and they're the same as my env locally. I also get this error if I build the project and run prod environment locally without deploying to Vercel. Any idea what might cause this; and how to solve it?
Aladin El-Khalil
Aladin El-Khalil•2mo ago
No description
Aladin El-Khalil
Aladin El-Khalil•2mo ago
I'm new on Discord. Used the search bar to find this post. Wasn't sure if I'm supposed to continue the discussion here or start a new post.
jonfanz
jonfanz•2mo ago
Start a new one, please 🙂
Want results from more Discord servers?
Add your server