Auto-update: Tue Jul 30 12:54:25 PDT 2024
This commit is contained in:
parent
4c2e1e5825
commit
6e958c5f1f
1 changed files with 10 additions and 8 deletions
|
@ -14,7 +14,7 @@ import reverse_geocoder as rg
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional, Tuple, Union, TypeVar
|
from typing import Any, Dict, List, Optional, Tuple, Union, TypeVar
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from pydantic import BaseModel, Field, create_model, validator
|
from pydantic import BaseModel, Field, create_model, PrivateAttr
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
@ -204,10 +204,14 @@ class APIConfig(BaseModel):
|
||||||
TZ: str
|
TZ: str
|
||||||
KEYS: List[str]
|
KEYS: List[str]
|
||||||
GARBAGE: Dict[str, Any]
|
GARBAGE: Dict[str, Any]
|
||||||
|
_db_pool: DatabasePool = PrivateAttr(default_factory=DatabasePool)
|
||||||
|
|
||||||
def __init__(self, **data):
|
class Config:
|
||||||
super().__init__(**data)
|
arbitrary_types_allowed = True
|
||||||
self._db_pool = DatabasePool()
|
|
||||||
|
@property
|
||||||
|
def db_pool(self):
|
||||||
|
return self._db_pool
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def db_pool(self):
|
def db_pool(self):
|
||||||
|
@ -252,9 +256,7 @@ class APIConfig(BaseModel):
|
||||||
|
|
||||||
config_data['MODULES'] = cls._create_dynamic_config(config_data.get('MODULES', {}), 'DynamicModulesConfig')
|
config_data['MODULES'] = cls._create_dynamic_config(config_data.get('MODULES', {}), 'DynamicModulesConfig')
|
||||||
config_data['EXTENSIONS'] = cls._create_dynamic_config(config_data.get('EXTENSIONS', {}), 'DynamicExtensionsConfig')
|
config_data['EXTENSIONS'] = cls._create_dynamic_config(config_data.get('EXTENSIONS', {}), 'DynamicExtensionsConfig')
|
||||||
instance = cls(**config_data)
|
return cls(**config_data)
|
||||||
instance.db_pool = DatabasePool()
|
|
||||||
return instance
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -739,12 +741,12 @@ class APIConfig(BaseModel):
|
||||||
""", table_name, column_name)
|
""", table_name, column_name)
|
||||||
return exists
|
return exists
|
||||||
|
|
||||||
|
|
||||||
async def close_db_pools(self):
|
async def close_db_pools(self):
|
||||||
if self._db_pool:
|
if self._db_pool:
|
||||||
await self._db_pool.close_all()
|
await self._db_pool.close_all()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Location(BaseModel):
|
class Location(BaseModel):
|
||||||
latitude: float
|
latitude: float
|
||||||
longitude: float
|
longitude: float
|
||||||
|
|
Loading…
Reference in a new issue