db

package
v0.0.0-...-77d485b Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package db provides utilities for interacting with BadgerDB v4.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerDB

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

BadgerDB wraps a Badger DB with additional context and configuration.

func NewBadgerDB

func NewBadgerDB(ctx context.Context, opts badger.Options) (*BadgerDB, error)

NewBadgerDB creates a new BadgerDB instance with the provided Options. It defaults to using a background context if no context is provided.

Example usage:

ctx := context.Background()
db, err := NewBadgerDB(ctx, "/tmp/mydb", opts...)

func (*BadgerDB) Close

func (d *BadgerDB) Close() error

Close closes the BadgerDB.

Example usage:

err := db.Close()

func (*BadgerDB) DB

func (d *BadgerDB) DB() *badger.DB

func (*BadgerDB) Exists

func (d *BadgerDB) Exists(key string) (bool, error)

Exists checks if a key exists in the BadgerDB.

Returns a boolean indicating if the key exists and any error encountered. It returns true and nil error if the key exists, false and nil error if the key does not exist. If an error other than ErrKeyNotFound is encountered during the operation, it returns false and the error.

Example usage:

exists, err := db.Exists("myKey")

func (*BadgerDB) GarbageCollect

func (d *BadgerDB) GarbageCollect() error

GarbageCollect runs a value log garbage collection on the BadgerDB, provided the rewrite ratio is more than 0.7 (70%).

Example usage:

err := db.GarbageCollect()

func (*BadgerDB) Get

func (d *BadgerDB) Get(key string) ([]byte, error)

Get retrieves the value for a given key from the BadgerDB.

Example usage:

value, err := db.Get("myKey")

func (*BadgerDB) Write

func (d *BadgerDB) Write(ctx context.Context, key string, value []byte) error

Write sets the value for a given key in the BadgerDB.

Example usage:

err := db.Write("myKey", []byte("myValue"))

type Db

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

func NewDB

func NewDB(ctx context.Context, opts *options.Options) (*Db, error)

NewDB ... TODO: Add support for multiple dialects... For now only Sqlite3

func (*Db) GetDB

func (d *Db) GetDB() *sql.DB

func (*Db) GetDatasource

func (d *Db) GetDatasource() string

func (*Db) GetDialect

func (d *Db) GetDialect() string

func (*Db) GetGoqu

func (d *Db) GetGoqu() *goqu.Database

Jump to

Keyboard shortcuts

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