dbadger

package module
v0.0.0-...-7cbb447 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

DBadger

DBadger is a library for distributing badger KV stores across multiple concurrent services trying to access the data. It is designed to provide consistency for persistent KV data in a cost-friendly way.

Installation

go get github.com/Jameslikestea/d-badger

Usage

See Examples for a showcase of some of the configurations this library supports.

package main

import (
	"log"

	dbadger "github.com/Jameslikestea/d-badger"
	clientv3 "go.etcd.io/etcd/client/v3"
)

func main() {
	c, err := clientv3.NewFromURLs([]string{"localhost:2379"})
	if err != nil {
		log.Fatalf("Cannot Connect To ETCD: %v", err)
	}

	config := dbadger.New()
	config.WithOpts(dbadger.WithETCDLock(c), dbadger.WithDiskProvider("./test_lock"))

	d, err := config.GetDB("db1")
	if err != nil {
		log.Fatalf("Cannot get dbadger: %v", err)
	}
	defer d.Close()

	b := d.Badger()
	txn := b.NewTransaction(true)
	txn.Set([]byte("hello"), []byte("world"))
	txn.Commit()
}

License

Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Persistence persistence.Provider
	Lock        lock.Manager
	Badger      *badger.Badger
}

func New

func New() *Config

func (*Config) GetDB

func (c *Config) GetDB(name string) (*Connection, error)

func (*Config) WithOpts

func (c *Config) WithOpts(opts ...Opt)

type Connection

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

func (*Connection) Badger

func (c *Connection) Badger() *badger.DB

func (*Connection) Close

func (c *Connection) Close() error

type Opt

type Opt func(*Config)

func WithDiskProvider

func WithDiskProvider(path string) Opt

func WithETCDLock

func WithETCDLock(client *clientv3.Client) Opt

func WithS3Provider

func WithS3Provider(s *session.Session, bucket, prefix string) Opt

func WithTempDirectory

func WithTempDirectory(path string) Opt

Directories

Path Synopsis
dbs
examples
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
mocks
Package mock_persistence is a generated GoMock package.
Package mock_persistence is a generated GoMock package.
s3
s3/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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