store

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: BSD-2-Clause Imports: 7 Imported by: 0

README

store

Documentation

Index

Constants

View Source
const (
	// DefaultStore define default store engine
	DefaultStore = "badger"
)

Variables

This section is empty.

Functions

func Register

func Register(name string, fn func(path string) (Store, error))

Register register the store engine

Types

type Badger

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

Badger badger.KV db store

func (*Badger) BatchClose

func (s *Badger) BatchClose() error

BatchClose close the db batch

func (*Badger) BatchDelete

func (s *Badger) BatchDelete(k []byte) error

BatchDelete deletes a key with batch

func (*Badger) BatchSet

func (s *Badger) BatchSet(k, v []byte) error

BatchSet sets the provided value for a given key with batch

func (*Badger) Close

func (s *Badger) Close() error

Close closes a KV. It's crucial to call it to ensure all the pending updates make their way to disk.

func (*Badger) Delete

func (s *Badger) Delete(k []byte, sync ...bool) error

Delete deletes a key. Exposing this so that user does not have to specify the Entry directly. For example, BitDelete seems internal to badger.

Use `snyc = true` set the db snyc mode

func (*Badger) ForEach

func (s *Badger) ForEach(fn func(k, v []byte) error) error

ForEach get all key and value

func (*Badger) Get

func (s *Badger) Get(k []byte) ([]byte, error)

Get looks for key and returns a value. If key is not found, value is nil.

func (*Badger) Has

func (s *Badger) Has(k []byte) (bool, error)

Has returns true if the DB does contains the given key.

func (*Badger) Len

func (s *Badger) Len() (int64, int64)

Len returns the size of lsm and value log files in bytes. It can be used to decide how often to call RunValueLogGC.

func (*Badger) NewBatch

func (s *Badger) NewBatch() error

NewBatch create a db batch

func (*Badger) Set

func (s *Badger) Set(k, v []byte, sync ...bool) error

Set sets the provided value for a given key. If key is not present, it is created. If it is present, the existing value is overwritten with the one provided.

Use `snyc = true` set the db snyc mode

func (*Badger) WALName

func (s *Badger) WALName() string

WALName is useless for this kv database

func (*Badger) Write

func (s *Badger) Write(sync ...bool) error

Write written the batch data to db

type Batch

type Batch struct {
	K, V []byte
	Kind uint8
}

Batch set db batch struct

type Bolt

type Bolt struct {
	DefPath []byte
	Arr     []Batch
	// contains filtered or unexported fields
}

Bolt bolt store struct

func (*Bolt) BatchClose

func (s *Bolt) BatchClose() error

BatchClose close the batch

func (*Bolt) BatchDelete

func (s *Bolt) BatchDelete(k []byte) error

BatchDelete delete a key in the batch

func (*Bolt) BatchSet

func (s *Bolt) BatchSet(k, v []byte) error

BatchSet add k, v to the batch

func (*Bolt) Close

func (s *Bolt) Close() error

Close releases all database resources. All transactions must be closed before closing the database.

func (*Bolt) Delete

func (s *Bolt) Delete(k []byte, sync ...bool) error

Delete deletes a key. Exposing this so that user does not have to specify the Entry directly.

func (*Bolt) ForEach

func (s *Bolt) ForEach(fn func(k, v []byte) error) error

ForEach get all key and value

func (*Bolt) Get

func (s *Bolt) Get(k []byte) (b []byte, err error)

Get executes a function within the context of a managed read-only transaction.

Any error that is returned from the function is returned from the View() method.

func (*Bolt) Has

func (s *Bolt) Has(k []byte) (bool, error)

Has returns true if the DB does contains the given key.

func (*Bolt) NewBatch

func (s *Bolt) NewBatch() error

NewBatch init the db batch

func (*Bolt) Set

func (s *Bolt) Set(k []byte, v []byte, sync ...bool) error

Set executes a function within the context of a read-write managed transaction.

func (*Bolt) WALName

func (s *Bolt) WALName() string

WALName returns the path to currently open database file.

func (*Bolt) Write

func (s *Bolt) Write(sync ...bool) error

Write write the batch data to db

type Leveldb

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

Leveldb leveldb store struct

func (*Leveldb) BatchClose

func (s *Leveldb) BatchClose() error

BatchClose close the batch

func (*Leveldb) BatchDelete

func (s *Leveldb) BatchDelete(k []byte) error

BatchDelete delete a key in the batch

func (*Leveldb) BatchSet

func (s *Leveldb) BatchSet(k, v []byte) error

BatchSet add k, v to the batch

func (*Leveldb) Close

func (s *Leveldb) Close() error

Close closes the DB. This will also releases any outstanding snapshot, abort any in-flight compaction and discard open transaction.

func (*Leveldb) Delete

func (s *Leveldb) Delete(k []byte, sync ...bool) error

Delete deletes the value for the given key. Delete will not returns error if key doesn't exist. Write merge also applies for Delete, see Write.

func (*Leveldb) ForEach

func (s *Leveldb) ForEach(fn func(k, v []byte) error) error

ForEach get all key and value

func (*Leveldb) Get

func (s *Leveldb) Get(k []byte) ([]byte, error)

Get gets the value for the given key. It returns ErrNotFound if the DB does not contains the key.

func (*Leveldb) Has

func (s *Leveldb) Has(k []byte) (bool, error)

Has returns true if the DB does contains the given key. It is safe to modify the contents of the argument after Has returns.

func (*Leveldb) Len

func (s *Leveldb) Len() (leveldb.Sizes, error)

Len calculates approximate sizes of the given key ranges. The length of the returned sizes are equal with the length of the given ranges.

func (*Leveldb) NewBatch

func (s *Leveldb) NewBatch() error

NewBatch init the db batch

func (*Leveldb) Set

func (s *Leveldb) Set(k, v []byte, sync ...bool) error

Set sets the provided value for a given key. If key is not present, it is created.

func (*Leveldb) WALName

func (s *Leveldb) WALName() string

WALName is useless for this kv database

func (*Leveldb) Write

func (s *Leveldb) Write(sync ...bool) error

Write write the batch data to db

type Store

type Store interface {
	Set(k, v []byte, sync ...bool) error
	Get(k []byte) ([]byte, error)
	Delete(k []byte, sync ...bool) error
	Has(k []byte) (bool, error)
	ForEach(fn func(k, v []byte) error) error
	Close() error
	WALName() string
	//
	NewBatch() error
	BatchSet(k, v []byte) error
	// BatchGet(k []byte) ([]byte, error)
	BatchDelete(k []byte) error
	Write(snyc ...bool) error
	BatchClose() error
}

Store is store interface

func Open

func Open(path string, args ...string) (Store, error)

Open open the store engine

func OpenBadger

func OpenBadger(dbPath string) (Store, error)

OpenBadger open the Badger store

func OpenBolt

func OpenBolt(dbPath string) (Store, error)

OpenBolt open the Bolt store

func OpenLeveldb

func OpenLeveldb(dbPath string) (Store, error)

OpenLeveldb opens or creates a DB for the given store. The DB will be created if not exist, unless ErrorIfMissing is true.

Jump to

Keyboard shortcuts

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