FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlmodel/tests/test_query.py at main · codeaucafe/sqlmodel · GitHub
codeaucafe
sqlmodel
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlmodel
/
tests
/
test_query.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (19 loc) · 732 Bytes
Breadcrumbs
sqlmodel
/
tests
/
test_query.py
Copy path
File metadata and controls
26 lines (19 loc) · 732 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
24
25
26
from
typing
import
Optional
from
sqlmodel
import
Field
,
Session
,
SQLModel
,
create_engine
def
test_query
(
clear_sqlmodel
):
class
Hero
(
SQLModel
,
table
=
True
):
id
:
Optional
[
int
]
=
Field
(
default
=
None
,
primary_key
=
True
)
name
:
str
secret_name
:
str
age
:
Optional
[
int
]
=
None
hero_1
=
Hero
(
name
=
"Deadpond"
,
secret_name
=
"Dive Wilson"
)
engine
=
create_engine
(
"sqlite://"
)
SQLModel
.
metadata
.
create_all
(
engine
)
with
Session
(
engine
)
as
session
:
session
.
add
(
hero_1
)
session
.
commit
()
session
.
refresh
(
hero_1
)
with
Session
(
engine
)
as
session
:
query_hero
=
session
.
query
(
Hero
).
first
()
assert
query_hero
assert
query_hero
.
name
==
hero_1
.
name
Back
|
FazBrowse Home
|
New Git URL