lots of post-DB cleanup
This commit is contained in:
parent
965d6f5c3e
commit
c9d950d2b2
23 changed files with 412 additions and 550 deletions
|
@ -29,14 +29,14 @@ func GetAllArtists(db *sqlx.DB) ([]*model.Artist, error) {
|
|||
return artists, nil
|
||||
}
|
||||
|
||||
func GetArtistsNotOnRelease(db *sqlx.DB, release *model.Release) ([]*model.Artist, error) {
|
||||
func GetArtistsNotOnRelease(db *sqlx.DB, releaseID string) ([]*model.Artist, error) {
|
||||
var artists = []*model.Artist{}
|
||||
|
||||
err := db.Select(&artists,
|
||||
"SELECT * FROM artist "+
|
||||
"WHERE id NOT IN "+
|
||||
"(SELECT artist FROM musiccredit WHERE release=$1)",
|
||||
release.ID)
|
||||
releaseID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -44,6 +44,33 @@ func GetArtistsNotOnRelease(db *sqlx.DB, release *model.Release) ([]*model.Artis
|
|||
return artists, nil
|
||||
}
|
||||
|
||||
func GetArtistCredits(db *sqlx.DB, artistID string) ([]*model.Credit, error) {
|
||||
type DBCredit struct {
|
||||
Release string
|
||||
Artist string
|
||||
Role string
|
||||
Primary bool `db:"is_primary"`
|
||||
}
|
||||
var dbCredits []DBCredit
|
||||
|
||||
err := db.Select(&dbCredits, "SELECT * FROM musiccredit WHERE artist=$1", artistID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var credits []*model.Credit
|
||||
for _, credit := range dbCredits {
|
||||
credits = append(credits, &model.Credit{
|
||||
Release: model.Release{ ID: credit.Release },
|
||||
Artist: model.Artist{ ID: credit.Artist },
|
||||
Role: credit.Role,
|
||||
Primary: credit.Primary,
|
||||
})
|
||||
}
|
||||
|
||||
return credits, nil
|
||||
}
|
||||
|
||||
func CreateArtist(db *sqlx.DB, artist *model.Artist) error {
|
||||
_, err := db.Exec(
|
||||
"INSERT INTO artist (id, name, website, avatar) "+
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue