2014-08-15 20:08:01 +04:00
|
|
|
package driver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-05-04 17:42:28 +03:00
|
|
|
|
2023-02-15 10:41:45 +03:00
|
|
|
"git.internal/re/ledisdb/config"
|
2014-08-15 20:08:01 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Store interface {
|
|
|
|
String() string
|
|
|
|
Open(path string, cfg *config.Config) (IDB, error)
|
2014-08-25 10:18:23 +04:00
|
|
|
Repair(path string, cfg *config.Config) error
|
2014-08-15 20:08:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var dbs = map[string]Store{}
|
|
|
|
|
|
|
|
func Register(s Store) {
|
|
|
|
name := s.String()
|
|
|
|
if _, ok := dbs[name]; ok {
|
|
|
|
panic(fmt.Errorf("store %s is registered", s))
|
|
|
|
}
|
|
|
|
|
|
|
|
dbs[name] = s
|
|
|
|
}
|
|
|
|
|
|
|
|
func ListStores() []string {
|
|
|
|
s := []string{}
|
2016-05-01 18:33:02 +03:00
|
|
|
for k := range dbs {
|
2014-08-15 20:08:01 +04:00
|
|
|
s = append(s, k)
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetStore(cfg *config.Config) (Store, error) {
|
|
|
|
if len(cfg.DBName) == 0 {
|
|
|
|
cfg.DBName = config.DefaultDBName
|
|
|
|
}
|
|
|
|
|
|
|
|
s, ok := dbs[cfg.DBName]
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("store %s is not registered", cfg.DBName)
|
|
|
|
}
|
|
|
|
|
|
|
|
return s, nil
|
|
|
|
}
|