当前位置: 首页>>代码示例>>Golang>>正文


Golang Tx.Bucket方法代码示例

本文整理汇总了Golang中github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/boltdb/bolt.Tx.Bucket方法的典型用法代码示例。如果您正苦于以下问题:Golang Tx.Bucket方法的具体用法?Golang Tx.Bucket怎么用?Golang Tx.Bucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/boltdb/bolt.Tx的用法示例。


在下文中一共展示了Tx.Bucket方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: removeFromRootLabel

func (s *BoltStore) removeFromRootLabel(tx *bolt.Tx, itemType string, itemID uint64, userid []byte) {
	index := tx.Bucket(boltBucketLabelRootIndex)
	id := index.Get(userid)
	if id != nil {
		label := itemType + "/" + strconv.FormatUint(itemID, 10)
		b := tx.Bucket(boltBucketLabels)
		v := b.Get(id)
		root := &Label{}
		root.UnmarshalMsg(v)

		if strings.Contains(root.Content, ","+label) {
			root.Content = strings.Replace(root.Content, ","+label, "", 1)
		} else if strings.HasPrefix(root.Content, label+",") {
			root.Content = strings.Replace(root.Content, label+",", "", 1)
		} else {
			root.Content = strings.Replace(root.Content, label, "", 1)
		}

		v, err := root.MarshalMsg(nil)
		if err != nil {
			return
		}

		b.Put(id, v)
	}
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:26,代码来源:store_bolt_labels.go

示例2: simulatePutHandler

// Inserts a key into the database.
func simulatePutHandler(tx *bolt.Tx, qdb *QuickDB) {
	var err error
	keys, value := randKeys(), randValue()

	// Retrieve root bucket.
	b := tx.Bucket(keys[0])
	if b == nil {
		b, err = tx.CreateBucket(keys[0])
		if err != nil {
			panic("create bucket: " + err.Error())
		}
	}

	// Create nested buckets, if necessary.
	for _, key := range keys[1 : len(keys)-1] {
		child := b.Bucket(key)
		if child != nil {
			b = child
		} else {
			b, err = b.CreateBucket(key)
			if err != nil {
				panic("create bucket: " + err.Error())
			}
		}
	}

	// Insert into database.
	if err := b.Put(keys[len(keys)-1], value); err != nil {
		panic("put: " + err.Error())
	}

	// Insert into in-memory database.
	qdb.Put(keys, value)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:35,代码来源:simulation_test.go

示例3: simulateGetHandler

// Retrieves a key from the database and verifies that it is what is expected.
func simulateGetHandler(tx *bolt.Tx, qdb *QuickDB) {
	// Randomly retrieve an existing exist.
	keys := qdb.Rand()
	if len(keys) == 0 {
		return
	}

	// Retrieve root bucket.
	b := tx.Bucket(keys[0])
	if b == nil {
		panic(fmt.Sprintf("bucket[0] expected: %08x\n", trunc(keys[0], 4)))
	}

	// Drill into nested buckets.
	for _, key := range keys[1 : len(keys)-1] {
		b = b.Bucket(key)
		if b == nil {
			panic(fmt.Sprintf("bucket[n] expected: %v -> %v\n", keys, key))
		}
	}

	// Verify key/value on the final bucket.
	expected := qdb.Get(keys)
	actual := b.Get(keys[len(keys)-1])
	if !bytes.Equal(actual, expected) {
		fmt.Println("=== EXPECTED ===")
		fmt.Println(expected)
		fmt.Println("=== ACTUAL ===")
		fmt.Println(actual)
		fmt.Println("=== END ===")
		panic("value mismatch")
	}
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:34,代码来源:simulation_test.go

示例4: getLabel

func (s *BoltStore) getLabel(tx *bolt.Tx, id []byte) *Label {
	b := tx.Bucket(boltBucketLabels)
	v := b.Get(id)
	if v != nil {
		label := &Label{}
		label.UnmarshalMsg(v)
		return label
	}
	return nil
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:10,代码来源:store_bolt_labels.go

示例5: addEvent

func (s *BoltStore) addEvent(tx *bolt.Tx, event *Event, userid uint64) error {
	b := tx.Bucket(boltBucketEvents)
	eventID, err := b.NextSequence()
	if err != nil {
		return err
	}

	v, err := event.MarshalMsg(nil)
	if err != nil {
		return err
	}

	id := make([]byte, 24)
	binary.BigEndian.PutUint64(id[:8], userid)
	binary.BigEndian.PutUint64(id[8:16], event.ClientTS)
	binary.BigEndian.PutUint64(id[16:], eventID)

	return b.Put(id, v)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:19,代码来源:store_bolt_events.go

示例6: saveEpisode

func (s *BoltStore) saveEpisode(tx *bolt.Tx, ep *Episode) error {
	index := tx.Bucket(boltBucketEpisodeGUIDIndex)
	guid := []byte(ep.GUID)
	if index.Get(guid) != nil {
		return nil
	}

	var err error
	b := tx.Bucket(boltBucketEpisodes)
	ep.ID, err = b.NextSequence()
	if err != nil {
		return err
	}

	ep.EncodeFeed()
	v, err := ep.MarshalMsg(nil)
	if err != nil {
		return err
	}

	id := uint64Bytes(ep.ID)
	err = index.Put(guid, id)
	if err != nil {
		return err
	}

	idxID := make([]byte, 16)
	binary.BigEndian.PutUint64(idxID[:8], ep.CastID)
	binary.BigEndian.PutUint64(idxID[8:], ep.ID)
	castIndex := tx.Bucket(boltBucketEpisodeCastIDIndex)
	err = castIndex.Put(idxID, id)
	if err != nil {
		return err
	}

	crawlTSIndex := tx.Bucket(boltBucketEpisodeCrawlTSIndex)
	idxID = make([]byte, 24)
	binary.BigEndian.PutUint64(idxID[:8], uint64(ep.CrawlTS))
	binary.BigEndian.PutUint64(idxID[8:16], ep.ID)
	binary.BigEndian.PutUint64(idxID[16:], ep.CastID)
	err = crawlTSIndex.Put(idxID, id)
	if err != nil {
		return err
	}

	return b.Put(id, v)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:47,代码来源:store_bolt_episodes.go

示例7: addToRootLabel

func (s *BoltStore) addToRootLabel(tx *bolt.Tx, itemType string, itemID uint64, userid []byte) {
	var err error
	label := itemType + "/" + strconv.FormatUint(itemID, 10)
	b := tx.Bucket(boltBucketLabels)
	index := tx.Bucket(boltBucketLabelRootIndex)
	id := index.Get(userid)
	if id != nil {
		v := b.Get(id)
		root := &Label{}
		root.UnmarshalMsg(v)
		if strings.Contains(root.Content, label) {
			return
		}

		if root.Content != "" {
			root.Content += ","
		}
		root.Content += label

		v, err = root.MarshalMsg(nil)
		if err != nil {
			return
		}

		b.Put(id, v)
	} else {
		root := &Label{
			Name:    "root",
			Content: itemType + "/" + strconv.FormatUint(itemID, 10),
			Root:    true,
		}

		root.ID, err = b.NextSequence()
		if err != nil {
			return
		}

		v, err := root.MarshalMsg(nil)
		if err != nil {
			return
		}

		id = uint64Bytes(root.ID)
		index.Put(userid, id)

		idxID := []byte{}
		idxID = append(idxID, userid...)
		idxID = append(idxID, id...)
		index = tx.Bucket(boltBucketLabelUserIDIndex)
		err = index.Put(idxID, id)
		if err != nil {
			return
		}

		b.Put(id, v)
	}
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:57,代码来源:store_bolt_labels.go


注:本文中的github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/boltdb/bolt.Tx.Bucket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。