refactor(onebot): extract openSqliteDb helper for the three stores

message/media/reaction store 构造器各自逐字复制同一段引导(mkdir 父目录 + 打开
DatabaseSync + PRAGMA journal_mode=WAL + PRAGMA synchronous=NORMAL),改一处 PRAGMA
要改三处。抽 openSqliteDb(dbPath) 收敛,schema init 与路径改写留在各调用方。

- message-store 的 .json→.db 改写保留(改写后同目录,mkdir 目标不变,等价)。
- 三文件删掉不再使用的 fs/path import。

行为严格不变:onebot 516 全绿、typecheck 干净;对抗性 Agent 逐字对比 HEAD 确认
三处引导等价、路径细节无边角、无回归。
This commit is contained in:
DrSmoothl committed 2026-07-01 18:37:42 +08:00
1 parent d89b095af5
commit 85ca207279
4 files changed
+27 -23

No files matched your search

+2 -7
View File
@@ -1,6 +1,5 @@
import fs from 'fs';
import { DatabaseSync, type StatementSync } from 'node:sqlite';
import path from 'path';
import { openSqliteDb } from './sqlite-open';
export class ReactionStore {
private readonly db: DatabaseSync;
@@ -11,11 +10,7 @@ export class ReactionStore {
private readonly stmtCountByEmoji: StatementSync;
constructor(dbPath: string) {
const dir = path.dirname(dbPath);
fs.mkdirSync(dir, { recursive: true });
this.db = new DatabaseSync(dbPath);
this.db.exec('PRAGMA journal_mode = WAL');
this.db.exec('PRAGMA synchronous = NORMAL');
this.db = openSqliteDb(dbPath);
this.initSchema();
this.stmtUpsert = this.db.prepare(