Exemplo n.º 1
0
// MapPut puts into a map in a scope.
func (b *BotDB) MapPut(scope, mapName, key, value string) error {
	return b.db.Batch(func(tx *bolt.Tx) error {
		maps, err := getMapsBucket(tx, scope)
		if err != nil {
			return err
		}

		bucket := maps.Bucket([]byte(mapName))
		if bucket == nil {
			return ErrMapNotFound
		}

		return types.AsMap(bucket).Put(key, value)
	})
}
Exemplo n.º 2
0
// MapGet gets a value from a map in a scope.
func (b *BotDB) MapGet(scope, mapName, key string) (string, error) {
	var value string
	err := b.db.View(func(tx *bolt.Tx) error {
		maps, err := getMapsBucket(tx, scope)
		if err != nil {
			return err
		}

		bucket := maps.Bucket([]byte(mapName))
		if bucket == nil {
			return ErrMapNotFound
		}

		value, err = types.AsMap(bucket).Get(key)
		return err
	})
	return value, err
}