badgerquery

package module
v0.0.0-...-5e4d13d Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: BSD-2-Clause Imports: 10 Imported by: 0

README

badgerquery

enchance badger db with index and query

data structs

  • db
    • seq
      • meta:seq
  • table
    • config
      • meta:table:config:$tableName
    • record
      • data
        • $tableDataID:$dataKey
      • index
        • $tableIndexID:$dataKey
  • index
    • config
      • meta:table:index:config:$tableName:$indexName
    • seq
      • meta:table:index:seq:$tableName:$indexName
    • data
      • $indexID:$dataKey:$indexSeq

components

- GC
    - badger's gc
    - clean deleted table, index , data

create item

  • create item
  • create index

update item

  • save item
  • add changed index
  • delete old index

delete item

  • delete item
  • delete index

create table

  • create default id index

drop table

  • delete items
  • delete index
  • delete index data
  • delete

create index

  • build index on exists items

drop index

  • delete index data

query

  • get queue

txn too big

  • do not update more than 1000 items in one update.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDBClosed       = errors.New("db already closed")
	ErrTableExists    = errors.New("table already exists")
	ErrTableNotExists = errors.New("table not exists")

	ErrIndexNotExists = errors.New("index not exists")

	ErrItemExists = errors.New("item already exists")
)

Functions

func DecodeIndexData

func DecodeIndexData(buf []byte, items ...interface{}) error

func EncodeIndexConfig

func EncodeIndexConfig(t *IndexConfig) []byte

func EncodeTableConfig

func EncodeTableConfig(t *TableConfig) []byte

Types

type DB

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

func Open

func Open(badgerOpt badger.Options, opt Options) (*DB, error)

func (*DB) Close

func (this *DB) Close() error

func (*DB) CreateItem

func (this *DB) CreateItem(item Item) error

not safe

func (*DB) CreateTable

func (this *DB) CreateTable(tableName string, indexConfigs map[string]*IndexConfig) error

func (*DB) DeleteItem

func (this *DB) DeleteItem(tableName string, itemKey string) error

safe

func (*DB) EachIndex

func (this *DB) EachIndex(opt IteratorOptions) error

func (*DB) EachItem

func (this *DB) EachItem(opt IteratorOptions) error

func (*DB) GC

func (this *DB) GC()

* badger 自身的GC 异步删除相关数据 重建索引

func (*DB) GetItem

func (this *DB) GetItem(itemKey string, item Item) error

func (*DB) HasItem

func (this *DB) HasItem(tableName string, itemKey string) (bool, error)

func (*DB) NextID

func (this *DB) NextID(seq *badger.Sequence) (uint64, error)

* can omit error now

func (*DB) SaveItem

func (this *DB) SaveItem(item Item) error

safe

func (*DB) Update

func (this *DB) Update(fn func(txn *badger.Txn) error, runBefore func()) error

* handle ErrConflict, ErrRetry.

func (*DB) UpdateItem

func (this *DB) UpdateItem(item Item) error

not safe

func (*DB) View

func (this *DB) View(fn func(txn *badger.Txn) error, runBefore func()) error

* handle ErrRetry, when gc cause vlog changed, we can assume no errors now

type Index

type Index struct {
	// contains filtered or unexported fields
}

func (*Index) Close

func (this *Index) Close() error

func (*Index) Config

func (this *Index) Config() *IndexConfig

type IndexConfig

type IndexConfig struct {
	TableName string
	ID        uint64
	Name      string
	Unique    bool // not used now
	Deleted   bool // not used now
}

func DecodeIndexConfig

func DecodeIndexConfig(b []byte) (*IndexConfig, error)

type Item

type Item interface {
	Key() string
	TableName() string
	Index(string) ([]interface{}, error)
	Marshal() []byte
	Unmarshal([]byte) error
}

type ItemIndexes

type ItemIndexes map[string][]byte

index name = > index key

func (*ItemIndexes) Marshal

func (this *ItemIndexes) Marshal() []byte

func (*ItemIndexes) Unmarshal

func (this *ItemIndexes) Unmarshal(data []byte) error

type IteratorOptions

type IteratorOptions struct {
	TableName string
	IndexName string
	Reverse   bool
	Update    bool
	Begin     []interface{}
	End       []interface{}
	BeforeRun func()
	Callback  func(*badger.Item) (bool, error)
}

type MultiError

type MultiError struct {
	// contains filtered or unexported fields
}

func NewMultiError

func NewMultiError() *MultiError

func (*MultiError) Add

func (this *MultiError) Add(err error)

func (*MultiError) Error

func (this *MultiError) Error() string

func (*MultiError) HasErrors

func (this *MultiError) HasErrors() bool

type Options

type Options struct {
	GCFreq   time.Duration
	SyncFreq time.Duration
}

type Table

type Table struct {
	// contains filtered or unexported fields
}

func (*Table) Close

func (this *Table) Close() error

func (*Table) Index

func (this *Table) Index(name string) *Index

type TableConfig

type TableConfig struct {
	Name    string
	DataID  uint64
	IndexID uint64
	Deleted bool
}

func DecodeTableConfig

func DecodeTableConfig(b []byte) (*TableConfig, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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