24 lines
584 B
Python
24 lines
584 B
Python
|
from typing import Tuple
|
||
|
from fastapi import FastAPI
|
||
|
from pydantic import MySQLDsn
|
||
|
from config import configs
|
||
|
from db import MySQLConfig, Database
|
||
|
|
||
|
def get_app() -> FastAPI:
|
||
|
app = FastAPI()
|
||
|
return app
|
||
|
|
||
|
def get_config(url: MySQLDsn) -> MySQLConfig:
|
||
|
db_config = MySQLConfig(url=url)
|
||
|
return db_config
|
||
|
|
||
|
def get_database(uri: MySQLConfig) -> Database:
|
||
|
database = Database(uri=uri)
|
||
|
return database
|
||
|
|
||
|
def init_app() -> Tuple[FastAPI, Database]:
|
||
|
app = get_app()
|
||
|
uri = get_config(url=configs.DB_URI)
|
||
|
database = get_database(uri=uri)
|
||
|
return app, database
|