#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ # @Version : Python 3.11.4 # @Software : Sublime Text 4 # @Author : StudentCWZ # @Email : StudentCWZ@outlook.com # @Date : 2023/10/28 22:01 # @File : init_sqlalchemy.py # @Description : """ from flask import Flask from flask_sqlalchemy import SQLAlchemy from application.utils import DatabaseUri db = SQLAlchemy() def init_database(app: Flask) -> None: """ Initialize the database extension :param app: flask.Flask application instance :return: None """ cfg = app.config.Database uri = DatabaseUri( db_type=cfg.Type, username=cfg.Username, password=cfg.Password, host=cfg.Host, port=cfg.Port, db=cfg.DB, driver=cfg.Driver, ) app.config.setdefault('SQLALCHEMY_DATABASE_URI', uri.create()) db.init_app(app)