Пример #1
0
func (lyric *Lyric) Save(db *sqlpg.DB) error {
	song := NewSong()
	song.Id = lyric.Id
	song.Lyric = lyric.Content
	song.HasLyric = true
	return db.Update(song, "id", "lyric", "has_lyric")
}
Пример #2
0
func (soca *SongCategory) Save(db *sqlpg.DB) error {

	var last error
	for _, song := range *(soca.Songs) {
		// dna.Log(song)
		last = db.Update(song, "id", "category")
	}
	return last
}
Пример #3
0
func (sf *APISongFreaksAlbum) Save(db *sqlpg.DB) error {
	album, err := sf.ToAlbum()

	if err != nil {
		return err
	} else {
		return db.Update(album, "id", "ratings", "songids", "review_author", "review")
	}

}
Пример #4
0
// Save stores some fields to DB.
func (svu *SongVideoUpdater) Save(db *sqlpg.DB) error {
	switch svu.Item.(type) {
	case *Song:
		return db.Update(svu.Item, "id", "title", "artists", "authors", "topics", "album_title", "album_href", "album_coverart", "producer", "lyric", "date_released", "date_created", "is_lyric")
	case *Video:
		return db.Update(svu.Item, "id", "title", "artists", "authors", "topics", "producer", "lyric", "date_released", "date_created", "is_lyric")
	default:
		panic("Invalid type of SongVideoUpdater.Item")
	}

}
Пример #5
0
func (alca *AlbumCategory) Save(db *sqlpg.DB) error {

	var last error
	var aids = dna.IntArray{}
	albums := &[]Album{}
	for _, album := range *(alca.Albums) {
		aids.Push(album.Id)
		// dna.Log(album)
	}
	query := "SELECT id, topics, genres from nsalbums WHERE id IN (" + aids.Join(",") + ")"
	// dna.Log(query)
	err := db.Select(albums, query)
	if err != nil {
		dna.Log(query, alca, *alca.Albums)
		dna.PanicError(err)
	}

	for _, album := range *(alca.Albums) {
		foundIndex := 0
		for j, anotherAlbum := range *(albums) {
			if album.Id == anotherAlbum.Id {
				foundIndex = j
			}
		}
		if foundIndex < len(*albums) {
			cat := album.Category.Concat((*albums)[foundIndex].Topics).Concat((*albums)[foundIndex].Genres).Unique()
			album.Category = cat.Filter(func(v dna.String, i dna.Int) dna.Bool {
				if v != "" {
					return true
				} else {
					return false
				}
			})

		}
		last = db.Update(album, "id", "category")

	}

	return last
}