You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
884 B

9 years ago
7 years ago
9 years ago
9 years ago
7 years ago
9 years ago
9 years ago
  1. package db
  2. import "fmt"
  3. //----------------------------------------
  4. // Main entry
  5. type dbBackendType string
  6. const (
  7. LevelDBBackend dbBackendType = "leveldb" // legacy, defaults to goleveldb unless +gcc
  8. CLevelDBBackend dbBackendType = "cleveldb"
  9. GoLevelDBBackend dbBackendType = "goleveldb"
  10. MemDBBackend dbBackendType = "memdb"
  11. FSDBBackend dbBackendType = "fsdb" // using the filesystem naively
  12. )
  13. type dbCreator func(name string, dir string) (DB, error)
  14. var backends = map[dbBackendType]dbCreator{}
  15. func registerDBCreator(backend dbBackendType, creator dbCreator, force bool) {
  16. _, ok := backends[backend]
  17. if !force && ok {
  18. return
  19. }
  20. backends[backend] = creator
  21. }
  22. func NewDB(name string, backend dbBackendType, dir string) DB {
  23. db, err := backends[backend](name, dir)
  24. if err != nil {
  25. panic(fmt.Sprintf("Error initializing DB: %v", err))
  26. }
  27. return db
  28. }