mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2026-06-07 10:27:25 +08:00
feat: 增加配置项支持自由选择数据是否保存到关系型数据库中
This commit is contained in:
24
db.py
Normal file
24
db.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from tortoise import Tortoise
|
||||
from tortoise import run_async
|
||||
|
||||
from config.db_config import *
|
||||
|
||||
from tools import utils
|
||||
|
||||
|
||||
async def init_db(create_db: bool = False) -> None:
|
||||
await Tortoise.init(
|
||||
db_url=RELATION_DB_URL,
|
||||
modules={'models': ['models']},
|
||||
_create_db=create_db
|
||||
)
|
||||
|
||||
|
||||
async def init():
|
||||
await init_db(create_db=True)
|
||||
await Tortoise.generate_schemas()
|
||||
utils.logger.info("Init DB Success!")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_async(init())
|
||||
Reference in New Issue
Block a user