Skip to content

Middleware params model should be an enum or union of strings. #3545

@dilizarov

Description

@dilizarov

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.

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions