Prisma and Hono on Cloudflare Workers
Hello everyone, I am trying to connect with database using hono and prisma.
Current Configs:
.env
prisma.ts
prisma.schema
index.ts
When I am sending a post request getting this kind of error.
If you could please help.
DATABASE_URL="postgresql://u:[email protected]/db-name?sslmode=require"
DATABASE_URL="postgresql://u:[email protected]/db-name?sslmode=require"
import { Pool, neonConfig } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@prisma/client'
import dotenv from 'dotenv'
import ws from 'ws'
dotenv.config()
neonConfig.webSocketConstructor = ws
const connectionString = `${process.env.DATABASE_URL}`
const pool = new Pool({ connectionString })
const adapter = new PrismaNeon(pool)
const prisma = new PrismaClient({ adapter })
export default prisma;
import { Pool, neonConfig } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@prisma/client'
import dotenv from 'dotenv'
import ws from 'ws'
dotenv.config()
neonConfig.webSocketConstructor = ws
const connectionString = `${process.env.DATABASE_URL}`
const pool = new Pool({ connectionString })
const adapter = new PrismaNeon(pool)
const prisma = new PrismaClient({ adapter })
export default prisma;
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
email String @unique
name String
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
email String @unique
name String
}
import { Hono } from 'hono';
import prisma from '../prisma/prisma';
const app = new Hono();
app.post('/:version', async (c) => {
const body = await c.req.json();
const version = c.req.param("version");
const newUser = await prisma.user.create({
data: {
name: body.name,
email: body.email,
},
});
return c.json(newUser);
});
export default app;
import { Hono } from 'hono';
import prisma from '../prisma/prisma';
const app = new Hono();
app.post('/:version', async (c) => {
const body = await c.req.json();
const version = c.req.param("version");
const newUser = await prisma.user.create({
data: {
name: body.name,
email: body.email,
},
});
return c.json(newUser);
});
export default app;
0 Replies