Usage of `@map` and `@@map` as a best practice to name tables and columns in a database
Say we have a legacy database somewhere that has its table names and column names.
One way to use
@map
and @@map
is to ensure that the names of our models and fields map to the names of the tables and columns, respectively in that database.
Apart from this use case, can I use these as a best practice whenever I am creating my Models where essentially a legacy database does not exist but I am building from scratch.
Example: When I define a Model named Category
and I use
Here the reason for using @@map
is just to ensure that the new table created in my database has the name categories
.
Essentially, this way I am thinking about what names I can pick for the columns and tables in my real database.3 Replies
You decided to hold for human wisdom. We'll chime in soon! Meanwhile,
#ask-ai
is there if you need a quick second opinion.Hey 👋
Yes, you can use
@map
and @@map
as a best practice even when building a database from scratch. This approach allows you to define your Prisma models and fields using naming conventions that are more natural or preferred in your application code, while still controlling the exact names used in the underlying database.Thanks so much ❤️ .