If you worked with Prisma, keep on reading, please
I know it may sound mean to somebody that I request it, but I am definitely beyond just asking for help..., and managing type inference is not easy at all. Generally, querying with Prisma looks like the following
const users = await db.user.findMany({
where: { name: 'dnartsbeW' }
})
but I need this particular approach
const users = await query('user', 'findMany', {
where: { name: 'dnartsbeW' }
})
You may have already guessed why, but if not, I'll tell you anyways. query is a server action/function that cannot get callbacks from the client, because they are not serializable, unlike strings and objects. query would look like the following from the inside
// actions.ts
'use server'
import { db } from '#/prisma'
import { Prisma } from '@prisma/client'
// Mind the types, I have no idea what they should be
export async function query(model: Lowercase<Prisma.ModelName>, operation: ..., filter: ...) {
const res = await db[model][func](filter)
return res
}
This function works alright however types are broken as I could not figure out what type of operation and filter should be. Also, there should be some use of generics to infer the return type.
With the above code, model is inferred, operation, filter and return type are not inferred.
If you would like to help, website of Prisma has AI assistant, it works 50/50 on the time, but is aware of the internal types like no else AI