diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-20 01:32:52 +0100 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-20 01:32:52 +0100 |
commit | cb3a9e58dbfa65da655c68e21d5bf270c4ccb7ef (patch) | |
tree | 68c8d797f26dbec33e335ea1b0ae96e1b36e26a1 /src/database.rs | |
parent | f739988888aacd04d9e821fd2d2eea467d01c6ae (diff) |
add searchResults
Diffstat (limited to 'src/database.rs')
-rw-r--r-- | src/database.rs | 67 |
1 files changed, 54 insertions, 13 deletions
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<Vec<Song>, sqlx::Error> { + pub async fn select_songs_by_artist(&self, artist_id: &str) -> Result<Vec<Song>, 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<Vec<Album>, 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<Vec<Album>, sqlx::Error> { + pub async fn select_albums_by_artist( + &self, + artist_id: &str, + ) -> Result<Vec<Album>, 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<Vec<Artist>, 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<Vec<Artist>, sqlx::Error>, + Result<Vec<Album>, sqlx::Error>, + Result<Vec<Song>, 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<Vec<Artist>, sqlx::Error>, + Result<Vec<Album>, sqlx::Error>, + Result<Vec<Song>, 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<Vec<Artist>, sqlx::Error>, + Result<Vec<Album>, sqlx::Error>, + Result<Vec<Song>, sqlx::Error>, + ) { + return ( + self.select_artists_by_name(name).await, + self.select_albums_by_name(name).await, + self.select_songs_by_name(name).await, + ); + } } |