File tree Expand file tree Collapse file tree 2 files changed +6
-24
lines changed
Expand file tree Collapse file tree 2 files changed +6
-24
lines changed Original file line number Diff line number Diff line change 1515RELATION_DB_PWD = os .getenv ("RELATION_DB_PWD" , "123456" )
1616RELATION_DB_USER = os .getenv ("RELATION_DB_USER" , "root" )
1717RELATION_DB_HOST = os .getenv ("RELATION_DB_HOST" , "localhost" )
18- RELATION_DB_PORT = os .getenv ("RELATION_DB_PORT" , " 3306" )
18+ RELATION_DB_PORT = os .getenv ("RELATION_DB_PORT" , 3306 )
1919RELATION_DB_NAME = os .getenv ("RELATION_DB_NAME" , "media_crawler" )
2020
21- RELATION_DB_URL = f"mysql://{ RELATION_DB_USER } :{ RELATION_DB_PWD } @{ RELATION_DB_HOST } :{ RELATION_DB_PORT } /{ RELATION_DB_NAME } "
2221
2322# redis config
2423REDIS_DB_HOST = "127.0.0.1" # your redis host
Original file line number Diff line number Diff line change 2626from var import db_conn_pool_var , media_crawler_db_var
2727
2828
29- def parse_mysql_url (mysql_url ) -> Dict :
30- """
31- 从配置文件中解析db链接url,给到aiomysql用,因为aiomysql不支持直接以URL的方式传递链接信息。
32- Args:
33- mysql_url: mysql://root:{RELATION_DB_PWD}@localhost:3306/media_crawler
34-
35- Returns:
36-
37- """
38- parsed_url = urlparse (mysql_url )
39- db_params = {
40- 'host' : parsed_url .hostname ,
41- 'port' : parsed_url .port or 3306 ,
42- 'user' : parsed_url .username ,
43- 'password' : parsed_url .password ,
44- 'db' : parsed_url .path .lstrip ('/' )
45- }
46- return db_params
47-
48-
4929async def init_mediacrawler_db ():
5030 """
5131 初始化数据库链接池对象,并将该对象塞给media_crawler_db_var上下文变量
5232 Returns:
5333
5434 """
55- db_conn_params = parse_mysql_url (config .RELATION_DB_URL )
5635 pool = await aiomysql .create_pool (
36+ host = config .RELATION_DB_HOST ,
37+ port = config .RELATION_DB_PORT ,
38+ user = config .RELATION_DB_USER ,
39+ password = config .RELATION_DB_PWD ,
40+ db = config .RELATION_DB_NAME ,
5741 autocommit = True ,
58- ** db_conn_params
5942 )
6043 async_db_obj = AsyncMysqlDB (pool )
6144
You can’t perform that action at this time.
0 commit comments