fakestore

package
v0.9.15 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package fakestore provides a fake in-mem storage. The implementation is based on the current real implementation using Datastore. See /lib/dsstore/ TODO: once we have a fake Datastore server, get rid of this.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rev

func Rev(rev int64) string

Rev gives the string value of a revision.

Types

type Data

type Data map[Key]Value

Data is the type of data items. Maps keys to their values.

type KV

type KV struct {
	K Key
	V Value
}

KV is the type of a (Key,Value) pair. Used for sorting.

type KVList

type KVList []KV

KVList is the type of list of (Key,Value) pairs. Used for sorting. Implements sort.Interface.

func (KVList) Len

func (s KVList) Len() int

Len is the number of elements in the collection.

func (KVList) Less

func (s KVList) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (KVList) Swap

func (s KVList) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type Key

type Key struct {
	Datatype string
	Realm    string
	User     string
	ID       string
	Rev      string
}

Key is the type of keys.

type State

type State struct {
	// Version is a UUID that can be used to check if Data has changed.
	Version string

	// LastCommit is the timestamp for the last commit.
	// Useful for troubleshooting.
	LastCommit time.Time

	// Date enteries.
	Data Data

	// History entries.
	History Data
}

State is the type containing the data in the store.

type Store

type Store struct {
	// Information map.
	Information map[string]string
	// State is where the data resides.
	// Any block of code that wants to access the state reads it from the chan,
	// performs its operations, and then writes it back to the chan.
	// See https://bit.ly/37ANPk4
	State chan State
}

Store is a fake in-mem store of data.

func New

func New() *Store

New creates a new Store.

func (*Store) Delete

func (s *Store) Delete(datatype, realm, user, id string, rev int64) error

Delete deletes an item.

func (*Store) DeleteTx

func (s *Store) DeleteTx(datatype, realm, user, id string, rev int64, tx storage.Tx) (ferr error)

DeleteTx deletes an item inside a transaction.

func (*Store) Exists

func (s *Store) Exists(datatype, realm, user, id string, rev int64) (_ bool, ferr error)

Exists checks if data item with given key exists.

func (*Store) Info

func (s *Store) Info() map[string]string

Info returns information about the storage.

func (*Store) LockTx

func (s *Store) LockTx(lockName string, minFrequency time.Duration, tx storage.Tx) storage.Tx

LockTx creates a lock with the give name.

func (*Store) MultiDeleteTx

func (s *Store) MultiDeleteTx(datatype, realm, user string, tx storage.Tx) (ferr error)

MultiDeleteTx deletes an item inside a transaction.

func (*Store) MultiReadTx

func (s *Store) MultiReadTx(
	datatype, realm, user, id string,
	filters [][]storage.Filter,
	offset, pageSize int,
	typ proto.Message,
	tx storage.Tx,
) (_ *storage.Results, ferr error)

MultiReadTx reads a set of items matching the input parameters and filters. Returns total count and error.

content will contain the items which

their key matches the provided datatype, realm, user (if realm/user are not "")
their value matches the provider filers

Items are sorted by their key's user and id in ascending order. The type of the item's value should be typ. Last revision of the items is used.

content's maps are keyed by user and id of the keys.

func (*Store) Read

func (s *Store) Read(datatype, realm, user, id string, rev int64, content proto.Message) error

Read reads a data item of a given key.

func (*Store) ReadHistory

func (s *Store) ReadHistory(datatype, realm, user, id string, content *[]proto.Message) error

ReadHistory reads the history of a given key.

func (*Store) ReadHistoryTx

func (s *Store) ReadHistoryTx(datatype, realm, user, id string, content *[]proto.Message, tx storage.Tx) (ferr error)

ReadHistoryTx reads the history of a given key inside a transaction.

func (*Store) ReadTx

func (s *Store) ReadTx(datatype, realm, user, id string, rev int64, content proto.Message, tx storage.Tx) (ferr error)

ReadTx reads a data item of a given key inside a transaction. Calls Read if transaction is nil.

func (*Store) Tx

func (s *Store) Tx(update bool) (storage.Tx, error)

Tx creates a new transaction.

func (*Store) Wipe

func (s *Store) Wipe(ctx context.Context, realm string, batchNum, maxEntries int) (done int, ferr error)

Wipe clears a realm.

func (*Store) Write

func (s *Store) Write(datatype, realm, user, id string, rev int64, content proto.Message, history proto.Message) error

Write writes an item.

func (*Store) WriteTx

func (s *Store) WriteTx(datatype, realm, user, id string, rev int64, content proto.Message, history proto.Message, tx storage.Tx) (ferr error)

WriteTx writes an item inside a transaction.

type Tx

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

Tx is a fake transaction.

func NewTx

func NewTx(source chan State, update bool) *Tx

NewTx creates a new transaction. update determines if the transaction is a mutation or a read-only.

func (*Tx) Finish

func (tx *Tx) Finish() error

Finish attempts to commit a transaction. Returns error if the transaction is an update, is not rolled back, and cannot be committed because of conflict.

func (*Tx) IsUpdate

func (tx *Tx) IsUpdate() bool

IsUpdate stated if the transaction is a mutation or read-only.

func (*Tx) MakeUpdate added in v0.8.8

func (tx *Tx) MakeUpdate() error

MakeUpdate will upgrade a read-only transaction to an update transaction.

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback attempts to rollback the transaction.

type Value

type Value proto.Message

Value is the type of values.

Jump to

Keyboard shortcuts

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