badger

package module
v0.0.1-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2021 License: MIT Imports: 15 Imported by: 0

README

go-ds-badger

DAOT Labs' fork of textileio/go-ds-badger3.

standard-readme compliant go.dev reference GitHub action

Datastore implementation using badger as backend.

This fork adds support for bytes-backed keys in addition to original string-backed keys, which could improve performance in some cases by preventing type conversion and reducing key size.

Lead Maintainer

Nex

Table of Contents

Documentation

See godoc.

Contribute

Feel free to join in. All welcome. Open an issue!

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("datastore closed")

Functions

This section is empty.

Types

type Datastore

type Datastore struct {
	DB *badger.DB
	// contains filtered or unexported fields
}

func NewDatastore

func NewDatastore(path string, ktype key.KeyType, options *Options) (*Datastore, error)

NewDatastore creates a new badger datastore.

DO NOT set the Dir and/or ValuePath fields of opt, they will be set for you.

func (*Datastore) Batch

func (d *Datastore) Batch(ctx context.Context) (ds.Batch, error)

Batch creats a new Batch object. This provides a way to do many writes, when there may be too many to fit into a single transaction.

func (*Datastore) Close

func (d *Datastore) Close() error

func (*Datastore) CollectGarbage

func (d *Datastore) CollectGarbage(ctx context.Context) (err error)

func (*Datastore) Delete

func (d *Datastore) Delete(ctx context.Context, key key.Key) error

func (*Datastore) DiskUsage

func (d *Datastore) DiskUsage() (uint64, error)

DiskUsage implements the PersistentDatastore interface. It returns the sum of lsm and value log files sizes in bytes.

func (*Datastore) Get

func (d *Datastore) Get(ctx context.Context, key key.Key) (value []byte, err error)

func (*Datastore) GetExpiration

func (d *Datastore) GetExpiration(ctx context.Context, key key.Key) (time.Time, error)

func (*Datastore) GetSize

func (d *Datastore) GetSize(ctx context.Context, key key.Key) (size int, err error)

func (*Datastore) Has

func (d *Datastore) Has(ctx context.Context, key key.Key) (bool, error)

func (*Datastore) NewTransaction

func (d *Datastore) NewTransaction(ctx context.Context, readOnly bool) (ds.Txn, error)

NewTransaction starts a new transaction. The resulting transaction object can be mutated without incurring changes to the underlying Datastore until the transaction is Committed.

func (*Datastore) NewTransactionExtended

func (d *Datastore) NewTransactionExtended(ctx context.Context, readOnly bool,
) (dsextensions.TxnExt, error)

NewTransactionExtended starts a new transaction with dsextensions capabilities. The resulting transaction object can be mutated without incurring changes to the underlying Datastore until the transaction is Committed.

func (*Datastore) Put

func (d *Datastore) Put(ctx context.Context, key key.Key, value []byte) error

func (*Datastore) PutWithTTL

func (d *Datastore) PutWithTTL(ctx context.Context, key key.Key, value []byte, ttl time.Duration) error

func (*Datastore) Query

func (d *Datastore) Query(ctx context.Context, q dsq.Query) (dsq.Results, error)

func (*Datastore) QueryExtended

func (d *Datastore) QueryExtended(ctx context.Context, q dsextensions.QueryExt) (dsq.Results, error)

func (*Datastore) SetTTL

func (d *Datastore) SetTTL(ctx context.Context, key key.Key, ttl time.Duration) error

func (*Datastore) Sync

func (d *Datastore) Sync(ctx context.Context, prefix key.Key) error

type Options

type Options struct {
	// Please refer to the Badger docs to see what this is for
	GcDiscardRatio float64

	// Interval between GC cycles
	//
	// If zero, the datastore will perform no automatic garbage collection.
	GcInterval time.Duration

	// Sleep time between rounds of a single GC cycle.
	//
	// If zero, the datastore will only perform one round of GC per
	// GcInterval.
	GcSleep time.Duration

	badger.Options
}

Options are the badger datastore options, reexported here for convenience.

var DefaultOptions Options

DefaultOptions are the default options for the badger datastore.

Jump to

Keyboard shortcuts

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