package util

import (
	"github.com/33cn/chain33/common/db"
	types33 "github.com/33cn/chain33/types"
)

// KVDBList list
type KVDBList struct {
	db.DB
	L *db.ListHelper
}

// List 列表
func (l *KVDBList) List(prefix, key []byte, count, direction int32) ([][]byte, error) {
	vals := l.L.List(prefix, key, count, direction)
	if vals == nil {
		return nil, types33.ErrNotFound
	}
	return vals, nil
}

// PrefixCount 前缀长度
func (l *KVDBList) PrefixCount(prefix []byte) int64 {
	return l.L.PrefixCount(prefix)
}

// NewKVDB new
func NewKVDBList(d db.DB) *KVDBList {
	return &KVDBList{DB: d, L: db.NewListHelper(d)}
}
