Skip to content

Commit c96bb4e

Browse files
committed
fix: Improve database initialization and error handling for production
- Add detailed logging for database loading process - Enhance database verification with table and record count checks - Add fallback mechanism with clear error messages - Improve debugging for production deployment issues This should resolve the search results not displaying issue in gh-pages.
1 parent c5fc14d commit c96bb4e

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/utils/database.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ export class DatabaseManager {
3333
await this.loadDatabase();
3434

3535
this.useSampleData = false;
36+
console.log('SQLiteデータベース初期化完了');
3637
} catch (error) {
3738
console.error('SQLiteデータベース初期化エラー:', error);
39+
console.log('サンプルデータモードにフォールバック');
3840
this.initializeWithSampleData();
3941
}
4042
}
@@ -73,6 +75,7 @@ export class DatabaseManager {
7375
});
7476

7577
// データベースファイルを取得
78+
console.log('データベースファイルを読み込み中...');
7679
const response = await fetch('./database/eparts.db');
7780
if (!response.ok) {
7881
throw new Error(`データベースファイルが見つかりません (status: ${response.status})`);
@@ -85,6 +88,7 @@ export class DatabaseManager {
8588
// データベースの内容を確認
8689
this.verifyDatabase(db);
8790
this.db = db;
91+
console.log('データベース読み込み完了');
8892

8993
} catch (error) {
9094
console.error('データベース読み込みエラー:', error);
@@ -98,9 +102,27 @@ export class DatabaseManager {
98102
private verifyDatabase(db: any): void {
99103
try {
100104
// データベースの基本的な確認のみ実行
101-
db.exec("SELECT name FROM sqlite_master WHERE type='table'");
105+
const stmt = db.prepare("SELECT name FROM sqlite_master WHERE type='table'");
106+
const tables = [];
107+
while (stmt.step()) {
108+
const row = stmt.get();
109+
tables.push(row[0]);
110+
}
111+
stmt.free();
112+
113+
console.log('データベーステーブル:', tables);
114+
115+
// パーツ数を確認
116+
const countStmt = db.prepare("SELECT COUNT(*) FROM parts");
117+
countStmt.step();
118+
const count = countStmt.get()[0];
119+
countStmt.free();
120+
121+
console.log('パーツ数:', count);
122+
102123
} catch (error) {
103124
console.error('データベース確認エラー:', error);
125+
throw error;
104126
}
105127
}
106128

0 commit comments

Comments
 (0)