You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
793 B
Python

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from os import getenv
db = SQLAlchemy()
def setup_db(app: Flask):
uri = 'postgresql+psycopg2://{user}:{pw}@{host}:{port}/{db}'.format(
user=getenv('DB_USER'),
pw=getenv('DB_PASS'),
host=getenv('DB_HOST', 'localhost'),
port=getenv('DB_PORT', 5432),
db=getenv('DB_NAME')
)
app.config['SQLALCHEMY_DATABASE_URI'] = uri
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
return db
def create_app():
app = Flask(__name__)
setup_db(app)
with app.app_context():
from app.routes import api_bp
from app.cli import cli_bp
app.register_blueprint(api_bp)
app.register_blueprint(cli_bp)
return app