Skip to content

Commit dc96203

Browse files
committed
Add support for pydantic date types
1 parent 7256820 commit dc96203

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

sqlmodel/main.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@
2525
overload,
2626
)
2727

28-
from pydantic import BaseModel, EmailStr
28+
from pydantic import (
29+
AwareDatetime,
30+
BaseModel,
31+
EmailStr,
32+
FutureDate,
33+
FutureDatetime,
34+
NaiveDatetime,
35+
PastDate,
36+
PastDatetime,
37+
)
2938
from pydantic.fields import FieldInfo as PydanticFieldInfo
3039
from sqlalchemy import (
3140
Boolean,
@@ -680,14 +689,18 @@ def get_sqlalchemy_type(field: Any) -> Any:
680689
return Boolean
681690
if issubclass(type_, int):
682691
return Integer
683-
if issubclass(type_, datetime):
692+
if issubclass(type_, (datetime, FutureDatetime, PastDatetime)):
684693
return DateTime
685-
if issubclass(type_, date):
694+
if issubclass(type_, (date, FutureDate, PastDate)):
686695
return Date
687696
if issubclass(type_, timedelta):
688697
return Interval
689698
if issubclass(type_, time):
690699
return Time
700+
if issubclass(type_, AwareDatetime):
701+
return DateTime(timezone=True)
702+
if issubclass(type_, NaiveDatetime):
703+
return DateTime(timezone=False)
691704
if issubclass(type_, bytes):
692705
return LargeBinary
693706
if issubclass(type_, Decimal):

0 commit comments

Comments
 (0)