aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/lunny/nodb/store/db.go
blob: 00a8831a67ea19f0cdeffda88d35cbfcecd9e261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package store

import (
	"github.com/lunny/nodb/store/driver"
)

type DB struct {
	driver.IDB
}

func (db *DB) NewIterator() *Iterator {
	it := new(Iterator)
	it.it = db.IDB.NewIterator()

	return it
}

func (db *DB) NewWriteBatch() WriteBatch {
	return db.IDB.NewWriteBatch()
}

func (db *DB) NewSnapshot() (*Snapshot, error) {
	var err error
	s := &Snapshot{}
	if s.ISnapshot, err = db.IDB.NewSnapshot(); err != nil {
		return nil, err
	}

	return s, nil
}

func (db *DB) RangeIterator(min []byte, max []byte, rangeType uint8) *RangeLimitIterator {
	return NewRangeLimitIterator(db.NewIterator(), &Range{min, max, rangeType}, &Limit{0, -1})
}

func (db *DB) RevRangeIterator(min []byte, max []byte, rangeType uint8) *RangeLimitIterator {
	return NewRevRangeLimitIterator(db.NewIterator(), &Range{min, max, rangeType}, &Limit{0, -1})
}

//count < 0, unlimit.
//
//offset must >= 0, if < 0, will get nothing.
func (db *DB) RangeLimitIterator(min []byte, max []byte, rangeType uint8, offset int, count int) *RangeLimitIterator {
	return NewRangeLimitIterator(db.NewIterator(), &Range{min, max, rangeType}, &Limit{offset, count})
}

//count < 0, unlimit.
//
//offset must >= 0, if < 0, will get nothing.
func (db *DB) RevRangeLimitIterator(min []byte, max []byte, rangeType uint8, offset int, count int) *RangeLimitIterator {
	return NewRevRangeLimitIterator(db.NewIterator(), &Range{min, max, rangeType}, &Limit{offset, count})
}

func (db *DB) Begin() (*Tx, error) {
	tx, err := db.IDB.Begin()
	if err != nil {
		return nil, err
	}

	return &Tx{tx}, nil
}