From ea973cac9083dabf743cafac36a3f27d47a4cc72 Mon Sep 17 00:00:00 2001 From: B <16448666+byte-voyager@users.noreply.github.com> Date: Thu, 11 Sep 2025 17:53:15 +0800 Subject: [PATCH] Fix pgsql syntax error in code generation (#808) * Update title field in OperaLogSchemaBase to allow None values * Update response type in get_all_tables to allow None values in dictionary * Fix code generation error in PostgreSQL * Update opera_log.py --- backend/plugin/code_generator/api/v1/code.py | 2 +- backend/plugin/code_generator/crud/crud_code.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/plugin/code_generator/api/v1/code.py b/backend/plugin/code_generator/api/v1/code.py index 69c8e026..a58c0b6b 100644 --- a/backend/plugin/code_generator/api/v1/code.py +++ b/backend/plugin/code_generator/api/v1/code.py @@ -19,7 +19,7 @@ router = APIRouter() @router.get('/tables', summary='获取数据库表') async def get_all_tables( table_schema: Annotated[str, Query(description='数据库名')] = 'fba', -) -> ResponseSchemaModel[list[dict[str, str]]]: +) -> ResponseSchemaModel[list[dict[str, str | None]]]: data = await gen_service.get_tables(table_schema=table_schema) return response_base.success(data=data) diff --git a/backend/plugin/code_generator/crud/crud_code.py b/backend/plugin/code_generator/crud/crud_code.py index a756cfc9..6b695240 100644 --- a/backend/plugin/code_generator/crud/crud_code.py +++ b/backend/plugin/code_generator/crud/crud_code.py @@ -27,6 +27,7 @@ class CRUDGen: WHERE table_name NOT LIKE 'sys_gen_%' AND table_schema = :table_schema; """ + stmt = text(sql).bindparams(table_schema=table_schema) else: sql = """ SELECT c.relname AS table_name, obj_description(c.oid) AS table_comment @@ -36,7 +37,7 @@ class CRUDGen: AND n.nspname = 'public' -- schema 通常是 'public' AND c.relname NOT LIKE 'sys_gen_%'; """ - stmt = text(sql).bindparams(table_schema=table_schema) + stmt = text(sql) result = await db.execute(stmt) return result.mappings().all() @@ -63,6 +64,7 @@ class CRUDGen: LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind = 'r' AND n.nspname = 'public' -- schema 通常是 'public' + AND c.relname = :table_name AND c.relname NOT LIKE 'sys_gen_%'; """ stmt = text(sql).bindparams(table_name=table_name)