From cb3a9e58dbfa65da655c68e21d5bf270c4ccb7ef Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Mon, 20 Jan 2025 01:32:52 +0100 Subject: add searchResults --- src/database.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 13 deletions(-) (limited to 'src/database.rs') diff --git a/src/database.rs b/src/database.rs index a9daa7f..32b1de7 100644 --- a/src/database.rs +++ b/src/database.rs @@ -95,10 +95,7 @@ impl DatabaseWrapper { .await; } - pub async fn select_songs_by_artist( - &self, - artist_id: &str, - ) -> Result, sqlx::Error> { + pub async fn select_songs_by_artist(&self, artist_id: &str) -> Result, sqlx::Error> { return sqlx::query_as!( Song, "SELECT song.name, song.lyrics, song.id, @@ -161,7 +158,7 @@ impl DatabaseWrapper { } pub async fn select_albums_by_name(&self, name_raw: &str) -> Result, sqlx::Error> { - let name : String = format!("{}{}{}", "%", name_raw, "%"); + let name: String = format!("{}{}{}", "%", name_raw, "%"); return sqlx::query_as!( Album, "SELECT album.name, album.id, @@ -176,7 +173,10 @@ impl DatabaseWrapper { .await; } - pub async fn select_albums_by_artist(&self, artist_id: &str) -> Result, sqlx::Error> { + pub async fn select_albums_by_artist( + &self, + artist_id: &str, + ) -> Result, sqlx::Error> { return sqlx::query_as!( Album, "SELECT album.name, album.id, @@ -194,8 +194,7 @@ impl DatabaseWrapper { return sqlx::query_as!( Artist, "SELECT name, id - FROM artist" - , + FROM artist", ) .fetch_all(&self.db_pool) .await; @@ -206,8 +205,7 @@ impl DatabaseWrapper { Artist, "SELECT name, id FROM artist - WHERE id = ?" - , + WHERE id = ?", id, ) .fetch_all(&self.db_pool) @@ -215,17 +213,60 @@ impl DatabaseWrapper { } pub async fn select_artists_by_name(&self, name_raw: &str) -> Result, sqlx::Error> { - let name : String = format!("{}{}{}", "%", name_raw, "%"); + let name: String = format!("{}{}{}", "%", name_raw, "%"); println!("ERROR HUNTING: {}", name); return sqlx::query_as!( Artist, "SELECT name, id FROM artist - WHERE name LIKE ?" - , + WHERE name LIKE ?", name, ) .fetch_all(&self.db_pool) .await; } + + pub async fn search_results( + &self, + ) -> ( + Result, sqlx::Error>, + Result, sqlx::Error>, + Result, sqlx::Error>, + ) { + return ( + self.select_artists().await, + self.select_albums().await, + self.select_songs().await, + ); + } + + pub async fn search_results_by_id( + &self, + id: &str, + ) -> ( + Result, sqlx::Error>, + Result, sqlx::Error>, + Result, sqlx::Error>, + ) { + return ( + self.select_artist_by_id(id).await, + self.select_album_by_id(id).await, + self.select_song_by_id(id).await, + ); + } + + pub async fn search_results_by_name( + &self, + name: &str, + ) -> ( + Result, sqlx::Error>, + Result, sqlx::Error>, + Result, sqlx::Error>, + ) { + return ( + self.select_artists_by_name(name).await, + self.select_albums_by_name(name).await, + self.select_songs_by_name(name).await, + ); + } } -- cgit v1.2.3