flask-sqlalchemy
flask-sqlalchemy copied to clipboard
Customize through `__init__` args
As per the decision made in #357.
Functionality to customize by init args:
- session options, including scope function
- Session class (#130)
db.Querywith query_class, defaults to BaseQuerydb.Model.metadatawith metadata, defaults to Nonedb.Modelbase class (the base class of the declarative meta) with model_class
Would this include options like the isolation_level? Edit: More of a curiosity question, I realized that isolation_level wasn't the fix to my problem.
I want to be somewhat conservative with X_class arguments, as pairing that with X_options can get out of hand quickly. There's got to be some balance where having an X_class class attribute, or a factory method, along with X_options init arg makes sense for most use cases.
Need that native session auto-committer. :)
Implemented in #1087, although I think other earlier changes addressed most of this by adding the arguments. All setup methods are now considered internal.
session_optionscustomizes the session. Aclass_key can customize the session class. Ascopefunckey can customize the scope function for the scoped session.engine_optionssets default options for all engines.metadatasets the metadata for the default bind. When creating other metadata for other binds, the default metadata'snaming_conventionis copied.query_classcustomizes the query class used bydb.Query,db.Model.query,db.relationship(lazy="dynamic"), anddb.sesison.query`. However, the query interface is legacy in SQLAlchemy 2.0.model_classcan be either a simple base class (sublcassingflask_sqlalchemy.model.Model), or a fully createddeclarative_base(usingDefaultMetaorBindMetaMixinat least).
Between those, that seems to cover customizing all the objects managed by the extension. It otherwise shouldn't get in the way of the capabilities of SQLAlchemy.