memdb

package
v0.0.67 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0, NCSA Imports: 7 Imported by: 0

Documentation

Overview

Package memdb implements kcd.ReadWriter with an in-memory representation, suitable for testing or ephemeral service-based collections.

Index

Constants

View Source
const (
	RevisionKey   = "revision"
	CorpusKey     = "corpus"
	UnitCorpusKey = "unit_corpus"
	OutputKey     = "output"
	LanguageKey   = "language"
	TargetKey     = "target"
	SourceKey     = "source"
)

String tags for index keys matching the fields of a kcd.FindFilter.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	Rev   []kcd.Revision
	Unit  map[string]Unit   // :: unit digest → compilation record
	File  map[string]string // :: file digest → file content
	Index map[string]Index  // :: unit digest → index entries
}

DB implements kcd.Reader, and *DB implements kcd.ReadWriter and kcd.Deleter. Records are stored in exported fields, to assist in testing. The zero value is ready for use as an empty database.

func (*DB) DeleteFile

func (db *DB) DeleteFile(_ context.Context, fileDigest string) error

DeleteFile implements a method of kcd.Deleter.

func (*DB) DeleteRevision

func (db *DB) DeleteRevision(_ context.Context, revision, corpus string) error

DeleteRevision implements a method of kcd.Deleter.

func (*DB) DeleteUnit

func (db *DB) DeleteUnit(_ context.Context, unitDigest string) error

DeleteUnit implements a method of kcd.Deleter.

func (DB) Files

func (db DB) Files(_ context.Context, fileDigests []string, f func(string, []byte) error) error

Files implements a method of kcd.Reader.

func (DB) FilesExist

func (db DB) FilesExist(_ context.Context, fileDigests []string, f func(string) error) error

FilesExist implements a method of kcd.Reader.

func (DB) Find

func (db DB) Find(_ context.Context, filter *kcd.FindFilter, f func(string) error) error

Find implements a method of kcd.Reader.

func (DB) Revisions

func (db DB) Revisions(_ context.Context, want *kcd.RevisionsFilter, f func(kcd.Revision) error) error

Revisions implements a method of kcd.Reader.

func (*DB) SetIndex

func (db *DB) SetIndex(digest, key, value string)

SetIndex sets an index term for the given digest.

func (DB) Units

func (db DB) Units(_ context.Context, unitDigests []string, f func(digest, key string, data []byte) error) error

Units implements a method of kcd.Reader.

func (*DB) WriteFile

func (db *DB) WriteFile(_ context.Context, r io.Reader) (string, error)

WriteFile implements a method of kcd.Writer.

func (*DB) WriteRevision

func (db *DB) WriteRevision(_ context.Context, rev kcd.Revision, replace bool) error

WriteRevision implements a method of kcd.Writer.

func (*DB) WriteUnit

func (db *DB) WriteUnit(_ context.Context, rev kcd.Revision, formatKey string, unit kcd.Unit) (string, error)

WriteUnit implements a method of kcd.Writer. On success, the returned digest is the kcd.HexDigest of whatever unit.MarshalBinary returned.

type Index

type Index map[string][]string

An Index is a mapping from index keys (e.g., "corpus", "source") to distinct values for those keys.

type Unit

type Unit struct {
	FormatKey string // may be empty
	Data      []byte // the raw data in wire format
}

A Unit represents a stored compilation unit.

Jump to

Keyboard shortcuts

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