agronholm / agronholm/sqlacodegen

Add support for multiple databases binding

Đang mở
#294 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
2.4k
Fork
284
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
1

Mô tả

### Things to check first

- [X] I have searched the existing issues and didn't find my feature already requested there

### Feature description

SQLAlchemy let you work with multiple databases.
In this case, apart from settings the connections with `SQLALCHEMY_BINDS` it's necessary to associate each `Model`/`Table` with the usage of the class attribute `__bind_key__` / the parameter `bind_key`, as described in the [documentation](https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/binds/#defining-models-and-tables-with-binds).

It would be nice if this information could be handled by a new `option` - in addition to the ones described in the [readme](https://github.com/agronholm/sqlacodegen/tree/master#generator-specific-options) to automatically set this value.

### Use case

In my experience, the need of "reverse engineering" the data model from the db is when you want to import a "third-part" db.
In my current case, the "main" db is handled "normally" (I have a flask-based webapp, where I've defined the model, and used flask-sqlalchemy to generate the schema of the db), but I need to access this external db to fetch some additional data.
In this case - as is a "staging area" db, the schema is "out of my control". I can at most use `sqlacodegen` to infer the `Table`s in my project.
But - as things are - this also mean that the connection to this db is in addition to the "default one" I already use.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.