Esempio n. 1
0
// Transactional executes the given function in a transaction. If todo returns an error, the transaction is rolled back
func Transactional(db *gorm.DB, todo func(tx *gorm.DB) error) error {
	var tx *gorm.DB
	tx = db.Begin()
	if tx.Error != nil {
		return tx.Error
	}
	if err := todo(tx); err != nil {
		tx.Rollback()
		return errs.WithStack(err)
	}
	tx.Commit()
	return tx.Error
}
Esempio n. 2
0
func getAudios(tx *gorm.DB, audios *[]models.Audio, id int) *[]models.Audio {
	tx.Where("sheet_id = ?",
		strconv.Itoa(id)).Find(&audios)
	tx.Commit()
	return audios
}