kvdb

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 11 Imported by: 1

README

Build Status

kvdb

Key value store in Golang Supports storing byte arrays with string keys. Supports concurrent write access. Has functions for serialization and deserialization to/from a file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

Database encapsulates the underlying datastore, and other related metadata. Restrictions : - The length of name should fit in 1 byte. So the maximum length is math.MaxUint8

func New

func New(name string) *Database

New creates and return a database with a given name. Returns nil if creation is not successful

func Open

func Open(filename string, create bool) (*Database, error)

Open reads in a database from disk, and creates a new one in memory and on disk if it can't find one with the supplied filename

func (*Database) Delete

func (db *Database) Delete(key string)

Delete removes a key from the database. It behaves the same way as the in build delete wherein it doesn't return anything and does nothing if the key doesn't exist

func (*Database) Export

func (db *Database) Export(filename string) (err error)

Export writes out the database to a file. This overwrites exising files and dumps the entire data into the file

func (*Database) Get

func (db *Database) Get(key string) ([]byte, *ErrorType)

Get a value for a key from the map. Return DatabaseKeyNotPresent if not in map

func (*Database) Insert

func (db *Database) Insert(key string, value []byte, overwrite bool) *ErrorType

Insert key value pair into the database. Overwrite existing value is parameter is true. No validation on the data is performed.

func (*Database) Name

func (db *Database) Name() string

Name is the getter for the database name

func (*Database) SetName

func (db *Database) SetName(name string) *ErrorType

SetName is the setter for the database name

func (*Database) ToRawMap

func (db *Database) ToRawMap() map[string][]byte

ToRawMap returns all the data as a raw map

type ErrorType

type ErrorType uint8

ErrorType defines custom error types

const (
	DatabaseNameOutOfBounds ErrorType = iota + 1
	DatabaseStateInvalid    ErrorType = iota + 1
	DatabaseKeyExists       ErrorType = iota + 1
	DatabaseKeyNotPresent   ErrorType = iota + 1
)

Custom ErrorTypes

func (*ErrorType) Error

func (err *ErrorType) Error() string

func (ErrorType) String

func (i ErrorType) String() string

Jump to

Keyboard shortcuts

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