Files
RuoYi-Vue3-FastAPI/ruoyi-fastapi-backend/module_generator/templates/python/do.py.jinja2
T
insistence ae852b8501 feat: 新增多数据源功能 (#123)
* feat: 新增多数据源功能

* perf: 优化多worker下数据源打印重复日志的问题

* perf: 优化代码

* perf: 优化代码

* chore: 固定ai插件相关依赖
2026-08-21 15:26:24 +08:00

51 lines
2.0 KiB
Django/Jinja

{% for do_import in doImportList %}
{{ do_import }}
{% endfor %}
{% if table.sub %}
from sqlalchemy.orm import relationship
{% endif %}
{% if dataSourceName == defaultDataSourceName %}
from config.database import Base
{% else %}
from config.database import get_data_source_base
DataSourceBase = get_data_source_base('{{ dataSourceName }}')
{% endif %}
class {{ ClassName }}({% if dataSourceName == defaultDataSourceName %}Base{% else %}DataSourceBase{% endif %}):
"""
{{ functionName }}表
"""
__tablename__ = '{{ tableName }}'
__table_args__ = {'comment': '{{ tableComment }}'}
{% for column in columns %}
{{ column.column_name }} = Column({{ column.column_type | get_sqlalchemy_type(dataSourceName) }}, {% if column.pk %}primary_key=True, {% endif %}{% if column.increment %}autoincrement=True, {% endif %}{% if column.required or column.pk %}nullable=False{% else %}nullable=True{% endif %}, comment='{{ column.column_comment }}')
{% endfor %}
{% if table.sub %}
{{ subclassName }}_list = relationship('{{ subClassName }}', back_populates='{{ businessName }}')
{% endif %}
{% if table.sub %}
class {{ subClassName }}({% if dataSourceName == defaultDataSourceName %}Base{% else %}DataSourceBase{% endif %}):
"""
{{ subTable.function_name }}表
"""
__tablename__ = '{{ subTableName }}'
{% for column in subTable.columns %}
{{ column.column_name }} = Column({{ column.column_type | get_sqlalchemy_type(dataSourceName) }}, {% if column.column_name == subTableFkName %}ForeignKey('{{ tableName }}.{{ subTableFkName }}'), {% endif %}{% if column.pk %}primary_key=True, {% endif %}{% if column.increment %}autoincrement=True, {% endif %}{% if column.required or column.pk %}nullable=False{% else %}nullable=True{% endif %}, comment='{{ column.column_comment }}')
{% endfor %}
{% if table.sub %}
{{ businessName }} = relationship('{{ ClassName }}', back_populates='{{ subclassName }}_list')
{% endif %}
{% endif %}