func NewDB(name string, backend BackendType, dir string) (tmdb.DB, error) {
	dbCreator, ok := backends[backend]
	if !ok {
		keys := make([]string, 0, len(backends))
		for k := range backends {
			keys = append(keys, string(k))
		}
		return nil, fmt.Errorf("unknown db_backend %s, expected one of %v",
			backend, strings.Join(keys, ","))
	}
	db, err := dbCreator(name, dir)
	if err != nil {
		return nil, fmt.Errorf("failed to initialize database: %w", err)
	}
	return db, nil
}
NewDB creates a new database of type backend with the given name.
package metadb
import (
	"fmt"
	"strings"
	tmdb "github.com/tendermint/tm-db"
)
type BackendType string
const (
	GoLevelDBBackend BackendType = "goleveldb"
	CLevelDBBackend BackendType = "cleveldb"
	MemDBBackend BackendType = "memdb"
	BoltDBBackend BackendType = "boltdb"
	RocksDBBackend BackendType = "rocksdb"
	BadgerDBBackend BackendType = "badgerdb"
)
type dbCreator func(name string, dir string) (tmdb.DB, error)
var backends = map[BackendType]dbCreator{}
func registerDBCreator(backend BackendType, creator dbCreator, force bool) {
	_, ok := backends[backend]
	if !force && ok {
		return
	}
	backends[backend] = creator
}