update: 修改了类的命名

This commit is contained in:
RTAkland
2023-01-07 20:56:43 +08:00
parent 681a535685
commit 2a47b24867
2 files changed
+8 -8

No files matched your search

+2 -2
View File
@@ -9,9 +9,9 @@ import os
class Config:
"""
Available database: sqlite3, mysql
Available database: sqlite3, mysql, detaBase
sqlite3 -> sqlite3 (default)
mysql -> user:pwd@host:port/db
mysql -> mysql://user:pwd@host:port/db
deta -> deta
"""
database = os.getenv("COUNTER_DB") or "sqlite3" # 数据库类型
+6 -6
View File
@@ -9,15 +9,15 @@
import os
from src.config import Config
if Config.database == 'sqlite3':
if Config.database in ["sqlite3", "sqlite"]:
import sqlite3 as operator
elif Config.database == 'deta':
elif Config.database == "deta":
from deta import Deta
else:
import pymysql as operator
class BaseSQL:
class SQL:
def __init__(self):
self.conn = None
self.cursor = None
@@ -56,17 +56,17 @@ class BaseSQL:
return result
class SQLite(BaseSQL):
class SQLite(SQL):
def __init__(self):
super().__init__()
self.conn = operator.connect('./src/db/data.sqlite')
self.cursor = self.conn.cursor()
class MySQL(BaseSQL):
class MySQL(SQL):
def __init__(self):
super().__init__()
_CONFIG = Config.database.split('@')
_CONFIG = Config.database.replace("mysql://", "").split("@")
user = _CONFIG[0].split(":")[0]
pwd = _CONFIG[0].split(":")[1]
host = _CONFIG[1].split(":")[0]