40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
import sqlite3
|
||
import os
|
||
|
||
# 确保数据库文件存放在正确的目录
|
||
DB_PATH = 'database.db'
|
||
|
||
def init_db():
|
||
# 连接到数据库(如果不存在则创建)
|
||
conn = sqlite3.connect(DB_PATH)
|
||
cursor = conn.cursor()
|
||
|
||
# 创建外链表
|
||
cursor.execute('''
|
||
CREATE TABLE IF NOT EXISTS exlinks (
|
||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||
exlink_id TEXT NOT NULL,
|
||
qr_limit INTEGER DEFAULT 3,
|
||
drivers TEXT, -- 存储为JSON字符串,例如 '["quark","wechat"]'
|
||
use_limit INTEGER DEFAULT 0,
|
||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||
)
|
||
''')
|
||
|
||
# 创建用户表(如果需要的话)
|
||
cursor.execute('''
|
||
CREATE TABLE IF NOT EXISTS users (
|
||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||
username TEXT NOT NULL UNIQUE,
|
||
token TEXT,
|
||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||
)
|
||
''')
|
||
|
||
# 提交更改
|
||
conn.commit()
|
||
conn.close()
|
||
|
||
if __name__ == '__main__':
|
||
init_db()
|
||
print("Database initialized successfully!") |