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
TtRPC
Created by Mattèo on 2/14/2024 in #❓-help
Can I perform react query queries without using a trpc procedure, using useQuery standalone
Hey, I need to perform a client site request, and I can't implement it with TRPC, so can I use regular useQuery method in my Next.js app ? Will the useQuery will be attached to the React Query context of TRPC ?
2 replies
TTCTheo's Typesafe Cult
Created by Mattèo on 1/16/2024 in #questions
How to authenticate users on a dynamic sudomain (next-auth)
Hey ! Hope you're doing well, I'm working on a project and I try to implement authentication on multiple domain with next-auth and Next.js Pages router. Here is a basic schema : - app.localhost:3000 (Admin only subdomain for managing the app, authentication needed) - [tenant].localhost:3000 (Authentication needed here using next-auth) Can someone help me with this. Currently, I got it working but I can't access session while i'm calling useSession from [tenant].localhost:3000. My NEXTAUTH_URL is http://app.localhost:3000
5 replies
TtRPC
Created by Mattèo on 12/31/2023 in #❓-help
How to handle Query Errors on client side (show toast on 401)
Hey ! Hope you're doing well ! I wanted to know if someone can explain to me how to handle errors on the client (using Next.js). I need to handle UNAUTHENTICATED error on client because when a user tries to access a resource I want to display a feedback toast. Thanks 🙏
3 replies
TtRPC
Created by Mattèo on 12/9/2023 in #❓-help
How to create a React Component that fetch API based on a router from props ?
I want to pass in my React component props the name of the router to use, here is my current implementation :
export const RowActionDeleteButton = ({ id, model}: { id: string; model : 'lesson' | 'module' }) => {
const router = useRouter()

const deleteMutation = api[model].delete.useMutation({
onSuccess: () => {
router.reload()
toast.success(`Key ${id} deleted`)
},
onError: (err, variables) => {
router.reload()
toast.error(`Error deleting key ${id}`)
console.error(err, variables)
},
})

return (
// Error here : Type '[]' has no properties in common with type...
<Button variant="destructive" onClick={() => deleteMutation.mutate({ id })}>
Delete
</Button>
)
}
export const RowActionDeleteButton = ({ id, model}: { id: string; model : 'lesson' | 'module' }) => {
const router = useRouter()

const deleteMutation = api[model].delete.useMutation({
onSuccess: () => {
router.reload()
toast.success(`Key ${id} deleted`)
},
onError: (err, variables) => {
router.reload()
toast.error(`Error deleting key ${id}`)
console.error(err, variables)
},
})

return (
// Error here : Type '[]' has no properties in common with type...
<Button variant="destructive" onClick={() => deleteMutation.mutate({ id })}>
Delete
</Button>
)
}
Does someone already achieve something like this ?
3 replies
RRailway
Created by Mattèo on 9/29/2023 in #✋|help
Does timescaledb and PostGIS are installed on the postgres-ssl image ?
No description
18 replies
RRailway
Created by Mattèo on 9/10/2023 in #✋|help
Change region for Postgres Database
Hey ! Congratulations for the launch of deployment region ! Now, how can I migrate my db to another region (eu resident) Byee
8 replies
RRailway
Created by Mattèo on 8/5/2023 in #✋|help
How to execute command on a deployment ?
Hey ! I wanted to know how to execute a command on a deployed service, I have small script in my project to initialize an admin account, but this script needs to be executed with a started service. Is it possible to connect with SSH to an instance, or to execute a command after starts of a service ? Bye
7 replies
RRailway
Created by Mattèo on 5/23/2023 in #✋|help
Issue with Railway CLI auth (404)
Hey ! When I run railway login or railway whoami I get this error (freshly installed, internet ok)
railway whoami
🚨 Response not successful status=404

railway login
🚨 Response not successful status=404
railway whoami
🚨 Response not successful status=404

railway login
🚨 Response not successful status=404
10 replies
TTCTheo's Typesafe Cult
Created by Mattèo on 3/6/2023 in #questions
Best ways to render a React component conditionally with Next (based on build time conditions)
1 replies
TTCTheo's Typesafe Cult
Created by Mattèo on 3/6/2023 in #questions
How to use react-query with the create-t3-app starter (non-TRPC call) ?
Hey ! I wanted to know if someone know how to use react-query with the create-t3-app starter. The starter seems to use react-query but there is no QueryClientProvider in the _app.tsx.
6 replies
TTCTheo's Typesafe Cult
Created by Mattèo on 3/3/2023 in #questions
What are the best ways to use TRPC procedures in getStaticProps ?
I wanted to know how can I use procedures made on my router from getStaticProps method
3 replies
TtRPC
Created by Mattèo on 1/4/2023 in #❓-help
React Native Usage
Hello, I wanted to know if trpc can be used with react native ? And is it possible on a bare react native cli project ? Thanks, have a nice day !
2 replies