feat(root):add mysql
This commit is contained in:
+15
@@ -81,3 +81,18 @@ database:
|
|||||||
version: 4
|
version: 4
|
||||||
password: 'sample'
|
password: 'sample'
|
||||||
user: 'local'
|
user: 'local'
|
||||||
|
|
||||||
|
# MySQL (read-only) - جدا از database تا مونگو و بقیه بدون تغییر بمانند
|
||||||
|
mysql:
|
||||||
|
dev:
|
||||||
|
host: '172.16.1.194'
|
||||||
|
port: 3309
|
||||||
|
user: 'root'
|
||||||
|
password: '2TjwtsnYAs'
|
||||||
|
db: 'doc'
|
||||||
|
production:
|
||||||
|
host: '172.16.1.194'
|
||||||
|
port: 3309
|
||||||
|
user: 'root'
|
||||||
|
password: '2TjwtsnYAs'
|
||||||
|
db: 'doc'
|
||||||
|
|||||||
+38
-4
@@ -1,10 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, List, Union
|
from typing import Optional, List, Union, Dict, Any
|
||||||
|
|
||||||
import pydantic
|
import pydantic
|
||||||
import yaml
|
import yaml
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, validator
|
||||||
|
|
||||||
|
|
||||||
def build_path(path: Union[Path, str], path_is_absolute: bool = False) -> Path:
|
def build_path(path: Union[Path, str], path_is_absolute: bool = False) -> Path:
|
||||||
@@ -73,6 +73,19 @@ class DatabaseModeConfig(BaseModel):
|
|||||||
production: Optional[DatabaseConfig]
|
production: Optional[DatabaseConfig]
|
||||||
|
|
||||||
|
|
||||||
|
class MySQLConfig(BaseModel):
|
||||||
|
host: str
|
||||||
|
port: int
|
||||||
|
user: str
|
||||||
|
password: str
|
||||||
|
db: str
|
||||||
|
|
||||||
|
|
||||||
|
class MySQLModeConfig(BaseModel):
|
||||||
|
dev: Optional[MySQLConfig]
|
||||||
|
production: Optional[MySQLConfig]
|
||||||
|
|
||||||
|
|
||||||
class DependencyConfig(BaseModel):
|
class DependencyConfig(BaseModel):
|
||||||
middleware: Optional[List[str]]
|
middleware: Optional[List[str]]
|
||||||
routes: Optional[List[str]]
|
routes: Optional[List[str]]
|
||||||
@@ -115,12 +128,33 @@ class CoreConfig(pydantic.BaseModel):
|
|||||||
server: Optional[ServerConfig]
|
server: Optional[ServerConfig]
|
||||||
auth: Optional[AuthConfig]
|
auth: Optional[AuthConfig]
|
||||||
dependency: Optional[DependencyConfig]
|
dependency: Optional[DependencyConfig]
|
||||||
database: dict[str, Union[DatabaseConfig, DatabaseModeConfig]]
|
database: Dict[str, Union[DatabaseConfig, DatabaseModeConfig]]
|
||||||
|
mysql: Optional[MySQLModeConfig] = None
|
||||||
static_files: dict[str, str] = dict()
|
static_files: dict[str, str] = dict()
|
||||||
celery: Optional[CeleryTask]
|
celery: Optional[CeleryTask]
|
||||||
|
|
||||||
|
@validator('database', pre=True)
|
||||||
|
def parse_database(cls, v: Any) -> Dict[str, Union[DatabaseConfig, DatabaseModeConfig]]:
|
||||||
|
if not isinstance(v, dict):
|
||||||
|
return v
|
||||||
|
result: Dict[str, Union[DatabaseConfig, DatabaseModeConfig]] = {}
|
||||||
|
for key, val in v.items():
|
||||||
|
if not isinstance(val, dict):
|
||||||
|
result[key] = val
|
||||||
|
continue
|
||||||
|
if 'dev' in val or 'production' in val:
|
||||||
|
dev = val.get('dev')
|
||||||
|
prod = val.get('production')
|
||||||
|
result[key] = DatabaseModeConfig(
|
||||||
|
dev=DatabaseConfig(**(dev or {})) if dev else None,
|
||||||
|
production=DatabaseConfig(**(prod or {})) if prod else None,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
result[key] = DatabaseConfig(**val)
|
||||||
|
return result
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
arbitrary_types_allowed = False
|
arbitrary_types_allowed = True
|
||||||
|
|
||||||
# def load_modules_config(self):
|
# def load_modules_config(self):
|
||||||
# # import dynamic routes in the modules
|
# # import dynamic routes in the modules
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
aiofiles==22.1.0
|
aiofiles==22.1.0
|
||||||
|
aiomysql==0.2.0
|
||||||
aioredis==2.0.1
|
aioredis==2.0.1
|
||||||
|
asyncmy==0.2.9
|
||||||
amqp==5.1.1
|
amqp==5.1.1
|
||||||
annotated-types==0.6.0
|
annotated-types==0.6.0
|
||||||
anyio==3.6.2
|
anyio==3.6.2
|
||||||
|
|||||||
Reference in New Issue
Block a user