25
25
overload ,
26
26
)
27
27
28
- from pydantic import BaseModel
28
+ from pydantic import BaseModel , EmailStr
29
29
from pydantic .fields import FieldInfo as PydanticFieldInfo
30
30
from sqlalchemy import (
31
31
Boolean ,
@@ -574,7 +574,18 @@ def get_sqlalchemy_type(field: Any) -> Any:
574
574
# Check enums first as an enum can also be a str, needed by Pydantic/FastAPI
575
575
if issubclass (type_ , Enum ):
576
576
return sa_Enum (type_ )
577
- if issubclass (type_ , str ):
577
+ if issubclass (
578
+ type_ ,
579
+ (
580
+ str ,
581
+ ipaddress .IPv4Address ,
582
+ ipaddress .IPv4Network ,
583
+ ipaddress .IPv6Address ,
584
+ ipaddress .IPv6Network ,
585
+ Path ,
586
+ EmailStr ,
587
+ ),
588
+ ):
578
589
max_length = getattr (metadata , "max_length" , None )
579
590
if max_length :
580
591
return AutoString (length = max_length )
@@ -600,16 +611,6 @@ def get_sqlalchemy_type(field: Any) -> Any:
600
611
precision = getattr (metadata , "max_digits" , None ),
601
612
scale = getattr (metadata , "decimal_places" , None ),
602
613
)
603
- if issubclass (type_ , ipaddress .IPv4Address ):
604
- return AutoString
605
- if issubclass (type_ , ipaddress .IPv4Network ):
606
- return AutoString
607
- if issubclass (type_ , ipaddress .IPv6Address ):
608
- return AutoString
609
- if issubclass (type_ , ipaddress .IPv6Network ):
610
- return AutoString
611
- if issubclass (type_ , Path ):
612
- return AutoString
613
614
if issubclass (type_ , uuid .UUID ):
614
615
return GUID
615
616
raise ValueError (f"{ type_ } has no matching SQLAlchemy type" )
0 commit comments