From 0bed478dcb0571859214bd65e169608a4b77ae0c Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 1 Oct 2024 19:15:24 +0300 Subject: [PATCH] Add save and update images --- .../Components/Element/DateSchemaComponent.vue | 5 ----- .../Element/ImageSchemaComponent.vue | 9 +++++++-- .../Components/Group/ListSchemaComponent.vue | 1 - .../api/routers/project/tables/item.py | 18 +++++++++++++++--- .../api/routers/project/tables/list.py | 1 - 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/client/src/views/Project/Tables/Components/Element/DateSchemaComponent.vue b/client/src/views/Project/Tables/Components/Element/DateSchemaComponent.vue index d09c3ce..2d5309d 100644 --- a/client/src/views/Project/Tables/Components/Element/DateSchemaComponent.vue +++ b/client/src/views/Project/Tables/Components/Element/DateSchemaComponent.vue @@ -15,11 +15,6 @@ export default defineComponent({ required: true } }, - data() { - return { - on: false - } - }, watch: { model(newVal) { this.doWrite(newVal) diff --git a/client/src/views/Project/Tables/Components/Element/ImageSchemaComponent.vue b/client/src/views/Project/Tables/Components/Element/ImageSchemaComponent.vue index 3fa6c52..d92d793 100644 --- a/client/src/views/Project/Tables/Components/Element/ImageSchemaComponent.vue +++ b/client/src/views/Project/Tables/Components/Element/ImageSchemaComponent.vue @@ -24,7 +24,7 @@ export default defineComponent({ reader.readAsDataURL(file) reader.onload = () => { const bytes = reader?.result?.split(',')[1] - this.doWrite(bytes) + this.doWrite({type: 'bytes', value: bytes}) } } } @@ -38,7 +38,12 @@ export default defineComponent({ @update:model-value="doWriteFile" /> + diff --git a/client/src/views/Project/Tables/Components/Group/ListSchemaComponent.vue b/client/src/views/Project/Tables/Components/Group/ListSchemaComponent.vue index 866cc03..2a9a821 100644 --- a/client/src/views/Project/Tables/Components/Group/ListSchemaComponent.vue +++ b/client/src/views/Project/Tables/Components/Group/ListSchemaComponent.vue @@ -143,7 +143,6 @@ export default defineComponent({ const columnDb = this.componentSchema.columns.find(el => { return el.title == i.title }) - console.log(columnDb, i) if (columnDb?.columnDbms) { return columnDb?.columnDbms } diff --git a/server/promptadmin_server/api/routers/project/tables/item.py b/server/promptadmin_server/api/routers/project/tables/item.py index c62a029..fa8c890 100644 --- a/server/promptadmin_server/api/routers/project/tables/item.py +++ b/server/promptadmin_server/api/routers/project/tables/item.py @@ -1,3 +1,4 @@ +import re from typing import Any from fastapi import APIRouter @@ -15,9 +16,14 @@ class LoadItemRequest(BaseModel): id: int +class TypeColumn(BaseModel): + type: str + value: Any + + class Column(BaseModel): key: str - value: Any + value: TypeColumn | Any class SaveItemRequest(LoadItemRequest): @@ -47,6 +53,10 @@ async def update(save_item_request: SaveItemRequest): if i > 0: sql_statement += ', ' sql_statement += f'{save_item_request.columns[i].key} = ${i + 1}' + if isinstance(save_item_request.columns[i].value, TypeColumn): + if save_item_request.columns[i].value.type == 'bytes': + values.append(str(save_item_request.columns[i].value.value).encode()) + continue values.append(save_item_request.columns[i].value) sql = f""" @@ -74,6 +84,10 @@ async def create(save_item_request: SaveItemRequest): sql_statement_values += ', ' sql_statement_columns += f'{save_item_request.columns[i].key}' sql_statement_values += f'${i + 1}' + if isinstance(save_item_request.columns[i].value, TypeColumn): + if save_item_request.columns[i].value.type == 'bytes': + values.append(str(save_item_request.columns[i].value.value).encode()) + continue values.append(save_item_request.columns[i].value) sql = f""" @@ -81,8 +95,6 @@ async def create(save_item_request: SaveItemRequest): values ({sql_statement_values}) returning id """ - print(sql) - print(values) return await connection.fetchrow(sql, *values) diff --git a/server/promptadmin_server/api/routers/project/tables/list.py b/server/promptadmin_server/api/routers/project/tables/list.py index 9c2823f..c4249e1 100644 --- a/server/promptadmin_server/api/routers/project/tables/list.py +++ b/server/promptadmin_server/api/routers/project/tables/list.py @@ -97,7 +97,6 @@ async def load(load_request: LoadRequest): f'{limit} ' f'{offset} ' ) - print(statement) return await connection.fetch(statement)