|
@ -5,21 +5,21 @@ import "fmt" |
|
|
//----------------------------------------
|
|
|
//----------------------------------------
|
|
|
// Main entry
|
|
|
// Main entry
|
|
|
|
|
|
|
|
|
type DbBackendType string |
|
|
|
|
|
|
|
|
type DBBackendType string |
|
|
|
|
|
|
|
|
const ( |
|
|
const ( |
|
|
LevelDBBackend DbBackendType = "leveldb" // legacy, defaults to goleveldb unless +gcc
|
|
|
|
|
|
CLevelDBBackend DbBackendType = "cleveldb" |
|
|
|
|
|
GoLevelDBBackend DbBackendType = "goleveldb" |
|
|
|
|
|
MemDBBackend DbBackendType = "memdb" |
|
|
|
|
|
FSDBBackend DbBackendType = "fsdb" // using the filesystem naively
|
|
|
|
|
|
|
|
|
LevelDBBackend DBBackendType = "leveldb" // legacy, defaults to goleveldb unless +gcc
|
|
|
|
|
|
CLevelDBBackend DBBackendType = "cleveldb" |
|
|
|
|
|
GoLevelDBBackend DBBackendType = "goleveldb" |
|
|
|
|
|
MemDBBackend DBBackendType = "memdb" |
|
|
|
|
|
FSDBBackend DBBackendType = "fsdb" // using the filesystem naively
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type dbCreator func(name string, dir string) (DB, error) |
|
|
type dbCreator func(name string, dir string) (DB, error) |
|
|
|
|
|
|
|
|
var backends = map[DbBackendType]dbCreator{} |
|
|
|
|
|
|
|
|
var backends = map[DBBackendType]dbCreator{} |
|
|
|
|
|
|
|
|
func registerDBCreator(backend DbBackendType, creator dbCreator, force bool) { |
|
|
|
|
|
|
|
|
func registerDBCreator(backend DBBackendType, creator dbCreator, force bool) { |
|
|
_, ok := backends[backend] |
|
|
_, ok := backends[backend] |
|
|
if !force && ok { |
|
|
if !force && ok { |
|
|
return |
|
|
return |
|
@ -27,7 +27,7 @@ func registerDBCreator(backend DbBackendType, creator dbCreator, force bool) { |
|
|
backends[backend] = creator |
|
|
backends[backend] = creator |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewDB(name string, backend DbBackendType, dir string) DB { |
|
|
|
|
|
|
|
|
func NewDB(name string, backend DBBackendType, dir string) DB { |
|
|
db, err := backends[backend](name, dir) |
|
|
db, err := backends[backend](name, dir) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
panic(fmt.Sprintf("Error initializing DB: %v", err)) |
|
|
panic(fmt.Sprintf("Error initializing DB: %v", err)) |
|
|