Beispiel #1
0
//removeFromTable removes node n and return true if exists.
//or returns false if not exists.
func removeFromTable(tx *bolt.Tx, datfile string, n *node.Node) error {
	if n == nil {
		err := errors.New("n is nil")
		log.Println(err)
		return err
	}
	if !db.HasVal(tx, "lookupT", []byte(datfile), n.Nodestr) {
		return errors.New("no node")
	}
	err := db.DelMap(tx, "lookupT", []byte(datfile), n.Nodestr)
	if err != nil {
		return err
	}
	return db.DelMap(tx, "lookupA", []byte(n.Nodestr), datfile)
}
Beispiel #2
0
//Set remove all tags and saves tag strings.
func Set(thread string, tag []string) {
	err := db.DB.Update(func(tx *bolt.Tx) error {
		ts, err := db.GetMap(tx, "usertag", []byte(thread))
		if err != nil {
			log.Println(err)
		}
		for t := range ts {
			err = db.DelMap(tx, "usertagTag", []byte(t), thread)
			if err != nil {
				return err
			}
		}
		if err := db.Del(tx, "usertag", []byte(thread)); err != nil {
			log.Println(err)
		}
		return AddTX(tx, thread, tag)
	})
	if err != nil {
		log.Print(err)
	}
}
Beispiel #3
0
//RemoveFromAllTable removes node n from all tables and return true if exists.
//or returns false if not exists.
func RemoveFromAllTable(n *node.Node) bool {
	err := db.DB.Update(func(tx *bolt.Tx) error {
		threads, err := db.GetMap(tx, "lookupA", []byte(n.Nodestr))
		if err != nil {
			return err
		}
		err = db.Del(tx, "lookupA", []byte(n.Nodestr))
		if err != nil {
			return err
		}
		for t := range threads {
			err := db.DelMap(tx, "lookupT", []byte(t), n.Nodestr)
			if err != nil {
				return err
			}
		}
		return nil
	})
	if err != nil {
		log.Println(err)
		return false
	}
	return true
}