2014-07-25 13:58:00 +04:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/siddontang/ledisdb/store/driver"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DB struct {
|
2014-08-25 10:18:23 +04:00
|
|
|
driver.IDB
|
2014-07-25 13:58:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (db *DB) NewIterator() *Iterator {
|
|
|
|
it := new(Iterator)
|
2014-08-25 10:18:23 +04:00
|
|
|
it.it = db.IDB.NewIterator()
|
2014-07-25 13:58:00 +04:00
|
|
|
|
|
|
|
return it
|
|
|
|
}
|
|
|
|
|
2014-07-29 18:30:59 +04:00
|
|
|
func (db *DB) NewWriteBatch() WriteBatch {
|
2014-08-25 10:18:23 +04:00
|
|
|
return db.IDB.NewWriteBatch()
|
2014-07-25 13:58:00 +04:00
|
|
|
}
|
|
|
|
|
2014-08-30 13:19:10 +04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2014-07-25 13:58:00 +04:00
|
|
|
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})
|
|
|
|
}
|
2014-07-29 13:29:51 +04:00
|
|
|
|
2014-08-25 10:18:23 +04:00
|
|
|
func (db *DB) Begin() (*Tx, error) {
|
|
|
|
tx, err := db.IDB.Begin()
|
2014-07-29 13:29:51 +04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-08-25 10:18:23 +04:00
|
|
|
return &Tx{tx}, nil
|
2014-07-29 13:29:51 +04:00
|
|
|
}
|