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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user