mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
- 将分页服务中方法名由get_page_obj统一替换为paginate - 注意相关controller均调整调用方式,保证统一接口调用 - 代码生成模块数据库模型统一替换为GenTableModel和GenTableColumnModel - 更改数据库类型及分页相关配置为settings.DATABASE_TYPE统一管理 - 重构代码生成模块查询参数,新增GenTableQueryParam和GenTableColumnQueryParam类支持更灵活查询 - 数据模型中Pydantic Schema类型统一调整为Schema后缀 - 优化异常处理,增加请求参数验证错误的友好提示映射 - 调整中间件及依赖以支持更严格的类型检查及更健壮的用户权限认证逻辑 - 微调日志打印格式,改进请求日志信息输出风格
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
import re
|
|
|
|
from app.common.constant import GenConstants
|
|
|
|
|
|
def snake_to_pascal_case(value):
|
|
"""将下划线命名 (snake_case) 转换大驼峰"""
|
|
return ''.join(word.capitalize() for word in value.split('_'))
|
|
|
|
|
|
def snake_to_camel(snake_str):
|
|
"""将下划线命名 (snake_case) 转换小驼峰"""
|
|
components = snake_str.split('_')
|
|
return components[0] + ''.join(x.title() for x in components[1:])
|
|
|
|
def snake_2_colon(snake_str: str) -> str:
|
|
"""将下划线命名 (snake_case) 转换冒号分隔"""
|
|
return snake_str.replace('_', ':')
|
|
|
|
def is_base_column(column_name: str) -> bool:
|
|
"""判断是否是基础字段"""
|
|
return column_name in GenConstants.BASE_ENTITY
|
|
|
|
def get_sqlalchemy_type(mysql_field_type: str) -> str:
|
|
"""mysql_field_type 转sqlalchemy类型"""
|
|
if mysql_field_type:
|
|
base_type = mysql_field_type.split("(", 1)[0]
|
|
if base_type.upper() in GenConstants.MYSQL_TO_SQLALCHEMY.keys():
|
|
sqlalchemy_type = GenConstants.MYSQL_TO_SQLALCHEMY[base_type.upper()]
|
|
if sqlalchemy_type == 'String' :
|
|
match = re.search(r'\((.*?)\)', mysql_field_type)
|
|
if match:
|
|
return f'{sqlalchemy_type}({match.group(1)})'
|
|
else:
|
|
return f'{sqlalchemy_type}'
|
|
else:
|
|
return f'{sqlalchemy_type}'
|
|
return "String"
|
|
|
|
def get_column_options(col) -> str:
|
|
options = []
|
|
# 主键
|
|
if col['isPk'] == "1":
|
|
options.append("primary_key=True")
|
|
# 是否允许为空
|
|
if col['isRequired'] == "1":
|
|
options.append("nullable=False")
|
|
# 自增
|
|
if col["isIncrement"] == "1":
|
|
options.append("autoincrement=True")
|
|
# 注释
|
|
options.append(f"comment='{col['columnComment']}'")
|
|
return ", ".join(options)
|