** 速查表**
连接
sqlite3 .\backend\data\finan.db
常用命令
.tables
PRAGMA user_version;
PRAGMA journal_mode ; # 查询 WAL 类型 默认是 delete 模式
PRAGMA journal_mode=WAL;
PRAGMA journal_mode ; # 查询 WAL 类型
PRAGMA table_info(users);
SELECT id, name, account, disable_at FROM users;
.quit
python 连接
import sqlite3
def connect(path: Path | None = None) -> sqlite3.Connection:
p = path if path is not None else db_path()
p.parent.mkdir(parents=True, exist_ok=True)
conn = sqlite3.connect(p, timeout=10, check_same_thread=False)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA foreign_keys=ON")
conn.execute("PRAGMA journal_mode=WAL")
conn.execute("PRAGMA busy_timeout=5000")
return conn