feat(trash): NoteRepository.permanentDelete/emptyTrash/listTrashed (#4 v0.2.3)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
altair823
2026-05-01 20:47:05 +09:00
parent bf49b8351e
commit 11703b976e
2 changed files with 111 additions and 0 deletions

View File

@@ -238,6 +238,34 @@ export class NoteRepository {
.run(now, id);
}
permanentDelete(id: string): void {
this.db.prepare('DELETE FROM notes WHERE id=?').run(id);
}
emptyTrash(): { noteIds: string[] } {
const noteIds: string[] = [];
const tx = this.db.transaction(() => {
const rows = this.db
.prepare('SELECT id FROM notes WHERE deleted_at IS NOT NULL')
.all() as Array<{ id: string }>;
for (const r of rows) {
this.db.prepare('DELETE FROM notes WHERE id=?').run(r.id);
noteIds.push(r.id);
}
});
tx();
return { noteIds };
}
listTrashed(opts: { limit: number }): Note[] {
const limit = Math.max(1, Math.min(200, opts.limit));
const rows = this.db
.prepare(`SELECT * FROM notes WHERE deleted_at IS NOT NULL ORDER BY deleted_at DESC, id DESC LIMIT ?`)
.all(limit) as any[];
return rows.map((r) => this.hydrate(r));
}
/** @deprecated v0.2.3 #4 부터 hard delete 는 permanentDelete() 사용. soft delete 는 trash(). 본 메서드는 v0.2.4 에서 제거 예정. */
delete(id: string): void {
this.db.prepare('DELETE FROM notes WHERE id=?').run(id);
}