note type removal

This commit is contained in:
Damien Elmes 2020-04-24 18:31:36 +10:00
parent d32935382d
commit a181d9aa02
3 changed files with 31 additions and 3 deletions

View File

@ -960,9 +960,8 @@ impl Backend {
})
}
fn remove_notetype(&self, _id: i64) -> Result<()> {
println!("fixme: remove notetype");
Ok(())
fn remove_notetype(&self, id: i64) -> Result<()> {
self.with_col(|col| col.remove_notetype(NoteTypeID(id)))
}
fn new_note(&self, ntid: i64) -> Result<pb::Note> {

View File

@ -375,4 +375,13 @@ impl Collection {
})
.collect()
}
pub fn remove_notetype(&mut self, ntid: NoteTypeID) -> Result<()> {
// fixme: currently the storage layer is taking care of removing the notes and cards,
// but we need to do it in this layer in the future for undo handling
self.transact(None, |col| {
col.storage.set_schema_modified()?;
col.storage.remove_notetype(ntid)
})
}
}

View File

@ -205,6 +205,26 @@ impl SqliteStorage {
Ok(())
}
pub(crate) fn remove_notetype(&self, ntid: NoteTypeID) -> Result<()> {
self.db
.prepare_cached("delete from cards where nid in (select id from notes where mid=?)")?
.execute(&[ntid])?;
self.db
.prepare_cached("delete from notes where mid=?")?
.execute(&[ntid])?;
self.db
.prepare_cached("delete from templates where ntid=?")?
.execute(&[ntid])?;
self.db
.prepare_cached("delete from fields where ntid=?")?
.execute(&[ntid])?;
self.db
.prepare_cached("delete from notetypes where id=?")?
.execute(&[ntid])?;
Ok(())
}
pub(crate) fn move_cards_for_repositioned_templates(
&self,
ntid: NoteTypeID,