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.

60 lines
1.1 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package db
  2. import . "github.com/tendermint/tmlibs/common"
  3. type DB interface {
  4. Get([]byte) []byte
  5. Set([]byte, []byte)
  6. SetSync([]byte, []byte)
  7. Delete([]byte)
  8. DeleteSync([]byte)
  9. Close()
  10. NewBatch() Batch
  11. // For debugging
  12. Print()
  13. Iterator() Iterator
  14. Stats() map[string]string
  15. }
  16. type Batch interface {
  17. Set(key, value []byte)
  18. Delete(key []byte)
  19. Write()
  20. }
  21. type Iterator interface {
  22. Next() bool
  23. Key() []byte
  24. Value() []byte
  25. }
  26. //-----------------------------------------------------------------------------
  27. const (
  28. LevelDBBackendStr = "leveldb" // legacy, defaults to goleveldb.
  29. CLevelDBBackendStr = "cleveldb"
  30. GoLevelDBBackendStr = "goleveldb"
  31. MemDBBackendStr = "memdb"
  32. )
  33. type dbCreator func(name string, dir string) (DB, error)
  34. var backends = map[string]dbCreator{}
  35. func registerDBCreator(backend string, creator dbCreator, force bool) {
  36. _, ok := backends[backend]
  37. if !force && ok {
  38. return
  39. }
  40. backends[backend] = creator
  41. }
  42. func NewDB(name string, backend string, dir string) DB {
  43. db, err := backends[backend](name, dir)
  44. if err != nil {
  45. PanicSanity(Fmt("Error initializing DB: %v", err))
  46. }
  47. return db
  48. }