Skip to content

Commit 7432323

Browse files
committed
Add support for pydantic.EmailStr
1 parent 680111c commit 7432323

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

docs/advanced/column-types.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,21 @@ In addition, the following types are stored as `VARCHAR`:
112112
* ipaddress.IPv6Address
113113
* ipaddress.IPv6Network
114114
* pathlib.Path
115+
* pydantic.EmailStr
115116

116117
### IP Addresses
117118

118119
IP Addresses from the <a href="https://docs.python.org/3/library/ipaddress.html" class="external-link" target="_blank">Python `ipaddress` module</a> are stored as text.
119120

120-
```Python hl_lines="1 11"
121-
{!./docs_src/advanced/column_types/tutorial003.py[ln:1-13]!}
121+
```Python hl_lines="1 12"
122+
{!./docs_src/advanced/column_types/tutorial003.py[ln:1-15]!}
122123
```
123124

124125
### Filesystem Paths
125126

126127
Paths to files and directories using the <a href="https://docs.python.org/3/library/pathlib.html" class="external-link" target="_blank">Python `pathlib` module</a> are stored as text.
127128

128-
```Python hl_lines="5 11"
129+
```Python hl_lines="3 13"
129130
{!./docs_src/advanced/column_types/tutorial003.py[ln:1-15]!}
130131
```
131132

@@ -141,7 +142,7 @@ ensure you call `absolute()` on the path before setting it in your model.
141142
UUIDs from the <a href="https://docs.python.org/3/library/uuid.html" class="external-link" target="_blank">Python `uuid`
142143
module</a> are stored as `UUID` types in supported databases (just PostgreSQL at the moment), otherwise as a `CHAR(32)`.
143144

144-
```Python hl_lines="3 10"
145+
```Python hl_lines="4 11"
145146
{!./docs_src/advanced/column_types/tutorial003.py[ln:1-15]!}
146147
```
147148

docs_src/advanced/column_types/tutorial003.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44
from uuid import UUID, uuid4
55

6+
from pydantic import EmailStr
67
from sqlmodel import Field, SQLModel, create_engine
78

89

@@ -11,6 +12,7 @@ class Avatar(SQLModel, table=True):
1112
source_ip_address: ipaddress.IPv4Address
1213
upload_location: Path
1314
uploaded_at: datetime = Field(default=datetime.now(tz=UTC))
15+
author_email: EmailStr
1416

1517

1618
sqlite_file_name = "database.db"

sqlmodel/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
overload,
2525
)
2626

27-
from pydantic import BaseModel
27+
from pydantic import BaseModel, EmailStr
2828
from pydantic.fields import FieldInfo as PydanticFieldInfo
2929
from sqlalchemy import (
3030
Boolean,
@@ -602,6 +602,8 @@ def get_sqlalchemy_type(field: Any) -> Any:
602602
return AutoString
603603
if issubclass(type_, Path):
604604
return AutoString
605+
if issubclass(type_, EmailStr):
606+
return AutoString
605607
if issubclass(type_, uuid.UUID):
606608
return GUID
607609
raise ValueError(f"{type_} has no matching SQLAlchemy type")

0 commit comments

Comments
 (0)