优化扫描
All checks were successful
Go CI / test-and-build (push) Successful in 14s
Web CI / lint-test-build (push) Successful in 28s

This commit is contained in:
2026-04-11 13:57:48 +08:00
parent 169b2c1858
commit 3f82e29c6c
11 changed files with 392 additions and 76 deletions

View File

@@ -95,6 +95,18 @@ func (r *SongRepository) Get(id int) (model.Song, error) {
return song, nil
}
func (r *SongRepository) HasByMediaFileID(mediaFileID int) (bool, error) {
var exists int
err := r.db.QueryRow("SELECT 1 FROM songs WHERE media_file_id = ? LIMIT 1", mediaFileID).Scan(&exists)
if err == sql.ErrNoRows {
return false, nil
}
if err != nil {
return false, err
}
return true, nil
}
func (r *SongRepository) Create(title string, artistID, albumID, duration, mediaFileID int) (model.Song, error) {
result, err := r.db.Exec(
"INSERT INTO songs (title, artist_id, album_id, duration, media_file_id) VALUES (?, ?, ?, ?, ?)",