Archived
update: 更新了对Redis数据库的支持
This commit is contained in:
1 file changed
+3
-32
+3
-32
@@ -11,30 +11,6 @@ from src.config import Config
|
|||||||
|
|
||||||
database = Config.database
|
database = Config.database
|
||||||
|
|
||||||
|
|
||||||
def split_(origin: str, type_: int = 0) -> dict:
|
|
||||||
"""
|
|
||||||
|
|
||||||
:param origin:
|
|
||||||
:param type_: 0 -> Mysql
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
origin = origin.split('://')[-1]
|
|
||||||
host = origin.split('@')[-1].split('/')[0].split(':')[0]
|
|
||||||
port = origin.split('@')[-1].split('/')[0].split(':')[1]
|
|
||||||
if type_ == 0: # Mysql
|
|
||||||
database_ = origin.split('@')[-1].split('/')[-1]
|
|
||||||
user = origin.split('@')[0].split(':')[0]
|
|
||||||
password = origin.split('@')[0].split(':')[1]
|
|
||||||
return {
|
|
||||||
'host': host,
|
|
||||||
'port': port,
|
|
||||||
'database': database_,
|
|
||||||
'user': user,
|
|
||||||
'password': password
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if database == 'sqlite':
|
if database == 'sqlite':
|
||||||
import sqlite3 as operator
|
import sqlite3 as operator
|
||||||
from src.utils.t_download import download
|
from src.utils.t_download import download
|
||||||
@@ -42,12 +18,7 @@ if database == 'sqlite':
|
|||||||
if not os.path.exists('./src/db/data.sqlite'):
|
if not os.path.exists('./src/db/data.sqlite'):
|
||||||
download('https://markusjoe.github.io/static_file_hosting/static/counter/data.sqlite')
|
download('https://markusjoe.github.io/static_file_hosting/static/counter/data.sqlite')
|
||||||
from src.db.db import SQLite as Database
|
from src.db.db import SQLite as Database
|
||||||
else:
|
elif 'redis' in database:
|
||||||
import pymysql as operator
|
import redis as operator
|
||||||
|
from src.db.db import Redis as Database
|
||||||
result = split_(database)
|
|
||||||
for k, v in zip(result.keys(), result.values()):
|
|
||||||
os.environ[f"m_{k}"] = v
|
|
||||||
from src.db.db import MySQL as Database
|
|
||||||
|
|
||||||
__all__ = [Database, operator]
|
__all__ = [Database, operator]
|
||||||
Reference in New Issue
Block a user