You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The aim of this proposal is to provide a sneak-peek for the new feature that will be added to Prisma Util v2.0. In this issue, I'll be outlining the process of defining a function and how the configuration will look like, so you can make preparations in advance.
Introduction
This feature will be released under the customAttributeFunctions flag and will require manual activation.
Configuration
To set a default function for a field, we can just do this:
functiongenerateDefault(dmmf){// Generate your default value based on the DMMF data of this fieldconstdefaultValue="";returndefaultValue;}exportdefault{// Other configuration valuesdefaultFunctions: {"path/to/file:ModelName.field": generateDefault}}
The function will then be grabbed by Prisma Util and added to a function map. To copy the function over, Prisma Util will use .toString() on the provided function and wrap the code in another function, as such:
constcolumnMappings={"ModelName.field": function(){constfunc=functiongenerateDefault(dmmf){// Generate your default value based on the DMMF data of this fieldconstdefaultValue="";returndefaultValue;}returnfunc;}(),}
Middleware
This feature makes use of Project Toolchain's Middleware API and defines a middleware called attributeFunctions. To use it, you have to import it like this and add it to your Prisma middleware chain:
Scope
The aim of this proposal is to provide a sneak-peek for the new feature that will be added to Prisma Util v2.0. In this issue, I'll be outlining the process of defining a function and how the configuration will look like, so you can make preparations in advance.
Introduction
This feature will be released under the
customAttributeFunctions
flag and will require manual activation.Configuration
To set a default function for a field, we can just do this:
The function will then be grabbed by Prisma Util and added to a function map. To copy the function over, Prisma Util will use
.toString()
on the provided function and wrap the code in another function, as such:Middleware
This feature makes use of Project Toolchain's Middleware API and defines a middleware called
attributeFunctions
. To use it, you have to import it like this and add it to your Prisma middleware chain:And that's it! Now everything will function correctly whenever you create a new model.
Final Words
Please let us know if this is suitable for you and if you would like any changes to be made.
The text was updated successfully, but these errors were encountered: