Documentation ¶
Overview ¶
Package level leveldb 数据库.
包括: DB, Service, 函数: KeyASC, KeyASCByInt, KeyDESC, KeyDESCByInt
Index ¶
- Constants
- Variables
- func Bytes(obj interface{}) []byte
- func Bytes2Interface(data []byte, obj interface{}) error
- func KeyASC(prefix []byte) []byte
- func KeyASCByInt(prefix []byte, id int64) []byte
- func KeyASCByUint32(prefix []byte, id uint32) []byte
- func KeyDESC(prefix []byte) []byte
- func KeyDESCByInt(prefix []byte, id int64) []byte
- func KeyDESCByUint32(prefix []byte, id uint32) []byte
- type Byteser
- type DB
- type Loader
- type Service
- func (p *Service) Append(key []byte, elems ...interface{})
- func (p *Service) Close() error
- func (p *Service) Get(key []byte, obj interface{}) bool
- func (p *Service) NextSequence(key []byte) uint32
- func (p *Service) NextSequenceASC(key []byte) []byte
- func (p *Service) NextSequenceDESC(key []byte) []byte
- func (p *Service) Pop(key []byte, elems ...interface{}) int
- func (p *Service) Push(key []byte, elems ...interface{})
- func (p *Service) Put(key []byte, o interface{})
- func (p *Service) Query(prefix []byte, limit int, slice interface{}, start []byte) []byte
- func (p *Service) QueryAndKey(prefix []byte, limit int, slice interface{}, start []byte, keys *[][]byte) []byte
- func (p *Service) Slice(key []byte, slice interface{})
- func (p *Service) StackSize(key []byte) int
Examples ¶
Constants ¶
View Source
const ( // ByteSlice 切片. ByteSlice = iota // ByteMap map. ByteMap // ByteSet 集合. ByteSet // ByteSeq 序列. ByteSeq // ByteStack 堆栈. ByteStack )
Variables ¶
View Source
var ErrBedType = errors.New("未知类型")
ErrBedType 错误的类型.
View Source
var ErrNotPtr = errors.New("参数不是指针")
ErrNotPtr 参数不是指针.
View Source
var ErrNotSlice = errors.New("参数不是切片")
ErrNotSlice 参数不是切片.
Functions ¶
func Bytes2Interface ¶ added in v1.0.47
Bytes2Interface 字节码转换到接口.
func KeyASCByInt ¶ added in v1.0.13
KeyASCByInt 根据整数生成顺序Key.
func KeyASCByUint32 ¶ added in v1.0.19
KeyASCByUint32 根据整数生成顺序Key.
func KeyDESCByInt ¶ added in v1.0.13
KeyDESCByInt 根据整数生成倒序Key.
func KeyDESCByUint32 ¶ added in v1.0.19
KeyDESCByUint32 uint32 倒序.
Types ¶
type DB ¶ added in v1.0.13
type DB interface { Has(key []byte, ro *opt.ReadOptions) (ret bool, err error) Put(key, value []byte, wo *opt.WriteOptions) error Get(key []byte, ro *opt.ReadOptions) (value []byte, err error) NewIterator(slice *util.Range, ro *opt.ReadOptions) iterator.Iterator Delete(key []byte, wo *opt.WriteOptions) error Close() error }
DB 数据库接口.
type Service ¶ added in v1.0.14
type Service struct { DB DB // contains filtered or unexported fields }
Service 数据库服务.
func (*Service) NextSequence ¶ added in v1.0.14
NextSequence 序列.
func (*Service) NextSequenceASC ¶ added in v1.0.14
NextSequenceASC 下一个顺序Key.
func (*Service) NextSequenceDESC ¶ added in v1.0.14
NextSequenceDESC 下一个倒序Key.
func (*Service) Query ¶ added in v1.0.15
Query 查询返回对象,返回下一个游标.
Example ¶
package main import ( "fmt" "gitee.com/xuender/oils/level" "gitee.com/xuender/oils/pb" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/storage" ) func main() { db, _ := leveldb.Open(storage.NewMemStorage(), nil) defer db.Close() service := level.NewService(db) test1 := &pb.Test{Data: "x1"} service.Put([]byte("t_1"), test1) test1.Data = "x2" service.Put([]byte("t_2"), test1) test1.Data = "x3" service.Put([]byte("t_3"), test1) tests := []*pb.Test{} cursor := service.Query([]byte("t_"), 2, &tests, nil) fmt.Println(tests) tests = []*pb.Test{} _ = service.Query([]byte("t_"), 2, &tests, cursor) fmt.Println(tests) }
Output: [data:"x1" data:"x2"] [data:"x3"]
func (*Service) QueryAndKey ¶ added in v1.0.22
func (p *Service) QueryAndKey( prefix []byte, limit int, slice interface{}, start []byte, keys *[][]byte, ) []byte
QueryAndKey 查询返回对象,返回下一个游标.
Click to show internal directories.
Click to hide internal directories.