agronholm / agronholm/sqlacodegen

Improve code generator design

未关闭
#199 13 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
Python
星标
2.4k
派生
284
平均合并
2 天 1 小时
30 天内合并 PR
1

描述

I'm pretty unhappy with the current design of the code generator system. There's duplication of logic between the model generation and rendering parts. The rendering system is not nearly flexible enough. There's a lot of awkwardness that I see everywhere.

Here's how I would like the code generation process to work:

1. Generator receives a `MetaData` object
2. Generator iterates through the tables, generating models and module variables
3. Generator assigns names to tables, classes and class attributes, potentially aliasing existing imports
4. Generator renders imports, module variables, tables and classes

Import collection must happen at or after phase 2, so that they could potentially be aliased to avoid conflicts with module variables and attribute names. This is preferable to renaming attributes to avoid clashes. In order for this to work, we need to factor out actual Columns and Tables out of the abstract model that is passed to the renderer. Any callables referred from the model must be abstracted so that they could be dynamically renamed if their relevant imports end up being aliased to avoid a name clash.

@leonarduschen do you see any obvious potential problems with this plan?

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。