github.com/iotexproject/iotex-core@v1.14.1-rc1/db/builder.go (about) 1 package db 2 3 import "github.com/pkg/errors" 4 5 var ( 6 // ErrEmptyDBPath is the error when db path is empty 7 ErrEmptyDBPath = errors.New("empty db path") 8 ) 9 10 // CreateKVStore creates db from config and db path 11 func CreateKVStore(cfg Config, dbPath string) (KVStore, error) { 12 if len(dbPath) == 0 { 13 return nil, ErrEmptyDBPath 14 } 15 cfg.DbPath = dbPath 16 17 return NewBoltDB(cfg), nil 18 } 19 20 // CreateKVStoreWithCache creates db with cache from config and db path, cacheSize 21 func CreateKVStoreWithCache(cfg Config, dbPath string, cacheSize int) (KVStore, error) { 22 dao, err := CreateKVStore(cfg, dbPath) 23 if err != nil { 24 return nil, err 25 } 26 27 return NewKvStoreWithCache(dao, cacheSize), nil 28 }