Abhaykd
CDCloudflare Developers
•Created by Abhaykd on 7/11/2024 in #workers-help
Unable to setup prisma accelerate with cloudflare workers
index.ts
import { PrismaClient } from '@prisma/client/edge';
import { withAccelerate } from '@prisma/extension-accelerate';
export default {
async fetch(request, env, ctx): Promise<Response> {
const prisma = new PrismaClient().$extends(withAccelerate());
console.log(env);
const user = await prisma.user.findMany({
where: {
email: {
contains: '[email protected]',
},
},
cacheStrategy: { swr: 60, ttl: 60 },
});
console.log(user);
return new Response('Hello World!');
},
} satisfies ExportedHandler<Env>;
import { PrismaClient } from '@prisma/client/edge';
import { withAccelerate } from '@prisma/extension-accelerate';
export default {
async fetch(request, env, ctx): Promise<Response> {
const prisma = new PrismaClient().$extends(withAccelerate());
console.log(env);
const user = await prisma.user.findMany({
where: {
email: {
contains: '[email protected]',
},
},
cacheStrategy: { swr: 60, ttl: 60 },
});
console.log(user);
return new Response('Hello World!');
},
} satisfies ExportedHandler<Env>;
.env
DATABASE_URL="prisma accelerate api key"
DIRECT_URL="database uri string"
wrangler.toml
name = "app2"
main = "src/index.ts"
compatibility_date = "2024-07-01"
compatibility_flags = ["nodejs_compat"]
[vars]
DATABASE_URL = "prisma accelerate api key"
name = "app2"
main = "src/index.ts"
compatibility_date = "2024-07-01"
compatibility_flags = ["nodejs_compat"]
[vars]
DATABASE_URL = "prisma accelerate api key"
schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
Invalid `prisma.user.findMany()` invocation: error: Environment variable not found: DATABASE_URL. In Cloudflare module Workers, environment variables are available only in the Worker's `env` parameter of `fetch`. To solve this, provide the connection string directly: https://pris.ly/d/cloudflare-datasource-url
Invalid `prisma.user.findMany()` invocation: error: Environment variable not found: DATABASE_URL. In Cloudflare module Workers, environment variables are available only in the Worker's `env` parameter of `fetch`. To solve this, provide the connection string directly: https://pris.ly/d/cloudflare-datasource-url
5 replies