store

package
v0.0.0-...-2cda445 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSuchEntity = fmt.Errorf("no such entity")
	ErrConflict     = fmt.Errorf("conflict")
)
View Source
var (
	ErrNoSuchIdent        = errors.New("ident does not exist")
	ErrIdentAlreadyExists = errors.New("ident already exists")
)
View Source
var ErrPropertyNotFound = errors.New("property not found")
View Source
var NullIdent = Ident{}

Functions

func TempID

func TempID() tempID

Types

type AssertMode

type AssertMode uint8
const (
	AssertModeInvalid AssertMode = iota
	AssertModeAddition
	AssertModeRetraction
	AssertModeRedaction
)

func (AssertMode) String

func (i AssertMode) String() string

type AssertResult

type AssertResult struct {
	DB      Database
	Data    []ResolvedAssertion
	TempIDs TempIDs
}

type Assertable

type Assertable interface {
	// Assertions gets zero or more assertions to submit. This method is only
	// responsible for preparing data into zero or more Assertions, not
	// resolving any IDs. This will be done within the Connection while
	// preparing a transaction.
	Assertions(conn *Connection) ([]Assertion, error)
}

type Assertion

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

Assertion represents some action (add/retract/redact) and the unresolved

func Assert

func Assert(eid any, attribute any, value any) Assertion

func Redact

func Redact(eid any, attribute any, value any) Assertion

func Retract

func Retract(eid any, attribute any, value any) Assertion

func (Assertion) Assertions

func (a Assertion) Assertions(conn *Connection) ([]Assertion, error)

Assertions implements Assertable for Assertion. This method allows an assertion to be passed directly to *Connection.Assert().

type Config

type Config struct {
	IdentManager
	IDManager
	Indexer
}

type Connection

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

Connection is the structure used to maintain

func NewConnection

func NewConnection(cfg Config) *Connection

func (*Connection) Assert

func (conn *Connection) Assert(assertables ...Assertable) (*AssertResult, error)

func (*Connection) GetEntity

func (conn *Connection) GetEntity(idResolver Resolver) (Entity, error)

func (*Connection) InitializeDB

func (conn *Connection) InitializeDB() error

InitializeDB sets up all of the required resources in the underlying storage engine for the database to which the peer is connected. It should only be called once, before transacting any data.

func (*Connection) ResolveIdents

func (conn *Connection) ResolveIdents(idents []any) (ids []Ident, err error)

ResolveIdents takes a slice of arguments, each of which may be an already-resolved ID or a string ident. It resolves the arguments to their canonical form. The resulting `ids` will be parallel to the given `idents`. This method will not allocate, and an error will be returned if any of the arguments cannot be resolved to an ident.

type Database

type Database struct {
	Basis Tx
}

Database

type EncodedTuple

type EncodedTuple []byte

Tuple is a tuple of values that are encoded together. They are typically used as keys in the database's indexes. One advantage of tuple encoding is that it allows for efficient prefix scans, as the tuple is encoded in a lexicographically sortable way. Our tuples are inspired by FoundationDB's Tuple layer. See https://apple.github.io/foundationdb/data-modeling.html#tuples and https://github.com/apple/foundationdb/blob/main/design/tuple.md for more information.

type EncodedValue

type EncodedValue []byte

EncodedValue is a value that has been encoded into a byte slice.

type Entity

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

Entity is an immutable record that contains that state of all attributes associated with a particular ID at some point in time.

func (Entity) Get

func (e Entity) Get(conn *Connection, attribute any) (Value, error)

Get ... attribute may either be a string attribute ident or a resolved ID representing the attribute to retrieve.

func (Entity) GetData

func (e Entity) GetData(conn *Connection) (EntityData, error)

func (Entity) ID

func (e Entity) ID() ID

type EntityData

type EntityData map[string]Value

func (EntityData) Assertions

func (ed EntityData) Assertions(conn *Connection) ([]Assertion, error)

Assertions implements Assertable for EntityData. This method resolves attribute idents because it needs and

type Fact

type Fact struct {
	EntityID  ID
	Attribute ID
	Value     Value
	Tx        ID
}

type ID

type ID int64

ID is an identifier that uniquely identifies an entity or ident.

const (
	// System-managed idents.
	IDID ID = -1*iota - 1
	IDIdent
	IDType
	IDCompositeComponents
	IDCardinality
	IDUnique
	IDIndexed
	IDDoc
	IDTxCommitTime

	// System-managed enumerated values.
	IDCardinalityOne
	IDCardinalityMany

	IDTypeString ID = -500 + -1*iota
	IDTypeBoolean
	IDTypeInt64
	IDTypeInt32
	IDTypeInt16
	IDTypeInt8
	IDTypeFloat64
	IDTypeFloat32
	IDTypeDecimal
	IDTypeTimestamp
	IDTypeDate
	IDTypeRef
	IDTypeBinary
	IDTypeUUID
	IDTypeULID
	IDTypeComposite
)

func (ID) Resolve

func (id ID) Resolve(conn *Connection) (ID, error)

func (ID) String

func (i ID) String() string

type IDManager

type IDManager interface {
	NextID() (ID, error)
}

type Ident

type Ident struct {
	ID   ID
	Name string
}

Ident is an ident that has been resolved such that we can access both canonical ID and string representations.

func ResolveIdent

func ResolveIdent(conn *Connection, ident any) (Ident, error)

func (Ident) MustResolve

func (ident Ident) MustResolve(conn *Connection) ID

func (Ident) Resolve

func (ident Ident) Resolve(conn *Connection) (ID, error)

func (Ident) String

func (ident Ident) String() string

type IdentManager

type IdentManager interface {
	// LoadIdents
	LoadIdents() ([]Ident, error)

	// LookupIdentIDs will return IDs for all of the names supplied. This will
	// return `ErrNoSuchIdent` if any name supplied does not represent a valid
	// ident.
	LookupIdentIDs([]string) ([]ID, error)

	// LookupIdentNames returns a list of names for the IDs supplied. This will
	// return `ErrNoSuchIdent` if any ID supplied does not represent a valid
	// ident.
	LookupIdentNames([]ID) ([]string, error)

	// StoreIdent will store the ident in the backing store. This will return
	// `ErrIdentAlreadyExists` if the ident already exists.
	StoreIdent(Ident) error
}

IdentManager controls the mapping of string idents to IDs. Each peer maintains a cache of ident mappings in memory, which it hydrates on start-up. Because the system maintains a set of well-known idents < 0, the IdentManager must guarantee that it only allocates positive idents.

type Indexer

type Indexer interface {
	Write([]ResolvedAssertion) error
	ScanEAVT(entityID ID, attribute *ID) (dataflow.Producer[Fact], error)
	ScanAEVT(attribute ID, entityID *ID) (dataflow.Producer[Fact], error)
	ScanAVET(attribute ID, val Value) (dataflow.Producer[Fact], error)
	ScanVAET(val Value, attribute *ID) (dataflow.Producer[Fact], error)
}

type Lookup

type Lookup struct {
	AttributeName string
	Value         Value
}

func NewLookup

func NewLookup(attributeName string, value Value) Lookup

func (Lookup) Resolve

func (l Lookup) Resolve(conn *Connection) (ID, error)

type ResolvedAssertion

type ResolvedAssertion struct {
	Fact
	// contains filtered or unexported fields
}

func (ResolvedAssertion) Mode

func (ra ResolvedAssertion) Mode() AssertMode

type Resolver

type Resolver interface {
	Resolve(conn *Connection) (ID, error)
}

type TempIDs

type TempIDs map[string]ID

func (TempIDs) LookupTempID

func (ids TempIDs) LookupTempID(tid tempID) (ID, bool)

type TupleHeader

type TupleHeader struct {
	Types []rtype.ConcreteType
}

type Tx

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

Tx is is a transaction entity. Transaction entities are normal entities, but they are associated with a database value as of a particular point in time, and they themselves are not associated with any other transaction.

func (Tx) ID

func (t Tx) ID() ID

ID returns the entity ID associated with the transaction.

func (Tx) Time

func (t Tx) Time() uint64

type TypeTag

type TypeTag uint8
const (
	TypeTagString TypeTag = iota
	TypeTagPosInt64
	TypeTagNegInt64
	TypeTagFloat64
	TypeTagBool
	TypeTagUUID
	TypeTagTuple
)

type TypedTuple

type TypedTuple struct {
	TupleHeader
	Values []Value
}

func NewTypedTuple

func NewTypedTuple(values ...TypedValue) TypedTuple

type TypedValue

type TypedValue struct {
	Type  rtype.ConcreteType
	Value any
}

Value is a typed value that can be stored in a database.

func (TypedValue) Encode

func (v TypedValue) Encode(w io.Writer) error

type Value

type Value any

Value is an untyped value. Typically it is used when type information is stored separately from the value (e.g. in a TupleHeader).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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