agronholm / agronholm/sqlacodegen

Improve code generator design

オープン
#199 コメント 13 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Python
スター
2.4k
フォーク
284
平均マージ
2日 1時間
マージ済み PR(30日)
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 を短くまとめたダイジェスト。