Mattèo
Mattèo
Explore posts from servers
PPrisma
Created by Mattèo on 10/31/2024 in #help-and-questions
How to use set a relation and update in the same time rows
Hey ! I wanted to know if someone know how to achieve this :
const data: Prisma.ModuleUpdateInput = {
name: input.name,
description: input.description,
course: {
connect: {
id: input.course,
},
},
// Here is a one to many relation with Module <-* Lesson
lessons:
lessons.length > 0
? {
set: lessons.map((lessonId, index) => ({
id: lessonId,
// Adding this field don't works, only the first item is linked
order: index,
})),
}
: undefined,
}
const data: Prisma.ModuleUpdateInput = {
name: input.name,
description: input.description,
course: {
connect: {
id: input.course,
},
},
// Here is a one to many relation with Module <-* Lesson
lessons:
lessons.length > 0
? {
set: lessons.map((lessonId, index) => ({
id: lessonId,
// Adding this field don't works, only the first item is linked
order: index,
})),
}
: undefined,
}
Has anyone had this problem before, or can anyone help me? Wishing you a good day 😉
2 replies
PPrisma
Created by Mattèo on 7/19/2024 in #help-and-questions
Slowness issue when using Supavisor connection pooling with Prisma
Hey Prisma community, I've set up Supabase Supavisor connection pooling on my Supabase project but it turns out that the request is abnormally slow with Prisma when I use supavisor. I compared the time it took to make a request with console.time and the result was clear. The tests are done locally with a remote postgres database hosted on Supabase with Supavisor enabled. I have the latest version of Prisma installed Here is my connection string in my .env
# Slow setup for Supabase with Supavisor
DATABASE_URL="postgres://postgres.project_id:[email protected]:6543/postgres?pgbouncer=true&connection_limit=1"
DIRECT_DATABASE_URL="postgres://postgres.project_id:[email protected]:5432/postgres"

# Fast setup for Supabase without using Supavisor
DATABASE_URL="postgres://postgres.project_id:[email protected]:5432/postgres"
DIRECT_DATABASE_URL="postgres://postgres.project_id:[email protected]:5432/postgres"
# Slow setup for Supabase with Supavisor
DATABASE_URL="postgres://postgres.project_id:[email protected]:6543/postgres?pgbouncer=true&connection_limit=1"
DIRECT_DATABASE_URL="postgres://postgres.project_id:[email protected]:5432/postgres"

# Fast setup for Supabase without using Supavisor
DATABASE_URL="postgres://postgres.project_id:[email protected]:5432/postgres"
DIRECT_DATABASE_URL="postgres://postgres.project_id:[email protected]:5432/postgres"
// schema.prisma

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
// schema.prisma

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
console.time("totalStudents");
const totalStudents = await db.user.count({
where: {
role: "STUDENT",
},
});
console.timeEnd("totalStudents");
console.time("totalStudents");
const totalStudents = await db.user.count({
where: {
role: "STUDENT",
},
});
console.timeEnd("totalStudents");
With Supavisor : 291.246ms Without Supavisor (same connection string in DATABASE_URLand DIRECT_DATABASE_URL) : 52.009ms Does someone can help me ? Have a nice day😉
2 replies