|
2 | 2 |
|
3 | 3 | import datetime |
4 | 4 | from collections import defaultdict |
| 5 | +from typing import TYPE_CHECKING |
5 | 6 |
|
6 | 7 | from sqlalchemy import text |
7 | | -from sqlalchemy.engine import Row |
8 | 8 | from sqlalchemy.exc import IntegrityError |
9 | | -from sqlalchemy.ext.asyncio import AsyncConnection |
10 | 9 |
|
11 | 10 | from database.exceptions import ( |
12 | 11 | _DUPLICATE_ENTRY, |
|
16 | 15 | ) |
17 | 16 | from schemas.datasets.openml import Feature |
18 | 17 |
|
| 18 | +if TYPE_CHECKING: |
| 19 | + from sqlalchemy.engine import Row |
| 20 | + from sqlalchemy.ext.asyncio import AsyncConnection |
| 21 | + |
19 | 22 |
|
20 | 23 | async def get(id_: int, connection: AsyncConnection) -> Row | None: |
21 | 24 | row = await connection.execute( |
@@ -45,6 +48,33 @@ async def get_file(*, file_id: int, connection: AsyncConnection) -> Row | None: |
45 | 48 | return row.one_or_none() |
46 | 49 |
|
47 | 50 |
|
| 51 | +async def get_tag(dataset_id: int, tag: str, connection: AsyncConnection) -> Row | None: |
| 52 | + return ( |
| 53 | + await connection.execute( |
| 54 | + text( |
| 55 | + """ |
| 56 | + SELECT * |
| 57 | + FROM dataset_tag |
| 58 | + WHERE id = :dataset_id AND tag = :tag |
| 59 | + """, |
| 60 | + ), |
| 61 | + parameters={"dataset_id": dataset_id, "tag": tag}, |
| 62 | + ) |
| 63 | + ).first() |
| 64 | + |
| 65 | + |
| 66 | +async def delete_tag(dataset_id: int, tag: str, connection: AsyncConnection) -> None: |
| 67 | + await connection.execute( |
| 68 | + text( |
| 69 | + """ |
| 70 | + DELETE FROM dataset_tag |
| 71 | + WHERE id = :dataset_id AND tag = :tag |
| 72 | + """, |
| 73 | + ), |
| 74 | + parameters={"dataset_id": dataset_id, "tag": tag}, |
| 75 | + ) |
| 76 | + |
| 77 | + |
48 | 78 | async def get_tags_for(id_: int, connection: AsyncConnection) -> list[str]: |
49 | 79 | row = await connection.execute( |
50 | 80 | text( |
|
0 commit comments