store

package
v0.0.0-...-ff1c243 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func RegisterStore

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

RegisterStore register store engine

Types

type Badger

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

Badger badger.KV db store

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) 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.

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) Set

func (s *Badger) Set(k, v []byte) 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.

func (*Badger) WALName

func (s *Badger) WALName() string

WALName is useless for this kv database

type Bolt

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

Bolt bolt store struct

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) 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) Set

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

Set executes a function within the context of a read-write managed transaction. If no error is returned from the function then the transaction is committed. If an error is returned then the entire transaction is rolled back. Any error that is returned from the function or returned from the commit is returned from the Update() method.

func (*Bolt) WALName

func (s *Bolt) WALName() string

WALName returns the path to currently open database file.

type Leveldb

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

Leveldb leveldb store

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) 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.

It is safe to modify the contents of the arguments after Delete returns but not before.

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.

The returned slice is its own copy, it is safe to modify the contents of the returned slice. It is safe to modify the contents of the argument after Get returns.

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. The returned sizes measure store space usage, so if the user data compresses by a factor of ten, the returned sizes will be one-tenth the size of the corresponding user data size. The results may not include the sizes of recently written data.

func (*Leveldb) Set

func (s *Leveldb) Set(k, v []byte) 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.

func (*Leveldb) WALName

func (s *Leveldb) WALName() string

WALName is useless for this kv database

type Store

type Store interface {
	// type KVBatch interface {
	Set(k, v []byte) error
	Get(k []byte) ([]byte, error)
	Delete(k []byte) error
	Has(k []byte) (bool, error)
	ForEach(fn func(k, v []byte) error) error
	Close() error
	WALName() string
}

Store is store interface

func OpenBadger

func OpenBadger(dbPath string) (Store, error)

OpenBadger open Badger store

func OpenBolt

func OpenBolt(dbPath string) (Store, error)

OpenBolt open 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. Also, if ErrorIfExist is true and the DB exist Open will returns os.ErrExist error.

func OpenStore

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

OpenStore open store engine

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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