Skip to content

Commit

Permalink
Simplify error check in SqliteStore note getters
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyrd committed Apr 19, 2024
1 parent 563bf03 commit ee831a0
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/store/sqlite_store/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,20 @@ impl SqliteStore {
if let NoteFilter::Unique(note_id) = filter {
params.push(note_id.inner().to_string());
}
let query_result = self
let notes = self
.db
.prepare(&filter.to_query(NoteTable::InputNotes))?
.query_map(params_from_iter(params), parse_input_note_columns)
.expect("no binding parameters used in query")
.map(|result| Ok(result?).and_then(parse_input_note))
.collect::<Result<Vec<InputNoteRecord>, _>>();
if let Ok(ref notes) = query_result {
if let NoteFilter::Unique(note_id) = filter {
if notes.is_empty() {
return Err(StoreError::NoteNotFound(note_id));
}
.collect::<Result<Vec<InputNoteRecord>, _>>()?;

if let NoteFilter::Unique(note_id) = filter {
if notes.is_empty() {
return Err(StoreError::NoteNotFound(note_id));
}
}
query_result
Ok(notes)
}

/// Retrieves the output notes from the database
Expand All @@ -139,21 +138,20 @@ impl SqliteStore {
if let NoteFilter::Unique(note_id) = filter {
params.push(note_id.inner().to_string());
}
let query_result = self
let notes = self
.db
.prepare(&filter.to_query(NoteTable::OutputNotes))?
.query_map(params_from_iter(params), parse_output_note_columns)
.expect("no binding parameters used in query")
.map(|result| Ok(result?).and_then(parse_output_note))
.collect::<Result<Vec<OutputNoteRecord>, _>>();
if let Ok(ref notes) = query_result {
if let NoteFilter::Unique(note_id) = filter {
if notes.is_empty() {
return Err(StoreError::NoteNotFound(note_id));
}
.collect::<Result<Vec<OutputNoteRecord>, _>>()?;

if let NoteFilter::Unique(note_id) = filter {
if notes.is_empty() {
return Err(StoreError::NoteNotFound(note_id));
}
}
query_result
Ok(notes)
}

pub(crate) fn insert_input_note(&mut self, note: &InputNoteRecord) -> Result<(), StoreError> {
Expand Down

0 comments on commit ee831a0

Please sign in to comment.