实现数据库级联删除
All checks were successful
Go CI / test-and-build (push) Successful in 10s

This commit is contained in:
2026-04-06 16:32:10 +08:00
parent 744fa578f1
commit 3aa8057648
5 changed files with 189 additions and 14 deletions

View File

@@ -55,13 +55,11 @@ func (r *SongRepository) GetAllWithDetails() ([]SongDetail, error) {
func (r *SongRepository) Get(id int) (Song, error) {
var song Song
rows, err := r.db.Query("SELECT id, title, artist_id, album_id, duration, media_file_id FROM songs WHERE id = ?", id)
err := r.db.QueryRow("SELECT id, title, artist_id, album_id, duration, media_file_id FROM songs WHERE id = ?", id).Scan(
&song.ID, &song.Title, &song.ArtistID, &song.AlbumID, &song.Duration, &song.MediaFileID,
)
if err != nil {
return Song{}, err
}
defer rows.Close()
if rows.Next() {
rows.Scan(&song.ID, &song.Title, &song.ArtistID, &song.AlbumID, &song.Duration, &song.MediaFileID)
}
return song, nil
}