Example #1
0
//HasTagstr return true if one of tags has tagstr
func HasTagstr(datfile string, tagstr string) bool {
	var r bool
	err := db.DB.View(func(tx *bolt.Tx) error {
		r = db.HasVal(tx, "sugtag", []byte(datfile), tagstr)
		return nil
	})
	if err != nil {
		log.Println(err)
	}
	return r
}
Example #2
0
//hasNodeInTable returns true if nodelist has n.
func hasNodeInTable(datfile string, n *node.Node) bool {
	var r bool
	err := db.DB.View(func(tx *bolt.Tx) error {
		r = db.HasVal(tx, "lookupT", []byte(datfile), n.Nodestr)
		return nil
	})
	if err != nil {
		log.Println(err)
	}
	return r
}
Example #3
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)
}
Example #4
0
//Has returns true if thread has the tag.
func Has(thread string, tag ...string) bool {
	rr := false
	err := db.DB.View(func(tx *bolt.Tx) error {
		for _, t := range tag {
			if db.HasVal(tx, "usertag", []byte(thread), t) {
				rr = true
				return nil
			}
		}
		return nil
	})
	if err != nil {
		log.Println(err)
	}
	return rr
}