Archived
修复了无法使用MySQL数据库的bug, 现已正式支持MySQL数据库
This commit is contained in:
3 files changed
+25
-22
No files matched your search
+11
-16
@@ -8,20 +8,21 @@
|
||||
|
||||
import sqlite3
|
||||
import pymysql
|
||||
from bin.utils.settings import Settings
|
||||
|
||||
conf = Settings()
|
||||
|
||||
|
||||
class SQLite:
|
||||
"""操作SQLite数据库"""
|
||||
|
||||
def __init__(self,
|
||||
path: str = './bin/db/data.db'
|
||||
) -> None:
|
||||
def __init__(self, **kwargs) -> None:
|
||||
"""
|
||||
初始化SQLite对象
|
||||
完成后会自动提交, 自动关闭
|
||||
:param path: 数据库路径
|
||||
"""
|
||||
self.__path = path
|
||||
self.__path = './bin/db/data.db'
|
||||
self.__conn = sqlite3.connect(self.__path)
|
||||
self.__cursor = self.__conn.cursor()
|
||||
|
||||
@@ -147,12 +148,7 @@ class SQLite:
|
||||
class MySQL:
|
||||
"""操作MySQL数据库"""
|
||||
|
||||
def __init__(self,
|
||||
host: str,
|
||||
user: str,
|
||||
pwd: str,
|
||||
database: str
|
||||
) -> None:
|
||||
def __init__(self, **kwargs) -> None:
|
||||
"""
|
||||
初始化MySQL对象并创建一个连接
|
||||
创建的连接会在执行完毕后自动提交以及自动关闭
|
||||
@@ -161,10 +157,10 @@ class MySQL:
|
||||
:param pwd: 数据库密码
|
||||
:param database: 数据库名
|
||||
"""
|
||||
self.__host = host
|
||||
self.__user = user
|
||||
self.__password = pwd
|
||||
self.__database = database
|
||||
self.__host = conf.m_host
|
||||
self.__user = conf.m_user
|
||||
self.__password = conf.m_pwd
|
||||
self.__database = conf.m_db
|
||||
self.__conn = pymysql.connect(user=self.__user,
|
||||
password=self.__password,
|
||||
host=self.__host,
|
||||
@@ -268,7 +264,7 @@ class MySQL:
|
||||
:return:
|
||||
"""
|
||||
self.__cursor.execute(
|
||||
'update reqcount set times="%(times)s" where name="%(name)s"";' % {'times': times + 1, 'name': name})
|
||||
'update reqcount set times=%(times)s where name="%(name)s";' % {'times': times + 1, 'name': name})
|
||||
return True
|
||||
|
||||
def fetching_table(self, table: str) -> list:
|
||||
@@ -292,4 +288,3 @@ class MySQL:
|
||||
|
||||
|
||||
__all__ = ['SQLite', 'MySQL']
|
||||
|
||||
@@ -6,4 +6,12 @@
|
||||
# @File Name: __init__.py
|
||||
|
||||
|
||||
__all__ = ['error', 'logger', 'packing_logs', 'view']
|
||||
import os
|
||||
from bin.utils.logger import logger
|
||||
from bin.utils.settings import Settings
|
||||
|
||||
if __name__ != '__main__':
|
||||
if Settings().type == 'MySQL' and not os.path.exists('./bin/db/origin.sql'):
|
||||
logger.info('当前使用的数据库为MySQL请前往 https://themedatabase.vercel.app/source/sql 下载sql文件')
|
||||
logger.info('并使用 source 命令来导入MySQL数据库')
|
||||
logger.info('忽略此消息请在./bin/db内创建一个名为origin.sql的文件')
|
||||
@@ -59,7 +59,7 @@ class Settings:
|
||||
return self.__database['type']
|
||||
|
||||
@property
|
||||
def mysql_host(self) -> str:
|
||||
def m_host(self) -> str:
|
||||
"""
|
||||
mysql数据库的地址
|
||||
:return:
|
||||
@@ -67,7 +67,7 @@ class Settings:
|
||||
return self.__database['MySQL']['host']
|
||||
|
||||
@property
|
||||
def mysql_port(self) -> int:
|
||||
def m_port(self) -> int:
|
||||
"""
|
||||
mysql数据库的端口
|
||||
默认3306
|
||||
@@ -76,7 +76,7 @@ class Settings:
|
||||
return self.__database['MySQL']['port']
|
||||
|
||||
@property
|
||||
def mysql_user(self) -> str:
|
||||
def m_user(self) -> str:
|
||||
"""
|
||||
mysql数据库的用户名
|
||||
:return:
|
||||
@@ -84,7 +84,7 @@ class Settings:
|
||||
return self.__database['MySQL']['user']
|
||||
|
||||
@property
|
||||
def mysql_pwd(self) -> str:
|
||||
def m_pwd(self) -> str:
|
||||
"""
|
||||
mysql数据库的密码
|
||||
:return:
|
||||
@@ -92,7 +92,7 @@ class Settings:
|
||||
return self.__database['MySQL']['password']
|
||||
|
||||
@property
|
||||
def mysql_db(self) -> str:
|
||||
def m_db(self) -> str:
|
||||
"""
|
||||
保存数据库数据库名
|
||||
:return:
|
||||
|
||||
Reference in New Issue
Block a user