Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize recommendation for db.money #6517

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions content/700-optimize/300-recordings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ When a recording session ends, Optimize generates recommendations such as:
- [Queries on unindexed columns](/optimize/recommendations/queries-on-unindexed-columns)
- [Repeated query](/optimize/recommendations/repeated-query)
- [Overfetching](/optimize/recommendations/select-returning)
- [Using `@db.Money`](/optimize/recommendations/avoid-db-money)

:::info
Use [Prisma AI](/optimize/prisma-ai) to ask follow-up questions about a recommendation.
Expand Down
28 changes: 28 additions & 0 deletions content/700-optimize/400-recommendations/600-avoid-db-money.mdx
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).

Loading