level

package
v1.1.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2022 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package level leveldb 数据库.

包括: DB, Service, 函数: KeyASC, KeyASCByInt, KeyDESC, KeyDESCByInt

Index

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 Bytes added in v1.0.47

func Bytes(obj interface{}) []byte

Bytes 对象转换字节码.

func Bytes2Interface added in v1.0.47

func Bytes2Interface(data []byte, obj interface{}) error

Bytes2Interface 字节码转换到接口.

func KeyASC added in v1.0.12

func KeyASC(prefix []byte) []byte

KeyASC 顺序Key.

func KeyASCByInt added in v1.0.13

func KeyASCByInt(prefix []byte, id int64) []byte

KeyASCByInt 根据整数生成顺序Key.

func KeyASCByUint32 added in v1.0.19

func KeyASCByUint32(prefix []byte, id uint32) []byte

KeyASCByUint32 根据整数生成顺序Key.

func KeyDESC added in v1.0.12

func KeyDESC(prefix []byte) []byte

KeyDESC 倒序Key.

func KeyDESCByInt added in v1.0.13

func KeyDESCByInt(prefix []byte, id int64) []byte

KeyDESCByInt 根据整数生成倒序Key.

func KeyDESCByUint32 added in v1.0.19

func KeyDESCByUint32(prefix []byte, id uint32) []byte

KeyDESCByUint32 uint32 倒序.

Types

type Byteser added in v1.0.17

type Byteser interface {
	Bytes() []byte
}

Byteser 转换字节码.

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 Loader added in v1.0.17

type Loader interface {
	// Load 加载.
	Load([]byte) error
}

Loader 加载器.

type Service added in v1.0.14

type Service struct {
	DB DB
	// contains filtered or unexported fields
}

Service 数据库服务.

func NewService added in v1.0.14

func NewService(db DB) *Service

NewService 新建数据库服务.

func (*Service) Append added in v1.0.43

func (p *Service) Append(key []byte, elems ...interface{})

Append 切片增加.

func (*Service) Close added in v1.0.36

func (p *Service) Close() error

Close 关闭.

func (*Service) Get added in v1.0.15

func (p *Service) Get(key []byte, obj interface{}) bool

Get 读取数据.

func (*Service) NextSequence added in v1.0.14

func (p *Service) NextSequence(key []byte) uint32

NextSequence 序列.

func (*Service) NextSequenceASC added in v1.0.14

func (p *Service) NextSequenceASC(key []byte) []byte

NextSequenceASC 下一个顺序Key.

func (*Service) NextSequenceDESC added in v1.0.14

func (p *Service) NextSequenceDESC(key []byte) []byte

NextSequenceDESC 下一个倒序Key.

func (*Service) Pop added in v1.0.34

func (p *Service) Pop(key []byte, elems ...interface{}) int

Pop 出栈.

func (*Service) Push added in v1.0.34

func (p *Service) Push(key []byte, elems ...interface{})

Push 压栈.

func (*Service) Put added in v1.0.15

func (p *Service) Put(key []byte, o interface{})

Put 写入数据.

func (*Service) Query added in v1.0.15

func (p *Service) Query(prefix []byte, limit int, slice interface{}, start []byte) []byte

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 查询返回对象,返回下一个游标.

func (*Service) Slice added in v1.0.43

func (p *Service) Slice(key []byte, slice interface{})

Slice 获取切片.

func (*Service) StackSize added in v1.0.34

func (p *Service) StackSize(key []byte) int

StackSize 栈内元素数量.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL