gkvstore

package module
v0.0.0-...-e2f4fbf Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: BSD-3-Clause Imports: 3 Imported by: 11

README

gkvstore Go Go Reference Coverage Status

Generic key-value store

gkvstore is a generic KV Store interface which provides an easier interface to access underlying database. It is mainly used to abstract the database used underneath so we can have a uniform API to use for clients

Different DB adapters can be built for the Store. This allows decoupling DB code from specific implementations and ability to change DBs on the fly.

Install

gkvstore works like a regular Go module:

> go get github.com/plexsysio/gkvstore

Usage

import "github.com/plexsysio/gkvstore"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordNotFound      = errors.New("record not found")
	ErrRecordAlreadyExists = errors.New("record already exists")
)

Functions

This section is empty.

Types

type Factory

type Factory func() Item

Factory interface provides a way to construct the object while returning results in the list method

type IDSetter

type IDSetter interface {
	SetID(string)
}

IDSetter interface can be used by the DB to provide new IDs for objects. If Item supports this, when we Create the new item we can set a unique ID based on different DB implementations

type Item

type Item interface {
	Serializable

	GetNamespace() string
	GetID() string
}

Item is a generic object which can be used to interact with the store. Users can create their own 'Item' for using the store

type ItemFilter

type ItemFilter interface {
	Compare(Item) bool
}

type ListOpt

type ListOpt struct {
	Page    int64
	Limit   int64
	Sort    Sort
	Version int64
	Filter  ItemFilter
}

ListOpt provides different options for querying the DB Pagination can be used if supported by underlying DB

type Result

type Result struct {
	Val Item
	Err error
}

Result contains result of a single result in a list operation

type Serializable

type Serializable interface {
	Marshal() ([]byte, error)
	Unmarshal([]byte) error
}

Serializable interface for the Items to store/retrieve data to/from DB as bytes

type Sort

type Sort int

Sort is an enum for using different sorting methods on the query

const (
	// SortNatural use natural order
	SortNatural Sort = iota
	// SortCreatedDesc created newest to oldest
	SortCreatedDesc
	// SortCreatedAsc created oldest to newset
	SortCreatedAsc
	// SortUpdatedDesc updated newest to oldest
	SortUpdatedDesc
	// SortUpdatedAsc updated oldest to newset
	SortUpdatedAsc
)

type Store

type Store interface {
	Create(context.Context, Item) error
	Read(context.Context, Item) error
	Update(context.Context, Item) error
	Delete(context.Context, Item) error
	List(context.Context, Factory, ListOpt) (<-chan *Result, error)

	io.Closer
}

Store is a generic KV Store interface which provides an easier interface to access underlying database. It is mainly used to abstract the database used underneath so we can have a uniform API to use for clients

type TimeTracker

type TimeTracker interface {
	SetCreated(t int64)
	GetCreated() int64
	SetUpdated(t int64)
	GetUpdated() int64
}

TimeTracker interface implements basic time tracking functionality for the objects. If Item supports this interface, additional indexes can be maintained to support queries based on this

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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