Expose some collection methods already public in rslib backend (#2510)

* Expose some collection methods already public in rslib backend
This commit is contained in:
Joel Koen 2023-05-22 13:44:18 +10:00 committed by GitHub
parent 878920712f
commit 6b1c799cbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 10 deletions

View file

@ -122,6 +122,7 @@ Kieran Black <kieranlblack@gmail.com>
XeR <github.com/XeR>
mgrottenthaler <github.com/mgrottenthaler>
Austin Siew <github.com/Aquafina-water-bottle>
Joel Koen <mail@joelkoen.com>
********************

View file

@ -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<Option<DeckId>> {
pub fn get_deck_id(&self, human_name: &str) -> Result<Option<DeckId>> {
self.storage
.get_deck_id(NativeDeckName::from_human_name(human_name).as_native_str())
}

View file

@ -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<OpOutput<()>> {
pub fn update_note(&mut self, note: &mut Note) -> Result<OpOutput<()>> {
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<NoteFieldsState> {
pub fn note_fields_check(&mut self, note: &Note) -> Result<NoteFieldsState> {
Ok(if let Some(text) = note.fields.get(0) {
let field1 = if self.get_config_bool(BoolKey::NormalizeNoteText) {
normalize_to_nfc(text)

View file

@ -408,7 +408,7 @@ impl super::SqliteStorage {
.map_err(Into::into)
}
pub(crate) fn all_cards_of_note(&self, nid: NoteId) -> Result<Vec<Card>> {
pub fn all_cards_of_note(&self, nid: NoteId) -> Result<Vec<Card>> {
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<Vec<CardId>> {
pub fn all_card_ids_of_note_in_template_order(&self, nid: NoteId) -> Result<Vec<CardId>> {
self.db
.prepare_cached("select id from cards where nid = ? order by ord")?
.query_and_then([nid], |r| Ok(CardId(r.get(0)?)))?

View file

@ -21,7 +21,7 @@ fn row_to_tag(row: &Row) -> Result<Tag> {
impl SqliteStorage {
/// All tags in the collection, in alphabetical order.
pub(crate) fn all_tags(&self) -> Result<Vec<Tag>> {
pub fn all_tags(&self) -> Result<Vec<Tag>> {
self.db
.prepare_cached(include_str!("get.sql"))?
.query_and_then([], row_to_tag)?