Add support for Decimal fields from Pydantic and SQLAlchemy (#103)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
robcxyz
2021-12-13 04:30:20 -07:00
committed by GitHub
parent 1c276ef88f
commit 580f372059
10 changed files with 262 additions and 7 deletions

View File

@ -399,7 +399,10 @@ def get_sqlachemy_type(field: ModelField) -> Any:
if issubclass(field.type_, bytes):
return LargeBinary
if issubclass(field.type_, Decimal):
return Numeric
return Numeric(
precision=getattr(field.type_, "max_digits", None),
scale=getattr(field.type_, "decimal_places", None),
)
if issubclass(field.type_, ipaddress.IPv4Address):
return AutoString
if issubclass(field.type_, ipaddress.IPv4Network):