Download server/base/database/init_db.py from Bread-F/Intelligent-Medical-Guidance-Large-Model: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/Bread-F/Intelligent-Medical-Guidance-Large-Model/resolve/main/server/base/database/init_db.py
- Command line
-
hf download hf://spaces/Bread-F/Intelligent-Medical-Guidance-Large-Model/server/base/database/init_db.py
-
curl -L -o init_db.py https://huggingface.co/spaces/Bread-F/Intelligent-Medical-Guidance-Large-Model/resolve/main/server/base/database/init_db.py
1.17 kB
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| @File : init_db.py | |
| @Time : 2024/09/06 | |
| @Project : https://github.com/PeterH0323/Streamer-Sales | |
| @Author : HinGwenWong | |
| @Version : 1.0 | |
| @Desc : 数据库初始化 | |
| """ | |
| from loguru import logger | |
| from pydantic import PostgresDsn | |
| from pydantic_core import MultiHostUrl | |
| from sqlmodel import SQLModel, create_engine | |
| from ...web_configs import WEB_CONFIGS | |
| ECHO_DB_MESG = True # 数据库执行中是否回显,for debug | |
| def sqlalchemy_db_url() -> PostgresDsn: | |
| """生成数据库 URL | |
| Returns: | |
| PostgresDsn: 数据库地址 | |
| """ | |
| return MultiHostUrl.build( | |
| scheme="postgresql+psycopg", | |
| username=WEB_CONFIGS.POSTGRES_USER, | |
| password=WEB_CONFIGS.POSTGRES_PASSWORD, | |
| host=WEB_CONFIGS.POSTGRES_SERVER, | |
| port=WEB_CONFIGS.POSTGRES_PORT, | |
| path=WEB_CONFIGS.POSTGRES_DB, | |
| ) | |
| logger.info(f"connecting to db: {str(sqlalchemy_db_url())}") | |
| DB_ENGINE = create_engine(str(sqlalchemy_db_url()), echo=ECHO_DB_MESG) | |
| def create_db_and_tables(): | |
| """创建所有数据库和对应的表,有则跳过""" | |
| SQLModel.metadata.create_all(DB_ENGINE) | |