示例#1
0
func (db *gormDB) beginTransaction() (Transaction, error) {
	log.Debug("gorm#Begin")
	txn := &gormTxn{}
	txn.Dbm = db.Dbm.Begin()
	if err := txn.Dbm.Error; err != nil {
		log.Error("Failed to begin-transaction %v", err)
		return nil, err
	}
	return txn, nil
}
示例#2
0
func (txn *sqlxTxn) Commit() error {
	if txn.Tx == nil {
		return nil
	}
	log.Debug("sqlx#Commit")
	if err := txn.Tx.Commit(); err != nil {
		log.Error("Failed to commit-transaction %v", err)
		return err
	}
	txn.Dbm = nil
	return nil
}
示例#3
0
/**************************
  gormTxn functions
**************************/
func (txn *gormTxn) Commit() error {
	if txn.Dbm == nil {
		return nil
	}
	log.Debug("gorm#Commit")
	if err := txn.Dbm.Commit().Error; err != nil {
		log.Error("Failed to commit-transaction %v", err)
		return err
	}
	txn.Dbm = nil
	return nil
}
示例#4
0
func (db *sqlxDB) beginTransaction() (Transaction, error) {
	log.Debug("sqlx#Begin")
	var err error
	tx, err := db.Dbm.Beginx()
	if err != nil {
		log.Error("Failed to begin-transaction %v", err)
		return nil, err
	}
	txn := &sqlxTxn{}
	txn.Dbm = db.Dbm
	txn.Tx = tx
	return txn, nil
}