store

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: MIT Imports: 1 Imported by: 0

README

ss-store

Generic KV Store interface

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

Install

ss-store works like a regular Go module:

> go get github.com/StreamSpace/ss-store

Usage

import "github.com/StreamSpace/ss-store"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 {
	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 Items

type Items []Item

Items stands for list of items. Used by the list operation

type ListOpt

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

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

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(Item) error
	Read(Item) error
	Update(Item) error
	Delete(Item) error
	List(Items, ListOpt) (int, 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

Jump to

Keyboard shortcuts

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