Problem
prisma.$use(async (params, next) => {
if (params.model === "User") {
//process
}
});
In the above, params.model is typed as a string, when the prisma client generated should be able to deduce the models based on the schema.prisma file and form a union.
Suggested solution
If a schema.prisma has models User, Project, Task for instance, then params.model should be typed as "User" | "Project" | "Task". If we had an enum, it could even params.model: Model
Ideally, we'd also have an enum we could leverage:
import { Model } from "@prisma/client";
Model.User // "User"
Model.Project // "Project"
Model.Task // "Task"
// This would allow for:
prisma.$use(async (params, next) => {
switch (params.model) {
case Model.User:
case Model.Project:
...
}
})
This should all be deduced and generated from the schema.prisma.
Additional context
This is largely a QoL improvement.
Problem
In the above, params.model is typed as a
string, when the prisma client generated should be able to deduce the models based on the schema.prisma file and form a union.Suggested solution
If a schema.prisma has models User, Project, Task for instance, then
params.modelshould be typed as"User" | "Project" | "Task". If we had an enum, it could evenparams.model: ModelIdeally, we'd also have an enum we could leverage:
This should all be deduced and generated from the schema.prisma.
Additional context
This is largely a QoL improvement.