riccardolardi
riccardolardi
Explore posts from servers
PPrisma
Created by riccardolardi on 7/25/2024 in #help-and-questions
findMany where first/latest of 1:n relation meets certain condition
Bump... pseudo code could look like this:
{
where: {
myRelation: {
first: {
myField: {
equals: "some value"
}
}
}
}
{
where: {
myRelation: {
first: {
myField: {
equals: "some value"
}
}
}
}
3 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 6/7/2023 in #questions
React guarantee updated state variable
I see. My usecase is a bit different than in the contrived example I gave. The state is in a context and is checked somewhere else, not directly referenced. It does "seem" to work so far
15 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 6/7/2023 in #questions
React guarantee updated state variable
why?
15 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 6/7/2023 in #questions
React guarantee updated state variable
@barry thanks. Ugly hack would be to use a setTimeout to bypass react state update cycle
15 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 4/22/2023 in #questions
Prisma nested write issue
8 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 4/22/2023 in #questions
Prisma nested write issue
@joerambo sure here you go
prisma.application.create({
data: {
form: {
connect: {
id: input.formId,
},
},
title: input.content["application-title"],
content: input.content,
applicant: {
connectOrCreate: {
where: {
email: input.content["applicant-email"],
},
create: {
fullname: input.content["applicant-fullname"],
email: input.content["applicant-email"],
address: input.content["applicant-address"],
phone: input.content["applicant-phone"],
},
},
},
},
});
prisma.application.create({
data: {
form: {
connect: {
id: input.formId,
},
},
title: input.content["application-title"],
content: input.content,
applicant: {
connectOrCreate: {
where: {
email: input.content["applicant-email"],
},
create: {
fullname: input.content["applicant-fullname"],
email: input.content["applicant-email"],
address: input.content["applicant-address"],
phone: input.content["applicant-phone"],
},
},
},
},
});
8 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 4/22/2023 in #questions
Prisma nested write issue
I figured it out with the help of Prisma support:
When performing a create operation, data is the type of XOR<ApplicationCreateInput,ApplicationUncheckedCreateInput > which means you can either provide ApplicationCreateInput which will have all nested relations specified or you can directly provide the ID as in the case of applicantId field but you can’t mix them. So you will need to use the fields specified in ApplicationUncheckedCreateInput in order to create it. Also, Unchecked input types allow you to perform some operations that Prisma considers dangerous like directly writing foreign keys. Prisma allows you to choose either a safe or an unchecked input type when doing operations like create. In this case, Prisma wants you to perform the create action using the Unchecked input type.
When performing a create operation, data is the type of XOR<ApplicationCreateInput,ApplicationUncheckedCreateInput > which means you can either provide ApplicationCreateInput which will have all nested relations specified or you can directly provide the ID as in the case of applicantId field but you can’t mix them. So you will need to use the fields specified in ApplicationUncheckedCreateInput in order to create it. Also, Unchecked input types allow you to perform some operations that Prisma considers dangerous like directly writing foreign keys. Prisma allows you to choose either a safe or an unchecked input type when doing operations like create. In this case, Prisma wants you to perform the create action using the Unchecked input type.
8 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 4/22/2023 in #questions
Prisma nested write issue
@joerambo the error still remains. I'm completely dazzled why this doesn't work
8 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 3/31/2023 in #questions
Global data fetching
You can't use gSSP / gSP in _app.tsx (where one could pass data down to children or store it in global state for everyone to consume)
10 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 3/31/2023 in #questions
Global data fetching
This makes sense for client-side data fetching but what if I needed the data already on server side to populate the pages / components before getting the response back?
10 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 3/30/2023 in #questions
Basic app architecture question for Auth/session state retrieval & storage
@barry I solved the infinite loop problem using useEffect see my updated original question. Now the question is just about the pattern really. Whether this is a common pattern and if there's a better practice of handling such case
33 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 3/30/2023 in #questions
Basic app architecture question for Auth/session state retrieval & storage
no because it's outside of supabase <SessionContextProvider>. That's why I use the renderless <AuthStateGrabber> component
33 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 3/30/2023 in #questions
Basic app architecture question for Auth/session state retrieval & storage
no. just a different table
33 replies
TTCTheo's Typesafe Cult
Created by riccardolardi on 3/30/2023 in #questions
Basic app architecture question for Auth/session state retrieval & storage
it's a renderless component
33 replies