Dmmf in frontend
Hi,
I need to determine whether a database field is an array. To achieve this, I’ve created a function that uses Prisma's DMMF.
Additionally, I want to associate multilingual labels with each field in the database. For this, I’ve defined a typed object that maps each field to its translated labels.
These two pieces of information — whether a field is an array and its translations — need to be accessible from the frontend.
What would be the best way to structure and expose this data to the client ?
Thanks a lot for your help!
2 Replies
Skipping coffee for instant knowledge! Let's brew that AI answer now.
To determine if a field is an array and expose field translations to the frontend, you can use Prisma's DMMF (Data Model Meta Format) which contains schema metadata.
Accessing DMMF
You can access DMMF through the Prisma client:
Or through the Prisma object:
Note that this is an internal API that's not officially documented and might change in future versions Link to discussion.
Checking if a Field is an Array
The DMMF contains an
isList
property for each field that indicates whether it's an array:
Adding Multilingual Labels
For multilingual labels, there's no built-in solution yet. There's an open feature request for column labels in Prisma (Link to issue), but for now, you'll need to create your own solution.
Exposing to Frontend
Here's a suggested approach:
1. Create a server endpoint that exposes the necessary metadata:
2. Fetch this data in your frontend application and use it
as needed.
Remember that using DMMF directly is not part of the official API, so consider generating this metadata during build time if possible to avoid runtime dependencies on internal APIs.
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.That's the solution I was thinking of, but I'm not sure — maybe there's a better way to do it