Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ddboline committed Sep 15, 2023
1 parent 1d3b73f commit 5efa20c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions movie_collection_lib/src/movie_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,22 @@ impl MovieCollection {
/// # Errors
/// Returns error if db queries fail
pub async fn get_collection_index(&self, path: &str) -> Result<Option<Uuid>, Error> {
let query = query!(
r#"SELECT idx FROM movie_collection WHERE path = $path"#,
path = path
);
let conn = self.pool.get().await?;
let id = query.fetch_opt(&conn).await?;
let id = if path.starts_with("/") {
let query = query!(
r#"SELECT idx FROM movie_collection WHERE path = $path LIMIT 1"#,
path = path
);
let conn = self.pool.get().await?;
query.fetch_opt(&conn).await?
} else {
let path = format_sstr!("%{path}");
let query = query!(
r#"SELECT idx FROM movie_collection WHERE path like $path LIMIT 1"#,
path = path
);
let conn = self.pool.get().await?;
query.fetch_opt(&conn).await?
};
Ok(id.map(|(x,)| x))
}

Expand Down

0 comments on commit 5efa20c

Please sign in to comment.