From 6b1c799cbff4f48d5d8797157bd40fc7f51053eb Mon Sep 17 00:00:00 2001 From: Joel Koen Date: Mon, 22 May 2023 13:44:18 +1000 Subject: [PATCH] Expose some collection methods already public in rslib backend (#2510) * Expose some collection methods already public in rslib backend --- CONTRIBUTORS | 1 + rslib/src/decks/mod.rs | 2 +- rslib/src/notes/mod.rs | 5 ++--- rslib/src/storage/card/mod.rs | 7 ++----- rslib/src/storage/tag/mod.rs | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 71a3e6107..3da3d4d2e 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -122,6 +122,7 @@ Kieran Black XeR mgrottenthaler Austin Siew +Joel Koen ******************** diff --git a/rslib/src/decks/mod.rs b/rslib/src/decks/mod.rs index c2184973e..06bb2f07a 100644 --- a/rslib/src/decks/mod.rs +++ b/rslib/src/decks/mod.rs @@ -177,7 +177,7 @@ impl Collection { /// Get a deck based on its human name. If you have a machine name, /// use the method in storage instead. - pub(crate) fn get_deck_id(&self, human_name: &str) -> Result> { + pub fn get_deck_id(&self, human_name: &str) -> Result> { self.storage .get_deck_id(NativeDeckName::from_human_name(human_name).as_native_str()) } diff --git a/rslib/src/notes/mod.rs b/rslib/src/notes/mod.rs index cea076c61..699ceff96 100644 --- a/rslib/src/notes/mod.rs +++ b/rslib/src/notes/mod.rs @@ -350,8 +350,7 @@ impl Collection { self.set_current_notetype_id(note.notetype_id) } - #[cfg(test)] - pub(crate) fn update_note(&mut self, note: &mut Note) -> Result> { + pub fn update_note(&mut self, note: &mut Note) -> Result> { self.transact(Op::UpdateNote, |col| col.update_note_inner(note)) } @@ -542,7 +541,7 @@ impl Collection { /// Check if the note's first field is empty or a duplicate. Then for cloze /// notetypes, check if there is a cloze in a non-cloze field or if there's /// no cloze at all. For other notetypes, just check if there's a cloze. - pub(crate) fn note_fields_check(&mut self, note: &Note) -> Result { + pub fn note_fields_check(&mut self, note: &Note) -> Result { Ok(if let Some(text) = note.fields.get(0) { let field1 = if self.get_config_bool(BoolKey::NormalizeNoteText) { normalize_to_nfc(text) diff --git a/rslib/src/storage/card/mod.rs b/rslib/src/storage/card/mod.rs index 11d42b901..1e3dbe038 100644 --- a/rslib/src/storage/card/mod.rs +++ b/rslib/src/storage/card/mod.rs @@ -408,7 +408,7 @@ impl super::SqliteStorage { .map_err(Into::into) } - pub(crate) fn all_cards_of_note(&self, nid: NoteId) -> Result> { + pub fn all_cards_of_note(&self, nid: NoteId) -> Result> { self.db .prepare_cached(concat!(include_str!("get_card.sql"), " where nid = ?"))? .query_and_then([nid], |r| row_to_card(r).map_err(Into::into))? @@ -431,10 +431,7 @@ impl super::SqliteStorage { }) } - pub(crate) fn all_card_ids_of_note_in_template_order( - &self, - nid: NoteId, - ) -> Result> { + pub fn all_card_ids_of_note_in_template_order(&self, nid: NoteId) -> Result> { self.db .prepare_cached("select id from cards where nid = ? order by ord")? .query_and_then([nid], |r| Ok(CardId(r.get(0)?)))? diff --git a/rslib/src/storage/tag/mod.rs b/rslib/src/storage/tag/mod.rs index 210246317..459b09c47 100644 --- a/rslib/src/storage/tag/mod.rs +++ b/rslib/src/storage/tag/mod.rs @@ -21,7 +21,7 @@ fn row_to_tag(row: &Row) -> Result { impl SqliteStorage { /// All tags in the collection, in alphabetical order. - pub(crate) fn all_tags(&self) -> Result> { + pub fn all_tags(&self) -> Result> { self.db .prepare_cached(include_str!("get.sql"))? .query_and_then([], row_to_tag)?