Example #1
0
func (apiSong *APIFullSong) Save(db *sqlpg.DB) error {

	var queries = dna.StringArray{}
	var err error

	// Getting artist queries
	artists := apiSong.ToArtists()
	for _, artist := range artists {
		queries.Push(sqlpg.GetInsertIgnoreStatement(sqlpg.GetTableName(artist), artist, "id", artist.Id, false))
	}

	// Getting album query
	album := apiSong.ToAlbum()
	queries.Push(sqlpg.GetInsertIgnoreStatement(sqlpg.GetTableName(album), album, "id", album.Id, false))

	// Getting song query
	song := apiSong.ToSong()
	queries.Push(sqlpg.GetInsertStatement(sqlpg.GetTableName(song), song, false))

	for _, query := range queries {
		_, err = db.Exec(query.String())
	}

	if err != nil {
		errQueries := dna.StringArray(queries.Map(func(val dna.String, idx dna.Int) dna.String {
			return "$$$error$$$" + val + "$$$error$$$"
		}).([]dna.String))
		return errors.New(err.Error() + errQueries.Join("\n").String())
	} else {
		return nil
	}

}
Example #2
0
File: song.go Project: olragon/dna
func (song *Song) Save(db *sqlpg.DB) error {
	insertStmt := sqlpg.GetInsertStatement("mlsongs", song, false) + "\n"
	mutex.Lock()
	n, err := SongFile.WriteString(insertStmt.String())
	TotalBytes += dna.Int(n)
	mutex.Unlock()
	if err == nil {
		return nil
	} else {
		return err
	}

}
Example #3
0
File: user.go Project: olragon/dna
func (users *Users) Save(db *sqlpg.DB) error {
	var queries dna.String = ""
	// var err error
	// for _, user := range users.List {
	// 	if user.IsValid() == true {
	// 		err = db.InsertIgnore(user)
	// 	}
	// }
	// return err

	for _, user := range users.List {
		if user.IsValid() == true {
			queries += sqlpg.GetInsertStatement("ziusers", user, false) + "\n"
		}
	}
	mutex.Lock()
	n, err := SongFile.WriteString(queries.String())
	if err != nil {
		dna.Log("Cannot write to file while getting song", err.Error(), "\n\n")
	}
	TotalBytes += dna.Int(n)
	mutex.Unlock()
	return nil
}