关于python:使用flask-sqlalchemy而没有子类声明基础

using flask-sqlalchemy without the subclassed declarative base

我正在为python wsgi服务器使用flask,为所有数据库访问使用sqlachemy。

我想在应用程序中使用flask sqlachemy扩展,但我不想使用声明性基类(db.model),而是使用sqlachemy.ext.declarative中的基。

这是否破坏了使用扩展的整个目的?

我的用例:

我希望扩展可以帮助我更好地管理会话/引擎,但我希望单独处理所有模型。

实际上,我不介意使用扩展,但我想编写严格的模型。我正在从一个非flask应用程序移植代码,我将在执行过程中把更改推回到那个项目。例如,如果flask-sqlAlchemy允许我在表元数据上作弊,那么当代码被推回时,这将导致问题。我的代码中也有一些部分进行了大量的类型检查(多态标识),我还记得我读到,在使用扩展时不建议对表进行类型检查。


(P)You can have flask-sqlalchemy exposure your own base model instead of it's built-in one.只是EDOCX1子字体0和Override EDOCX1(p)字母名称


(P)I'm actually using sqlachemy in flask without using declarative base and I don't have any problems.You can always do that if you want to,there is no obligation to use object relational mapper,orm is just one part of sqlalchemy.You can always just stay with alchemy sql expression language,defining your tables in model objects,and defining some methods there will use expression language.I have a code like this(model is the object I defined earlier),connect is a decorator which connects to db,it works fine for me.(p)字母名称(P)Flask's documentation concerning alchemy explicitly says that it is completely good to do that:(p)布尔奇1(P)P.S.Oh,and one more thing,they say in the docs that if you want to get started quickly you're better off using extension,but I'm personally not so sure about that,if you're like me and you feel more familiar with the sql want rather the m with orm,it may be much easier for you to get started quickly without extension.(p)


(P)Sqlalchemy themselves actually recommend you use the flask wrapper(db.model)for flask projects.That being said I have used the declarative…uu base model in several of my flask projects where it made more sense.(p)(P)It does defeat the whole purpose of the sqlachemy class from Flask-Sqlalchemy.(p)(P)这里有一些相同的代码:(p)字母名称