Archived
update: 增加了对Deta的数据库支持和修改了一点文档
This commit is contained in:
6 files changed
+44
-14
No files matched your search
+3
-1
@@ -4,6 +4,7 @@
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2022/9/11
|
||||
# @File Name: config.py
|
||||
import os
|
||||
|
||||
|
||||
class Config:
|
||||
@@ -12,4 +13,5 @@ class Config:
|
||||
sqlite3 -> sqlite3 (default)
|
||||
mysql -> user:pwd@host:port/db
|
||||
"""
|
||||
database = "sqlite3" # Database type
|
||||
database = os.getenv('COUNTER_DB') or "sqlite3" # Database type
|
||||
DETA = eval(os.getenv('DETA_RUNTIME').title()) # mark Deta
|
||||
+10
-3
@@ -12,13 +12,20 @@ from src.config import Config
|
||||
|
||||
database = Config.database # operator
|
||||
|
||||
if not os.path.exists('./src/db/data.sqlite') and \
|
||||
Config.database == 'sqlite3':
|
||||
|
||||
def download_file(path: str):
|
||||
print('Downloading database file. Please wait...')
|
||||
file_url = 'https://static.rtast.cn/data.sqlite'
|
||||
urlretrieve(file_url, './src/db/data.sqlite') # standard lib for downloading file
|
||||
urlretrieve(file_url, path) # standard lib for downloading file
|
||||
print('Download database file successfully.')
|
||||
|
||||
|
||||
if Config.DETA and Config.database == 'sqlite3':
|
||||
if not os.path.exists('/tmp/data.sqlite'):
|
||||
download_file('/tmp/data.sqlite')
|
||||
elif not Config.DETA and Config.database == 'sqlite3':
|
||||
download_file('./src/db/data.sqlite')
|
||||
|
||||
if Config.database == 'sqlite3':
|
||||
from src.db.db import SQLite as Database
|
||||
|
||||
|
||||
+4
-1
@@ -56,7 +56,10 @@ class BaseSQL:
|
||||
class SQLite(BaseSQL):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.conn = operator.connect('./src/db/data.sqlite')
|
||||
if Config.DETA:
|
||||
self.conn = operator.connect('/tmp/data.sqlite')
|
||||
else:
|
||||
self.conn = operator.connect('./src/db/data.sqlite')
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user