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.2 KiB

  1. /**
  2. * @file
  3. * @copyright defined in aergo/LICENSE.txt
  4. */
  5. package db
  6. // ImplType represents implementators of a DB interface
  7. type ImplType string
  8. const (
  9. // LevelImpl represents a name of DB interface implementation using leveldb
  10. LevelImpl ImplType = "leveldb"
  11. // MemoryImpl represents a name of DB interface implementation in memory
  12. MemoryImpl ImplType = "memorydb"
  13. )
  14. type dbConstructor func(dir string) (DB, error)
  15. // DB is an general interface to access at storage data
  16. type DB interface {
  17. Type() string
  18. Set(key, value []byte)
  19. Delete(key []byte)
  20. Get(key []byte) []byte
  21. Exist(key []byte) bool
  22. Iterator(start, end []byte) Iterator
  23. NewTx() Transaction
  24. NewBulk() Bulk
  25. Close()
  26. //Print()
  27. //Stats() map[string]string
  28. }
  29. // Transaction is used to batch multiple operations
  30. type Transaction interface {
  31. // Get(key []byte) []byte
  32. Set(key, value []byte)
  33. Delete(key []byte)
  34. Commit()
  35. Discard()
  36. }
  37. // Bulk is used to batch multiple transactions
  38. // This will internally commit transactions when reach maximum tx size
  39. type Bulk interface {
  40. Set(key, value []byte)
  41. Delete(key []byte)
  42. Flush()
  43. DiscardLast()
  44. }
  45. // Iterator is used to navigate specific key ranges
  46. type Iterator interface {
  47. Next()
  48. Valid() bool
  49. Key() []byte
  50. Value() []byte
  51. }