Skip to content

Commit ea973ca

Browse files
authored
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
1 parent 1bedda0 commit ea973ca

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

backend/plugin/code_generator/api/v1/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@router.get('/tables', summary='获取数据库表')
2020
async def get_all_tables(
2121
table_schema: Annotated[str, Query(description='数据库名')] = 'fba',
22-
) -> ResponseSchemaModel[list[dict[str, str]]]:
22+
) -> ResponseSchemaModel[list[dict[str, str | None]]]:
2323
data = await gen_service.get_tables(table_schema=table_schema)
2424
return response_base.success(data=data)
2525

backend/plugin/code_generator/crud/crud_code.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ async def get_all_tables(db: AsyncSession, table_schema: str) -> Sequence[RowMap
2727
WHERE table_name NOT LIKE 'sys_gen_%'
2828
AND table_schema = :table_schema;
2929
"""
30+
stmt = text(sql).bindparams(table_schema=table_schema)
3031
else:
3132
sql = """
3233
SELECT c.relname AS table_name, obj_description(c.oid) AS table_comment
@@ -36,7 +37,7 @@ async def get_all_tables(db: AsyncSession, table_schema: str) -> Sequence[RowMap
3637
AND n.nspname = 'public' -- schema 通常是 'public'
3738
AND c.relname NOT LIKE 'sys_gen_%';
3839
"""
39-
stmt = text(sql).bindparams(table_schema=table_schema)
40+
stmt = text(sql)
4041
result = await db.execute(stmt)
4142
return result.mappings().all()
4243

@@ -63,6 +64,7 @@ async def get_table(db: AsyncSession, table_name: str) -> Row[tuple]:
6364
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
6465
WHERE c.relkind = 'r'
6566
AND n.nspname = 'public' -- schema 通常是 'public'
67+
AND c.relname = :table_name
6668
AND c.relname NOT LIKE 'sys_gen_%';
6769
"""
6870
stmt = text(sql).bindparams(table_name=table_name)

0 commit comments

Comments
 (0)