db

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EmptyInstanceID represents an empty InstanceID.
	EmptyInstanceID = InstanceID("")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	// Type of the action.
	Type ActionType
	// InstanceID of the instance in action.
	InstanceID InstanceID
	// CollectionName of the instance in action.
	CollectionName string
	// Previous is the instance before the action.
	Previous []byte
	// Current is the instance after the action was done.
	Current []byte
}

Action is a operation done in the collection.

type ActionType

type ActionType int

ActionType is the type used by actions done in a txn.

const (
	// Create indicates the creation of an instance in a txn.
	Create ActionType = iota
	// Save indicates the mutation of an instance in a txn.
	Save
	// Delete indicates the deletion of an instance by ID in a txn.
	Delete
)

type Event

type Event interface {
	// Time (wall-clock) the event was created.
	Time() []byte
	// InstanceID is the associated instance's unique identifier.
	InstanceID() InstanceID
	// Collection is the associated instance's collection name.
	Collection() string
	// Marshal the event to JSON.
	Marshal() ([]byte, error)
}

Event is a local or remote event generated in collection and dispatcher by Dispatcher.

type EventCodec

type EventCodec interface {
	// Reduce applies generated events into state.
	Reduce(events []Event, store ds.TxnDatastore, baseKey ds.Key, indexFunc IndexFunc) ([]ReduceAction, error)
	// Create corresponding events to be dispatched.
	Create(ops []Action) ([]Event, format.Node, error)
	// EventsFromBytes deserializes a format.Node bytes payload into Events.
	EventsFromBytes(data []byte) ([]Event, error)
}

EventCodec transforms actions generated in collections to events dispatched to thread logs, and viceversa.

type IndexFunc

type IndexFunc func(collection string, key ds.Key, oldData, newData []byte, txn ds.Txn) error

IndexFunc handles index updates.

type InstanceID

type InstanceID string

InstanceID is the type used in instance identities.

func NewInstanceID

func NewInstanceID() InstanceID

NewInstanceID generates a new identity for an instance.

func (InstanceID) String

func (e InstanceID) String() string

type ReduceAction

type ReduceAction struct {
	// Type of the reduced action.
	Type ActionType
	// Collection in which action was made.
	Collection string
	// InstanceID of the instance in reduced action.
	InstanceID InstanceID
}

Jump to

Keyboard shortcuts

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