versioned

package
v4.6.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: BSD-2-Clause, BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const PrefixSeparator = "/"

Variables

This section is empty.

Functions

func MakePartnerPrefix

func MakePartnerPrefix(id *id.ID) string

MakePartnerPrefix creates a string prefix to denote who a conversation or relationship is with

Types

type KV

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

KV stores versioned data and Upgrade functions

func NewKV

func NewKV(data ekv.KeyValue) *KV

Create a versioned key/value store backed by something implementing KeyValue

func (*KV) Delete

func (v *KV) Delete(key string, version uint64) error

delete removes a given key from the data store

func (*KV) Exists

func (v *KV) Exists(err error) bool

Exists returns false if the error indicates the element doesn't exist.

func (*KV) Get

func (v *KV) Get(key string, version uint64) (*Object, error)

Get gets and upgrades data stored in the key/value store Make sure to inspect the version returned in the versioned object

func (*KV) GetAndUpgrade

func (v *KV) GetAndUpgrade(key string, ut UpgradeTable) (*Object, error)

Get gets and upgrades data stored in the key/value store Make sure to inspect the version returned in the versioned object

func (*KV) GetFullKey

func (v *KV) GetFullKey(key string, version uint64) string

Returns the key with all prefixes appended

func (*KV) GetPrefix

func (v *KV) GetPrefix() string

GetPrefix returns the prefix of the KV.

func (*KV) IsMemStore

func (v *KV) IsMemStore() bool

func (*KV) Prefix

func (v *KV) Prefix(prefix string) *KV

Returns a new KV with the new prefix

func (*KV) Set

func (v *KV) Set(key string, object *Object) error

Set upserts new data into the storage When calling this, you are responsible for prefixing the key with the correct type optionally unique id! Call MakeKeyWithPrefix() to do so. The Object should contain the versioning if you are maintaining such a functionality.

type Object

type Object struct {
	// Used to determine version Upgrade, if any
	Version uint64

	// Set when this object is written
	Timestamp time.Time

	// Serialized version of original object
	Data []byte
}

Object is used by VersionedKeyValue to keep track of versioning and time of storage

func (*Object) Marshal

func (v *Object) Marshal() []byte

Marshal serializes a Object into a byte slice. It's used to make these storable in a KeyValue. Object exports all fields and they have simple types, so json.Marshal works fine.

func (*Object) Unmarshal

func (v *Object) Unmarshal(data []byte) error

Unmarshal deserializes a Object from a byte slice. It's used to make these storable in a KeyValue. Object exports all fields and they have simple types, so json.Unmarshal works fine.

type Upgrade

type Upgrade func(oldObject *Object) (*Object,
	error)

Upgrade functions must be of this type

type UpgradeTable

type UpgradeTable struct {
	CurrentVersion uint64
	Table          []Upgrade
}

Jump to

Keyboard shortcuts

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