代码优化,功能新增

This commit is contained in:
DelLevin-Home
2026-06-26 23:46:37 +08:00
parent f7ef50a677
commit 45137b96d6
59 changed files with 5041 additions and 4937 deletions

View File

@@ -39,7 +39,7 @@ class DatabaseHelper {
return await openDatabase(
path,
version: 21,
version: 22,
onCreate: _createDB,
onUpgrade: _onUpgrade,
);
@@ -152,6 +152,10 @@ class DatabaseHelper {
}
} catch (_) {}
}
if (oldVersion < 22) {
// 为笔记表添加置顶字段
await _upgradeNotesTableV22(db);
}
}
/// 升级books表到V11添加ISBN和出版时间字段
@@ -191,6 +195,15 @@ class DatabaseHelper {
}
}
/// 升级notes表到V22添加置顶字段
Future<void> _upgradeNotesTableV22(Database db) async {
final columns = await db.rawQuery('PRAGMA table_info(notes)');
final hasIsPinned = columns.any((col) => col['name'] == 'is_pinned');
if (!hasIsPinned) {
await db.execute('ALTER TABLE notes ADD COLUMN is_pinned INTEGER NOT NULL DEFAULT 0');
}
}
/// 升级到V14创建阅读器书籍表
Future<void> _createReaderBooksTable(Database db) async {
await db.execute('''
@@ -574,7 +587,8 @@ class DatabaseHelper {
images TEXT,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL,
is_deleted INTEGER DEFAULT 0
is_deleted INTEGER DEFAULT 0,
is_pinned INTEGER NOT NULL DEFAULT 0
)
''');