Added merge
This commit is contained in:
@@ -714,11 +714,6 @@ pub async fn set_album_artist(pool: &PgPool, album_id: i64, artist_id: i64) -> R
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn move_albums_to_artist(pool: &PgPool, from_artist_id: i64, to_artist_id: i64) -> Result<(), sqlx::Error> {
|
||||
sqlx::query("UPDATE albums SET artist_id = $2 WHERE artist_id = $1")
|
||||
.bind(from_artist_id).bind(to_artist_id).execute(pool).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn move_track_artists(pool: &PgPool, from_artist_id: i64, to_artist_id: i64) -> Result<(), sqlx::Error> {
|
||||
// Update, but avoid duplicate (track_id, artist_id, role) - delete first any conflicting rows
|
||||
@@ -772,3 +767,14 @@ pub async fn update_track_storage_path(pool: &PgPool, track_id: i64, new_path: &
|
||||
.bind(track_id).bind(new_path).execute(pool).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_albums_for_artist(pool: &PgPool, artist_id: i64) -> Result<Vec<Album>, sqlx::Error> {
|
||||
sqlx::query_as::<_, Album>("SELECT * FROM albums WHERE artist_id = $1 ORDER BY year NULLS LAST, name")
|
||||
.bind(artist_id).fetch_all(pool).await
|
||||
}
|
||||
|
||||
pub async fn find_album_by_artist_id_and_name(pool: &PgPool, artist_id: i64, name: &str) -> Result<Option<i64>, sqlx::Error> {
|
||||
let row: Option<(i64,)> = sqlx::query_as("SELECT id FROM albums WHERE artist_id = $1 AND name = $2")
|
||||
.bind(artist_id).bind(name).fetch_optional(pool).await?;
|
||||
Ok(row.map(|r| r.0))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user