Skip to content

Commit 41495e3

Browse files
authored
📝 Update docs for Decimal, use proper types (#719)
1 parent 50b0198 commit 41495e3

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

docs/advanced/decimal.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,13 @@ In most cases this would probably not be a problem, for example measuring views
1919

2020
## Decimal Types
2121

22-
Pydantic has special support for `Decimal` types using the <a href="https://pydantic-docs.helpmanual.io/usage/types/#arguments-to-condecimal" class="external-link" target="_blank">`condecimal()` special function</a>.
22+
Pydantic has special support for <a href="https://docs.pydantic.dev/latest/api/standard_library_types/#decimaldecimal" class="external-link" target="_blank">`Decimal` types</a>.
2323

24-
/// tip
25-
26-
Pydantic 1.9, that will be released soon, has improved support for `Decimal` types, without needing to use the `condecimal()` function.
27-
28-
But meanwhile, you can already use this feature with `condecimal()` in **SQLModel** it as it's explained here.
29-
30-
///
31-
32-
When you use `condecimal()` you can specify the number of digits and decimal places to support. They will be validated by Pydantic (for example when using FastAPI) and the same information will also be used for the database columns.
24+
When you use `Decimal` you can specify the number of digits and decimal places to support in the `Field()` function. They will be validated by Pydantic (for example when using FastAPI) and the same information will also be used for the database columns.
3325

3426
/// info
3527

36-
For the database, **SQLModel** will use <a href="https://docs.sqlalchemy.org/en/14/core/type_basics.html#sqlalchemy.types.DECIMAL" class="external-link" target="_blank">SQLAlchemy's `DECIMAL` type</a>.
28+
For the database, **SQLModel** will use <a href="https://docs.sqlalchemy.org/en/20/core/type_basics.html#sqlalchemy.types.DECIMAL" class="external-link" target="_blank">SQLAlchemy's `DECIMAL` type</a>.
3729

3830
///
3931

docs_src/advanced/decimal/tutorial001.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
from decimal import Decimal
12
from typing import Optional
23

3-
from pydantic import condecimal
44
from sqlmodel import Field, Session, SQLModel, create_engine, select
55

66

@@ -9,7 +9,7 @@ class Hero(SQLModel, table=True):
99
name: str = Field(index=True)
1010
secret_name: str
1111
age: Optional[int] = Field(default=None, index=True)
12-
money: condecimal(max_digits=5, decimal_places=3) = Field(default=0)
12+
money: Decimal = Field(default=0, max_digits=5, decimal_places=3)
1313

1414

1515
sqlite_file_name = "database.db"

docs_src/advanced/decimal/tutorial001_py310.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from pydantic import condecimal
1+
from decimal import Decimal
2+
23
from sqlmodel import Field, Session, SQLModel, create_engine, select
34

45

@@ -7,7 +8,7 @@ class Hero(SQLModel, table=True):
78
name: str = Field(index=True)
89
secret_name: str
910
age: int | None = Field(default=None, index=True)
10-
money: condecimal(max_digits=5, decimal_places=3) = Field(default=0)
11+
money: Decimal = Field(default=0, max_digits=5, decimal_places=3)
1112

1213

1314
sqlite_file_name = "database.db"

0 commit comments

Comments
 (0)