本站源代码
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.

62 lines
1.5KB

  1. package store
  2. import (
  3. "github.com/lunny/nodb/store/driver"
  4. )
  5. type DB struct {
  6. driver.IDB
  7. }
  8. func (db *DB) NewIterator() *Iterator {
  9. it := new(Iterator)
  10. it.it = db.IDB.NewIterator()
  11. return it
  12. }
  13. func (db *DB) NewWriteBatch() WriteBatch {
  14. return db.IDB.NewWriteBatch()
  15. }
  16. func (db *DB) NewSnapshot() (*Snapshot, error) {
  17. var err error
  18. s := &Snapshot{}
  19. if s.ISnapshot, err = db.IDB.NewSnapshot(); err != nil {
  20. return nil, err
  21. }
  22. return s, nil
  23. }
  24. func (db *DB) RangeIterator(min []byte, max []byte, rangeType uint8) *RangeLimitIterator {
  25. return NewRangeLimitIterator(db.NewIterator(), &Range{min, max, rangeType}, &Limit{0, -1})
  26. }
  27. func (db *DB) RevRangeIterator(min []byte, max []byte, rangeType uint8) *RangeLimitIterator {
  28. return NewRevRangeLimitIterator(db.NewIterator(), &Range{min, max, rangeType}, &Limit{0, -1})
  29. }
  30. //count < 0, unlimit.
  31. //
  32. //offset must >= 0, if < 0, will get nothing.
  33. func (db *DB) RangeLimitIterator(min []byte, max []byte, rangeType uint8, offset int, count int) *RangeLimitIterator {
  34. return NewRangeLimitIterator(db.NewIterator(), &Range{min, max, rangeType}, &Limit{offset, count})
  35. }
  36. //count < 0, unlimit.
  37. //
  38. //offset must >= 0, if < 0, will get nothing.
  39. func (db *DB) RevRangeLimitIterator(min []byte, max []byte, rangeType uint8, offset int, count int) *RangeLimitIterator {
  40. return NewRevRangeLimitIterator(db.NewIterator(), &Range{min, max, rangeType}, &Limit{offset, count})
  41. }
  42. func (db *DB) Begin() (*Tx, error) {
  43. tx, err := db.IDB.Begin()
  44. if err != nil {
  45. return nil, err
  46. }
  47. return &Tx{tx}, nil
  48. }
上海开阖软件有限公司 沪ICP备12045867号-1