Flask 应用程序工厂:我们如何告诉应用程序使用 PostgresqlExtDatabase?

Flask application factory: how do we tell the app to use PostgresqlExtDatabase?

In the peewee documentation表示:

In order to start using the features described below, you will need to use the extension PostgresqlExtDatabase class instead of PostgresqlDatabase.

这是我的应用程序初始化代码:

from playhouse.flask_utils import FlaskDB  

db_wrapper = FlaskDB()

def create_app(env):

    app = Flask(__name__)

    # load config depending on the environment
    app.config.from_yaml(os.path.join(app.root_path, 'config.yml'), env)

    # init extensions
    db_wrapper.init_app(app)

config.yml里面我们有:

COMMON: &common
  DEBUG: False
  TESTING: False

DEVELOPMENT: &development
  <<: *common
  DEBUG: True
  DATABASE: 'postgresql://user:pass@localhost:5432/app_db_name'

如何让 flask 应用程序 使用 PostgresqlExtDatabase

将您的数据库 URL 架构更改为 postgresext,或者 postgresext+pool 如果您想使用连接池。
示例:

DATABASE: 'postgresext://user:pass@localhost:5432/app_db_name'
DATABASE: 'postgresext+pool://user:pass@localhost:5432/app_db_name'

参考(以及支持的方案列表):http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#db-url