golkeyval

package module
v0.0.0-...-14a2057 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 13 Imported by: 0

README

golkeyval

helper KeyVal integrations

extracted from an older pandora box of such packages at abhishekkr/gol

Currently provides: leveldb, badger, bitcask, sqlite3 & dumb in-mem via map

Public Functions

  • golkeyval.GetDBEngine(dbtype): to init dbengine of above types providing type via values mentioned above

  • golkeyval.Configure(cfg map[string]string): to configure DB specific fields

  • badger: mandatory is DBPath; optional are DetectConflicts:false, NumGoroutines, LogLevel:INFO
  • bitcask: mandatory is DBPath
  • leveldb: mandatory is DBPath
  • sqlite3: mandatory is DBPath; optional is TableName:golkeyval
  • golkeyval.CreateDB() to create required DB & get connection if required

  • golkeyval.CloseDB() to cleanly close DB connection

  • golkeyval.CloseAndDeleteDB() to close DB connection and purge its persistence

  • golkeyval.PushKeyVal(key string, val string) bool to push a key-val

  • golkeyval.GetVal(key string) string to fetch a val for key

  • golkeyval.DelKey(key string) bool to remove a key-val


Documentation

Index

Constants

View Source
const (
	DEBUG loggingLevel = iota
	INFO
	WARNING
	ERROR
)

Variables

View Source
var DBEngines = make(map[string]DBEngine)

DBEngines acts as map for all available db-engines.

Functions

func RegisterDBEngine

func RegisterDBEngine(name string, dbEngine DBEngine)

RegisterDBEngine gets used by adapters to register themselves.

Types

type Badger

type Badger struct {
	DBPath          string
	DetectConflicts bool
	NumGoroutines   int
	LogLevel        badger.Logger
	GolDB           *badger.DB
}

Badger struct with required badger details.

func (*Badger) CloseAndDeleteDB

func (b *Badger) CloseAndDeleteDB()

CloseAndDeleteDB closes and deletes a db given handle and DBPath. Useful in use and throw implementations. And also tests.

func (*Badger) CloseDB

func (b *Badger) CloseDB()

CloseDB closes a db given handle.

func (*Badger) Configure

func (b *Badger) Configure(cfg map[string]string)

Configure populates Badger required configs.

func (*Badger) CreateDB

func (b *Badger) CreateDB()

CreateDB creates a Badger db at provided DBPath.

func (*Badger) DelKey

func (b *Badger) DelKey(key string) bool

DelKey deletes key from provided DB handle.

func (*Badger) GetVal

func (b *Badger) GetVal(key string) string

GetVal return string-ified value of key from provided db handle.

func (*Badger) PushKeyVal

func (b *Badger) PushKeyVal(key string, val string) bool

PushKeyVal pushes key-val in provided DB handle.

type Bitcask

type Bitcask struct {
	DBPath string
	GolDB  *bitcask.Bitcask
}

Bitcask struct with required bitcask details.

func (*Bitcask) CloseAndDeleteDB

func (b *Bitcask) CloseAndDeleteDB()

CloseAndDeleteDB closes and deletes a db given handle and DBPath. Useful in use and throw implementations. And also tests.

func (*Bitcask) CloseDB

func (b *Bitcask) CloseDB()

CloseDB syncs and closes a db given handle.

func (*Bitcask) Configure

func (b *Bitcask) Configure(cfg map[string]string)

Configure populates Bitcask required configs.

func (*Bitcask) CreateDB

func (b *Bitcask) CreateDB()

CreateDB creates a bitcask directory at provided DBPath.

func (*Bitcask) DelKey

func (b *Bitcask) DelKey(key string) bool

DelKey deletes key from provided DB handle.

func (*Bitcask) GetVal

func (b *Bitcask) GetVal(key string) string

GetVal return string-ified value of key from provided db handle.

func (*Bitcask) PushKeyVal

func (b *Bitcask) PushKeyVal(key string, val string) bool

PushKeyVal pushes key-val in provided DB handle.

type DBEngine

type DBEngine interface {
	Configure(cfg map[string]string)
	CreateDB()
	CloseDB()
	CloseAndDeleteDB()
	PushKeyVal(key string, val string) bool
	GetVal(key string) string
	DelKey(key string) bool
}

DBEngine interface enables adapter feature for a key-val oriented DB.

func GetDBEngine

func GetDBEngine(name string) DBEngine

GetDBEngine gets used by client to fetch a required db-engine.

type InMem

type InMem struct {
	KeyVal map[string]string
}

func (*InMem) CloseAndDeleteDB

func (inMem *InMem) CloseAndDeleteDB()

CloseAndDeleteDB just a proxy for CloseDB here.

func (*InMem) CloseDB

func (inMem *InMem) CloseDB()

CloseDB deletes all keys from Map.

func (*InMem) Configure

func (inMem *InMem) Configure(cfg map[string]string)

Configure is for sake of interface only, placeholder.

func (*InMem) CreateDB

func (inMem *InMem) CreateDB()

CreateDB just initializes Map.

func (*InMem) DelKey

func (inMem *InMem) DelKey(key string) bool

DelKey deletes key from map.

func (*InMem) GetVal

func (inMem *InMem) GetVal(key string) string

GetVal return val for provided key in InMem map.

func (*InMem) PushKeyVal

func (inMem *InMem) PushKeyVal(key string, val string) bool

PushKeyVal pushes key-val in provided inMem map.

type LevelDB

type LevelDB struct {
	DBPath string
	GolDB  *leveldb.DB
}

LevelDB struct with required leveldb details.

func (*LevelDB) CloseAndDeleteDB

func (levelDB *LevelDB) CloseAndDeleteDB()

CloseAndDeleteDB closes and deletes a db given handle and DBPath. Useful in use and throw implementations. And also tests.

func (*LevelDB) CloseDB

func (levelDB *LevelDB) CloseDB()

CloseDB closes a db given handle.

func (*LevelDB) Configure

func (levelDB *LevelDB) Configure(cfg map[string]string)

Configure populates LevelDB required configs.

func (*LevelDB) CreateDB

func (levelDB *LevelDB) CreateDB()

CreateDB creates a leveldb db at provided DBPath.

func (*LevelDB) DelKey

func (levelDB *LevelDB) DelKey(key string) bool

DelKey deletes key from provided DB handle.

func (*LevelDB) GetVal

func (levelDB *LevelDB) GetVal(key string) string

GetVal return string-ified value of key from provided db handle.

func (*LevelDB) PushKeyVal

func (levelDB *LevelDB) PushKeyVal(key string, val string) bool

PushKeyVal pushes key-val in provided DB handle.

type Pebble

type Pebble struct {
	DBPath string
	GolDB  *pebbledb.DB
}

Pebble struct with required pebble details.

func (*Pebble) CloseAndDeleteDB

func (pbl *Pebble) CloseAndDeleteDB()

CloseAndDeleteDB closes and deletes a db given handle and DBPath. Useful in use and throw implementations. And also tests.

func (*Pebble) CloseDB

func (pbl *Pebble) CloseDB()

CloseDB closes a db given handle.

func (*Pebble) Configure

func (pbl *Pebble) Configure(cfg map[string]string)

Configure populates Pebble required configs.

func (*Pebble) CreateDB

func (pbl *Pebble) CreateDB()

CreateDB creates a pebble db at provided DBPath.

func (*Pebble) DelKey

func (pbl *Pebble) DelKey(key string) bool

DelKey deletes key from provided DB handle.

func (*Pebble) GetVal

func (pbl *Pebble) GetVal(key string) string

GetVal return string-ified value of key from provided db handle.

func (*Pebble) PushKeyVal

func (pbl *Pebble) PushKeyVal(key string, val string) bool

PushKeyVal pushes key-val in provided DB handle.

type Sqlite3DB

type Sqlite3DB struct {
	DBPath    string
	GolDB     *sql.DB
	TableName string
}

Sqlite3DB struct with sqlite3 required details.

func (*Sqlite3DB) CloseAndDeleteDB

func (sqlite3 *Sqlite3DB) CloseAndDeleteDB()

CloseAndDeleteDB closes and deletes a db given handle and DBPath. Useful in use and throw implementations. And also tests.

func (*Sqlite3DB) CloseDB

func (sqlite3 *Sqlite3DB) CloseDB()

CloseDB closes a db given handle.

func (*Sqlite3DB) Configure

func (sqlite3 *Sqlite3DB) Configure(cfg map[string]string)

Configure populates SQLite required configs.

func (*Sqlite3DB) CreateDB

func (sqlite3 *Sqlite3DB) CreateDB()

CreateDB creates a sqlite3 db at provided DBPath. It will create Table with the name provided during Configure(), so multiple key-val can be kept isolated at same db-path. Create fixed fields FieldKey and FieldValue for key-name and key-value in it.

func (*Sqlite3DB) DelKey

func (sqlite3 *Sqlite3DB) DelKey(key string) bool

DelKey deletes a key from provided DB handle.

func (*Sqlite3DB) GetVal

func (sqlite3 *Sqlite3DB) GetVal(key string) string

GetVal fetches value of key from provided db handle.

func (*Sqlite3DB) PushKeyVal

func (sqlite3 *Sqlite3DB) PushKeyVal(key string, val string) bool

PushKeyVal creates a key-val in provided DB handle.

Jump to

Keyboard shortcuts

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