123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- """
- @desc 数据库连接
- @auth chenkai
- @date 2020/11/19
- """
- from .DataBaseOperation import *
- from model.common.log import logger
- import yaml
- import os
- log = logger()
- class MysqlUtils:
- _quchen_text = None
- def __init__(self):
- p_path = os.path.dirname(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))
- path = os.path.join(p_path,"config", "db_config.yaml")
- f = open(path, encoding="utf-8")
- self.config = yaml.load(f.read(), Loader=yaml.FullLoader)
- @property
- def quchen_text(self):
- conf = self.config['quchen_text']
- self._quchen_text = MysqlOperation(host=conf['host'],
- user=conf['user'],
- passwd=conf['passwd'],
- db=conf['db'])
- return self._quchen_text
- def find_db(self, db):
- if db == "quchen_text":
- self._quchen_text = self._quchen_text
- return self._quchen_text
- else:
- log.debug("输入数据库有误")
- def close(self):
- if self._quchen_text:
- self._quchen_text.cursor.close()
- self._quchen_text.conn.close()
|