ericnicolaas
ericnicolaas
PPrisma
Created by ericnicolaas on 8/8/2024 in #help-and-questions
How do I define type of returned object based on selected fields?
I have a function that fetches a client and optionally only selects some of the client props:
// Example implementation of clientSelect
const clientSelect = {
a: true,
b: true,
c: true
}

export const getClientById = async (
clientId: number,
select?: Prisma.ClientSelect
) => {
return await prisma.client.findFirst({
select: select || clientSelect,
where: {
id: clientId,
},
});
};
// Example implementation of clientSelect
const clientSelect = {
a: true,
b: true,
c: true
}

export const getClientById = async (
clientId: number,
select?: Prisma.ClientSelect
) => {
return await prisma.client.findFirst({
select: select || clientSelect,
where: {
id: clientId,
},
});
};
I would like to be able to call getClientById and have the return type correctly inferred based on what is passed for select. For example:
const myClient = getClientById(333, { a: true })

// I want TypeScript to understand that myClient contains a and doesn't contain b and c
const myClient = getClientById(333, { a: true })

// I want TypeScript to understand that myClient contains a and doesn't contain b and c
What is the correct way to achieve this?
1 replies
PPrisma
Created by ericnicolaas on 6/28/2024 in #help-and-questions
Invalidating/flushing cache in Accelerate
We're using Accelerate but haven't started using the caching mechanism. From reading the docs, I'm not seeing any obvious way to flush/invalidate cache on the fly. We have some slow queries which we would like to cache, but these queries are used in report generation, so we would want to be able to refresh the cache when new data has been added which changes the report data. What is the recommended approach for achieving this with Prisma Accelerate?
2 replies
PPrisma
Created by ericnicolaas on 5/8/2024 in #help-and-questions
Does Accelerate support using cacheStrategy with groupBy queries on a view?
I'm trying to define a cache strategy for a groupBy query on a view. TypeScript is flagging an error though, saying the type for cacheStrategy is never. From reading the docs for Accelerate it looks like the cache strategy may only be possible on queries on models. Can someone confirm if that's the case?
1 replies