FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlmodel/tests/test_annotated_uuid.py at main · ByteDecoder/sqlmodel · GitHub
ByteDecoder
sqlmodel
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlmodel
/
tests
/
test_annotated_uuid.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (18 loc) · 715 Bytes
Breadcrumbs
sqlmodel
/
tests
/
test_annotated_uuid.py
Copy path
File metadata and controls
23 lines (18 loc) · 715 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import
uuid
from
typing
import
Optional
from
sqlmodel
import
Field
,
Session
,
SQLModel
,
create_engine
,
select
def
test_annotated_optional_types
(
clear_sqlmodel
)
->
None
:
from
pydantic
import
UUID4
class
Hero
(
SQLModel
,
table
=
True
):
# Pydantic UUID4 is: Annotated[UUID, UuidVersion(4)]
id
:
Optional
[
UUID4
]
=
Field
(
default_factory
=
uuid
.
uuid4
,
primary_key
=
True
)
engine
=
create_engine
(
"sqlite:///:memory:"
)
SQLModel
.
metadata
.
create_all
(
engine
)
with
Session
(
engine
)
as
db
:
hero
=
Hero
()
db
.
add
(
hero
)
db
.
commit
()
statement
=
select
(
Hero
)
result
=
db
.
exec
(
statement
).
all
()
assert
len
(
result
)
==
1
assert
isinstance
(
hero
.
id
,
uuid
.
UUID
)
Back
|
FazBrowse Home
|
New Git URL