コード例 #1
0
ファイル: transaction.go プロジェクト: Ritsyy/almighty-core
// 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
}
コード例 #2
0
ファイル: list.go プロジェクト: ts25504/MuShare
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
}