From b520a4ee83d1e4cd6e435f1091417e0522837e4b Mon Sep 17 00:00:00 2001 From: junjun Date: Tue, 10 Jun 2025 12:07:44 +0800 Subject: [PATCH] feat: template --- backend/apps/template/template.py | 2 +- backend/template.yaml | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/apps/template/template.py b/backend/apps/template/template.py index 7dd5b1cc..e342a84f 100644 --- a/backend/apps/template/template.py +++ b/backend/apps/template/template.py @@ -4,7 +4,7 @@ base_template = None def load(): - with open('./template.yaml', 'r') as f: + with open('./template.yaml', 'r', encoding='utf-8') as f: global base_template base_template = yaml.load(f, Loader=yaml.SafeLoader) diff --git a/backend/template.yaml b/backend/template.yaml index 5256e6f2..6cb4a885 100644 --- a/backend/template.yaml +++ b/backend/template.yaml @@ -7,8 +7,12 @@ template: - 生成的SQL必须符合{engine}的规范。 - 根据表结构生成SQL语句。 - SQL查询中不能使用星号(*),必须明确指定字段名. - - SQL查询的字段名和别名必须为英文。 + - SQL查询的字段名不要自动翻译,别名必须为英文。 - 计算占比,百分比类型字段,保留两位小数,以%结尾。 + - 生成SQL时,必须避免关键字冲突: + - 如{engine}是 PostgreSQL、Oracle,则在schema、表名、字段名、别名外层加双引号; + - 如{engine}是 MySQL,则在表名、字段名、别名外层加反引号; + - 如{engine}是 Microsoft SQL Server,则在schema、表名、字段名、别名外层加方括号。 - 生成的SQL使用JSON格式返回: {{"success":true,"sql":"生成的SQL语句"}} - 问题与生成SQL无关时,直接回答: