From 61fd56bf21baea8deddeca129cd51e861b3aaa8f Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 22 May 2023 08:25:51 -0500 Subject: [PATCH] configure the server --- learn_sql_model/config.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/learn_sql_model/config.py b/learn_sql_model/config.py index c1b6a41..27aabff 100644 --- a/learn_sql_model/config.py +++ b/learn_sql_model/config.py @@ -1,8 +1,8 @@ from typing import TYPE_CHECKING -from pydantic import BaseSettings +from pydantic import BaseModel, BaseSettings from sqlalchemy import create_engine -from sqlmodel import SQLModel, Session +from sqlmodel import Session from learn_sql_model.standard_config import load @@ -10,6 +10,13 @@ if TYPE_CHECKING: from sqlalchemy import Engine +class ApiServer(BaseModel): + app: str = "learn_sql_model.api.app:app" + port: int = 5000 + reload: bool = True + log_level: str = "info" + + class Database: def __init__(self, config: "Config" = None) -> None: if config is None: @@ -23,24 +30,20 @@ class Database: def engine(self) -> "Engine": return create_engine(self.config.database_url) + @property def session(self) -> "Session": return Session(self.engine) - def create_db_and_tables(self) -> None: - from learn_sql_model.models.hero import Hero - from learn_sql_model.models.pet import Pet - - __all__ = [Hero, Pet] - - SQLModel.metadata.create_all(self.engine) - class Config(BaseSettings): + env: str = "dev" database_url: str = "sqlite:///database.db" - port: int = 5000 + api_server: ApiServer = ApiServer() class Config: - env_prefix = "LEARN_SQL_MODEL_" + extra = "ignore" + env_nested_delimiter = "__" + env_file = ".env", ".env.dev", ".env.qa", ".env.prod" @property def database(self) -> Database: