func (db *DB) AddPeer(addr lncore.LnAddr, pi lncore.PeerInfo) (err error) {

	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		return
	}

	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while adding peer: \n%s", err)
			return
		}
		err = tx.Commit()
	}()

	// use peer schema
	if _, err = tx.Exec("USE " + db.peerSchema + ";"); err != nil {
		return
	}

	addPeerQuery := fmt.Sprintf("INSERT INTO %s VALUES ('%s', '%s', '%s', %d);", db.peerTableName, pi.LnAddr.ToString(), *pi.NetAddr, *pi.Nickname, pi.PeerIdx)
	if _, err = tx.Exec(addPeerQuery); err != nil {
		return
	}

	return
}
// AddPeer adds a peer (address, peerinfo) to the database
AddPeer adds a peer (address, peerinfo) to the database
// AddPeer adds a peer ( address peerinfo ) to the database
func (db *DB) AddPeer(addr lncore.LnAddr, pi lncore.PeerInfo) (err error) {
	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		return
	}
	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while adding peer: \n%s", err)
			return
		}
		err = tx.Commit()
	}()
	if _, err = tx.Exec("USE " + db.peerSchema + ";"); err != nil {
		return
	}
	addPeerQuery := fmt.Sprintf("INSERT INTO %s VALUES ('%s', '%s', '%s', %d);", db.peerTableName, pi.LnAddr.ToString(), *pi.NetAddr, *pi.Nickname, pi.PeerIdx)
	if _, err = tx.Exec(addPeerQuery); err != nil {
		return
	}
	return
}
func ( db * DB ) AddPeer ( addr lncore . LnAddr , pi lncore . PeerInfo ) ( err error ) { var tx * sql . Tx if tx , err = db . DBHandler . Begin ( ) ; err != nil { return } defer func ( ) { if err != nil { tx . Rollback ( ) err = fmt . Errorf ( " \n " , err ) return } err = tx . Commit ( ) } ( ) if _ , err = tx . Exec ( " " + db . peerSchema + " " ) ; err != nil { return } addPeerQuery := fmt . Sprintf ( " " , db . peerTableName , pi . LnAddr . ToString ( ) , * pi . NetAddr , * pi . Nickname , pi . PeerIdx ) if _ , err = tx . Exec ( addPeerQuery ) ; err != nil { return } return }
AddPeer adds a peer (address, peerinfo) to the database
AddPeer adds a peer ( address peerinfo ) to the database
// use peer schema