Files
nj/app/lib/data/local/collections/journal_entry_collection.dart
iven 2481c8fce6 feat(app): Isar 本地数据库集成 — Collection + Repository + 编辑器持久化 + SyncEngine 队列
新增文件:
- data/local/collections/ 3 个 Isar Collection 定义 + 生成 Schema
- data/repositories/isar_journal_repository.dart 完整 CRUD + 乐观锁

修改文件:
- app.dart: IsarJournalRepository 注册为主 JournalRepository + SyncEngine 注入
- editor_page.dart: onSave 接入 JournalRepository,笔画/元素自动保存到 Isar
- sync_engine.dart: 新增 persistPendingQueue/restorePendingQueue Isar 持久化
- isar_database.dart: 注册 3 个 Collection Schema
- main.dart: 启动时初始化 Isar

架构: 离线优先 — Isar 为本地主仓库,Remote 供 SyncEngine 推送
2026-06-01 14:41:40 +08:00

61 lines
1.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 日记条目 Isar Collection — 本地持久化存储
//
// 与纯 Dart 模型 JournalEntry 分离,通过转换函数桥接。
// 业务 ID (String UUID) 作为索引字段Isar 主键用 autoIncrement。
import 'package:isar/isar.dart';
part 'journal_entry_collection.g.dart';
@collection
class JournalEntryCollection {
/// Isar 自增主键
Id isarId = Isar.autoIncrement;
/// 业务 UUID索引用于查找
@Index()
String id = '';
/// 作者 ID
String authorId = '';
/// 班级 ID可选
String? classId;
/// 日记标题
String title = '';
/// 日记日期epoch milliseconds
int dateEpoch = 0;
/// 心情enum → string
String mood = 'calm';
/// 天气enum → string
String weather = 'sunny';
/// 标签列表JSON String
String tagsJson = '[]';
/// 是否私密
bool isPrivate = true;
/// 是否分享到班级
bool sharedToClass = false;
/// 关联主题 ID可选
String? assignedTopicId;
/// 版本号(乐观锁)
int version = 1;
/// 创建时间epoch milliseconds
int createdAtEpoch = 0;
/// 更新时间epoch milliseconds
int updatedAtEpoch = 0;
/// 软删除标记
bool isDeleted = false;
}