Improvements upon api and database api
This commit is contained in:
parent
34ae028698
commit
dc6ba8f462
4 changed files with 95 additions and 7 deletions
34
dba.py
34
dba.py
|
|
@ -450,11 +450,16 @@ def create_asset(conn: DBConnector, name: str, description: str, fid: str):
|
|||
return False, None
|
||||
|
||||
|
||||
def update_asset(conn: DBConnector, asset_id: int, asset_description: str):
|
||||
def update_asset(
|
||||
conn: DBConnector, asset_id: int, asset_description: str, asset_tags: list[str]
|
||||
):
|
||||
try:
|
||||
conn.updateDataInTable(
|
||||
ASSETS_TABLE_NAME,
|
||||
[ColumnUpdate("description", asset_description)],
|
||||
[
|
||||
ColumnUpdate("description", asset_description),
|
||||
ColumnUpdate("tags", ",".join(asset_tags)),
|
||||
],
|
||||
[ColumnCondition("id", "eq", asset_id)],
|
||||
)
|
||||
return True, None
|
||||
|
|
@ -527,3 +532,28 @@ def get_asset_by_id(conn: DBConnector, asset_id: int):
|
|||
except Exception as e:
|
||||
logger.exception(e)
|
||||
return None
|
||||
|
||||
|
||||
def get_assets(conn: DBConnector) -> list[Asset]:
|
||||
try:
|
||||
assets = conn.selectFromTable(ASSETS_TABLE_NAME, ["*"])
|
||||
if not assets:
|
||||
return []
|
||||
return [Asset.parse_obj(asset) for asset in assets]
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
return []
|
||||
|
||||
|
||||
def get_assets_tags(conn: DBConnector) -> list[str]:
|
||||
try:
|
||||
with conn.connection as connection:
|
||||
with connection.cursor() as cursor:
|
||||
tags = cursor.execute(
|
||||
f"SELECT DISTINCT unnest(string_to_array(tags, ',')) FROM {ASSETS_TABLE_NAME}"
|
||||
).fetchall()
|
||||
|
||||
return [tag["unnest"] for tag in tags]
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
return []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue