forked from openml/server-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetups.py
More file actions
49 lines (43 loc) · 1.19 KB
/
setups.py
File metadata and controls
49 lines (43 loc) · 1.19 KB
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
from sqlalchemy import Connection, text
from sqlalchemy.engine import Row
def get(id_: int, connection: Connection) -> Row | None:
"""Get the setup by its ID."""
row = connection.execute(
text(
"""
SELECT *
FROM algorithm_setup
WHERE sid = :setup_id
""",
),
parameters={"setup_id": id_},
)
return row.one_or_none()
def get_tags_for(id_: int, connection: Connection) -> list[str]:
"""Get all tags for a specific setup."""
rows = connection.execute(
text(
"""
SELECT tag
FROM setup_tag
WHERE id = :setup_id
""",
),
parameters={"setup_id": id_},
)
return [row.tag for row in rows]
def tag(id_: int, tag_: str, *, user_id: int, connection: Connection) -> None:
"""Insert a new tag for the setup."""
connection.execute(
text(
"""
INSERT INTO setup_tag(`id`, `tag`, `uploader`)
VALUES (:setup_id, :tag, :user_id)
""",
),
parameters={
"setup_id": id_,
"user_id": user_id,
"tag": tag_,
},
)