-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimize recommendation for db.money (#6517)
- Loading branch information
1 parent
5032bd3
commit 8439c2b
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
content/700-optimize/400-recommendations/600-avoid-db-money.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
title: 'Using @db.Money' | ||
metaTitle: 'Optimize Recommendations: Avoid usage of `@db.Money`' | ||
metaDescription: "Learn about the recommendation provided by Optimize for using `@db.Money` native type." | ||
tocDepth: 3 | ||
toc: true | ||
--- | ||
|
||
Optimize provides recommendations to help you identify and resolve performance issues caused by the use of `@db.Money` type. | ||
|
||
The following model uses the `@db.Money` native type: | ||
|
||
```prisma | ||
model Item { | ||
// ... | ||
price Decimal @db.Money | ||
// ... | ||
} | ||
``` | ||
|
||
## What is the problem? | ||
|
||
The `@db.Money` data type in PostgreSQL is not ideal for storing monetary values. Internally, `@db.Money` is implemented as an integer, which offers speed but lacks flexibility. It handles fractional values and rounding in unexpected ways, which can lead to inaccuracies. | ||
|
||
Additionally, the `@db.Money` type does not store any information about the associated currency. Instead, it relies on the global `lc_monetary` locale setting, which may not be suitable for all use cases. | ||
|
||
For more information, refer to the [PostgreSQL documentation](https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_money). | ||
|