FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlmodel/scripts/generate_select.py at main · rbrady/sqlmodel · GitHub
rbrady
sqlmodel
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlmodel
/
scripts
/
generate_select.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (40 loc) · 1.56 KB
Breadcrumbs
sqlmodel
/
scripts
/
generate_select.py
Copy path
File metadata and controls
55 lines (40 loc) · 1.56 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from
itertools
import
product
from
pathlib
import
Path
from
typing
import
List
,
Tuple
import
black
from
jinja2
import
Template
from
pydantic
import
BaseModel
template_path
=
Path
(
__file__
).
parent
.
parent
/
"sqlmodel/sql/expression.py.jinja2"
destiny_path
=
Path
(
__file__
).
parent
.
parent
/
"sqlmodel/sql/expression.py"
number_of_types
=
4
class
Arg
(
BaseModel
):
name
:
str
annotation
:
str
arg_groups
:
List
[
Arg
]
=
[]
signatures
:
List
[
Tuple
[
List
[
Arg
],
List
[
str
]]]
=
[]
for
total_args
in
range
(
2
,
number_of_types
+
1
):
arg_types_tuples
=
product
([
"scalar"
,
"model"
],
repeat
=
total_args
)
for
arg_type_tuple
in
arg_types_tuples
:
args
:
List
[
Arg
]
=
[]
return_types
:
List
[
str
]
=
[]
for
i
,
arg_type
in
enumerate
(
arg_type_tuple
):
if
arg_type
==
"scalar"
:
t_var
=
f"_TScalar_
{
i
}
"
arg
=
Arg
(
name
=
f"entity_
{
i
}
"
,
annotation
=
t_var
)
ret_type
=
t_var
else
:
t_type
=
f"_TModel_
{
i
}
"
t_var
=
f"Type[
{
t_type
}
]"
arg
=
Arg
(
name
=
f"entity_
{
i
}
"
,
annotation
=
t_var
)
ret_type
=
t_type
args
.
append
(
arg
)
return_types
.
append
(
ret_type
)
signatures
.
append
((
args
,
return_types
))
template
:
Template
=
Template
(
template_path
.
read_text
())
result
=
template
.
render
(
number_of_types
=
number_of_types
,
signatures
=
signatures
)
result
=
(
"# WARNING: do not modify this code, it is generated by "
"expression.py.jinja2
\n
\n
"
+
result
)
result
=
black
.
format_str
(
result
,
mode
=
black
.
Mode
())
destiny_path
.
write_text
(
result
)
Back
|
FazBrowse Home
|
New Git URL