plaindb

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxUpgradeAttempts is the maximum number of times a data record will attempt to be upgraded successively.
	// Used to prevent version loops. i.e. upgrading to v3 but goes v1 -> v2 -> v1 infinitely
	MaxUpgradeAttempts = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket interface {
	// Iter iterates over all values, assigning each value to 'v', then calling fn with it's ID
	Iter(v interface{}, fn func(id string) (keepGoing bool)) error
	// Get reads the record with key 'id' into 'v'
	Get(id string, v interface{}) (found bool, err error)
	// Put writes the record 'v' with key 'id'. If 'v' is nil, the record is deleted
	Put(id string, v interface{}) error
}

Bucket reads and writes records on a DB

type BucketUpgrader added in v0.8.0

type BucketUpgrader interface {
	// UpgradeAll attempts to upgrade all of data once, prior to individual item upgrades
	UpgradeAll(dataVersion string, data map[string]interface{}) (newVersion string, newData map[string]interface{}, err error)
}

BucketUpgrader is only used for schema-level upgrades to a bucket, e.g. updating the ID format. Only runs once, then bucket items are processed. For a simpler upgrade implementation, stick to just Upgrader.

type DB

type DB interface {
	io.Closer
	// Bucket returns a bucket with 'name.json' on disk, and auto-upgraded to 'version'
	Bucket(name, version string, upgrader Upgrader) (Bucket, error)
}

DB creates buckets that can read or write JSON data

func Open

func Open(path string, opts ...DBOpt) (DB, error)

Open prepares and creates a DB for the given file path

type DBOpt

type DBOpt interface {
	// contains filtered or unexported methods
}

DBOpt configures the DB built by Open

func VersionControl

func VersionControl(setRepo *vcs.Repository) DBOpt

type LegacyUpgrader

type LegacyUpgrader interface {
	Upgrader
	// ParseLegacy parses the original JSON data as a whole.
	// Deprecated: Use Parse with the version format instead.
	ParseLegacy(legacyData json.RawMessage) (version string, data map[string]json.RawMessage, err error)
}

LegacyUpgrader upgrades data from a legacy, unversioned format

type MockConfig

type MockConfig struct {
	FileReader func(path string) ([]byte, error)
	Saver      func(Bucket) error
}

MockConfig contains stubs for a full MockDB

type MockDB

type MockDB interface {
	DB
	Dump(Bucket) string
}

MockDB is a DB with additional mocking utilities

func NewMockDB

func NewMockDB(conf MockConfig) MockDB

NewMockDB creates a new DB without a backing file store, to be used in tests

type Upgrader

type Upgrader interface {
	// Parse parses the original JSON record for the given version
	Parse(dataVersion, id string, data json.RawMessage) (interface{}, error)
	// Upgrade upgrades 'data' to 'dataVersion'. May be run multiple times to incrementally upgrade the data.
	Upgrade(dataVersion, id string, data interface{}) (newVersion string, newData interface{}, err error)
}

Upgrader upgrades data to the given version

Jump to

Keyboard shortcuts

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