Skip to content

Commit 51f86b6

Browse files
committed
在数据引擎中添加初始 Todo 任务的种子数据逻辑,确保在表为空时插入默认任务;增加错误处理以捕获查找失败的情况
1 parent fcb1370 commit 51f86b6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

examples/server/src/kernel/engine.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ export class DataEngine {
6767
// In real world, we wait for 'ready' event.
6868
try {
6969
await this.ql.insert('SystemStatus', { status: 'OK', uptime: 0 });
70+
71+
// Seed some Todo Tasks if table is empty
72+
// Use try-catch because find might throw if object not registered (though it should be)
73+
try {
74+
const tasks = await this.ql.find('todo_task', { top: 1 });
75+
if (tasks.length === 0) {
76+
console.log('[DataEngine] Seeding initial Todo Data...');
77+
await this.ql.insert('todo_task', { subject: 'Review PR #102', is_completed: true, priority: 3, due_date: new Date() });
78+
await this.ql.insert('todo_task', { subject: 'Write Documentation', is_completed: false, priority: 2, due_date: new Date(Date.now() + 86400000) });
79+
await this.ql.insert('todo_task', { subject: 'Fix specific Server bug', is_completed: false, priority: 1 });
80+
}
81+
} catch (e) {
82+
console.warn('[DataEngine] Failed to seed todo_task', e);
83+
}
84+
7085
} catch(e) {
7186
console.warn('Seed failed (driver might not be ready):', e);
7287
}

0 commit comments

Comments
 (0)