ormkv

package
v1.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry interface {
	fmt.Stringer

	// GetTableName returns the table-name (equivalent to the fully-qualified
	// proto message name) this entry corresponds to.
	GetTableName() protoreflect.FullName
	// contains filtered or unexported methods
}

Entry defines a logical representation of a kv-store entry for ORM instances.

type EntryCodec

type EntryCodec interface {
	// DecodeEntry decodes a kv-pair into an Entry.
	DecodeEntry(k, v []byte) (Entry, error)

	// EncodeEntry encodes an entry into a kv-pair.
	EncodeEntry(entry Entry) (k, v []byte, err error)
}

EntryCodec defines an interfaces for decoding and encoding entries in the kv-store backing an ORM instance. EntryCodec's enable full logical decoding of ORM data.

type IndexCodec

type IndexCodec interface {
	EntryCodec

	// MessageType returns the message type this index codec applies to.
	MessageType() protoreflect.MessageType

	// GetFieldNames returns the field names in the key of this index.
	GetFieldNames() []protoreflect.Name

	// DecodeIndexKey decodes a kv-pair into index-fields and primary-key field
	// values. These fields may or may not overlap depending on the index.
	DecodeIndexKey(k, v []byte) (indexFields, primaryKey []protoreflect.Value, err error)

	// EncodeKVFromMessage encodes a kv-pair for the index from a message.
	EncodeKVFromMessage(message protoreflect.Message) (k, v []byte, err error)

	// CompareKeys compares the provided values which must correspond to the
	// fields in this key. Prefix keys of different lengths are supported but the
	// function will panic if either array is too long. A negative value is returned
	// if values1 is less than values2, 0 is returned if the two arrays are equal,
	// and a positive value is returned if values2 is greater.
	CompareKeys(key1, key2 []protoreflect.Value) int

	// EncodeKeyFromMessage encodes the key part of this index and returns both
	// index values and encoded key.
	EncodeKeyFromMessage(message protoreflect.Message) (keyValues []protoreflect.Value, key []byte, err error)

	// IsFullyOrdered returns true if all fields in the key are also ordered.
	IsFullyOrdered() bool
}

IndexCodec defines an interfaces for encoding and decoding index-keys in the kv-store.

type IndexKeyCodec

type IndexKeyCodec struct {
	*KeyCodec
	// contains filtered or unexported fields
}

IndexKeyCodec is the codec for (non-unique) index keys.

func NewIndexKeyCodec

func NewIndexKeyCodec(prefix []byte, messageType protoreflect.MessageType, indexFields, primaryKeyFields []protoreflect.Name) (*IndexKeyCodec, error)

NewIndexKeyCodec creates a new IndexKeyCodec with an optional prefix for the provided message descriptor, index and primary key fields.

func (IndexKeyCodec) DecodeEntry

func (cdc IndexKeyCodec) DecodeEntry(k, v []byte) (Entry, error)

func (IndexKeyCodec) DecodeIndexKey

func (cdc IndexKeyCodec) DecodeIndexKey(k, _ []byte) (indexFields, primaryKey []protoreflect.Value, err error)

func (IndexKeyCodec) EncodeEntry

func (cdc IndexKeyCodec) EncodeEntry(entry Entry) (k, v []byte, err error)

func (IndexKeyCodec) EncodeKVFromMessage

func (cdc IndexKeyCodec) EncodeKVFromMessage(message protoreflect.Message) (k, v []byte, err error)

type IndexKeyEntry

type IndexKeyEntry struct {
	// TableName is the table this entry represents.
	TableName protoreflect.FullName

	// Fields are the index fields this entry represents.
	Fields []protoreflect.Name

	// IsUnique indicates whether this index is unique or not.
	IsUnique bool

	// IndexValues represent the index values.
	IndexValues []protoreflect.Value

	// PrimaryKey represents the primary key values, it is empty if this is a
	// prefix key
	PrimaryKey []protoreflect.Value
}

IndexKeyEntry represents a logically decoded index entry.

func (*IndexKeyEntry) GetTableName

func (i *IndexKeyEntry) GetTableName() protoreflect.FullName

func (*IndexKeyEntry) String

func (i *IndexKeyEntry) String() string

type KeyCodec

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

func NewKeyCodec

func NewKeyCodec(prefix []byte, messageType protoreflect.MessageType, fieldNames []protoreflect.Name) (*KeyCodec, error)

NewKeyCodec returns a new KeyCodec with an optional prefix for the provided message descriptor and fields.

func (KeyCodec) CheckValidRangeIterationKeys

func (cdc KeyCodec) CheckValidRangeIterationKeys(start, end []protoreflect.Value) error

CheckValidRangeIterationKeys checks if the start and end key prefixes are valid for range iteration meaning that for each non-equal field in the prefixes those field types support ordered iteration. If start or end is longer than the other, the omitted values will function as the minimum and maximum values of that type respectively.

func (*KeyCodec) CompareKeys

func (cdc *KeyCodec) CompareKeys(values1, values2 []protoreflect.Value) int

CompareKeys compares the provided values which must correspond to the fields in this key. Prefix keys of different lengths are supported but the function will panic if either array is too long. A negative value is returned if values1 is less than values2, 0 is returned if the two arrays are equal, and a positive value is returned if values2 is greater.

func (KeyCodec) ComputeKeyBufferSize

func (cdc KeyCodec) ComputeKeyBufferSize(values []protoreflect.Value) (int, error)

ComputeKeyBufferSize computes the required buffer size for the provided values which can represent a full or prefix key.

func (*KeyCodec) DecodeKey

func (cdc *KeyCodec) DecodeKey(r *bytes.Reader) ([]protoreflect.Value, error)

DecodeKey decodes the values in the key specified by the reader. If the provided key is a prefix key, the values that could be decoded will be returned with io.EOF as the error.

func (*KeyCodec) EncodeKey

func (cdc *KeyCodec) EncodeKey(values []protoreflect.Value) ([]byte, error)

EncodeKey encodes the values assuming that they correspond to the fields specified for the key. If the array of values is shorter than the number of fields in the key, a partial "prefix" key will be encoded which can be used for constructing a prefix iterator.

func (*KeyCodec) EncodeKeyFromMessage

func (cdc *KeyCodec) EncodeKeyFromMessage(message protoreflect.Message) ([]protoreflect.Value, []byte, error)

EncodeKeyFromMessage combines GetKeyValues and EncodeKey.

func (*KeyCodec) GetFieldDescriptors

func (cdc *KeyCodec) GetFieldDescriptors() []protoreflect.FieldDescriptor

GetFieldDescriptors returns the field descriptors for this codec.

func (*KeyCodec) GetFieldNames

func (cdc *KeyCodec) GetFieldNames() []protoreflect.Name

GetFieldNames returns the field names for this codec.

func (*KeyCodec) GetKeyValues

func (cdc *KeyCodec) GetKeyValues(message protoreflect.Message) []protoreflect.Value

GetKeyValues extracts the values specified by the key fields from the message.

func (*KeyCodec) IsFullyOrdered

func (cdc *KeyCodec) IsFullyOrdered() bool

IsFullyOrdered returns true if all fields are also ordered.

func (*KeyCodec) MessageType

func (cdc *KeyCodec) MessageType() protoreflect.MessageType

MessageType returns the message type of fields in this key.

func (*KeyCodec) Prefix

func (cdc *KeyCodec) Prefix() []byte

Prefix returns the prefix applied to keys in this codec before any field values are encoded.

func (*KeyCodec) SetKeyValues

func (cdc *KeyCodec) SetKeyValues(message protoreflect.Message, values []protoreflect.Value)

SetKeyValues sets the provided values on the message which must correspond exactly to the field descriptors for this key. Prefix keys aren't supported.

type PrimaryKeyCodec

type PrimaryKeyCodec struct {
	*KeyCodec
	// contains filtered or unexported fields
}

PrimaryKeyCodec is the codec for primary keys.

func NewPrimaryKeyCodec

func NewPrimaryKeyCodec(prefix []byte, msgType protoreflect.MessageType, fieldNames []protoreflect.Name, unmarshalOptions proto.UnmarshalOptions) (*PrimaryKeyCodec, error)

NewPrimaryKeyCodec creates a new PrimaryKeyCodec for the provided msg and fields, with an optional prefix and unmarshal options.

func (*PrimaryKeyCodec) ClearValues

func (p *PrimaryKeyCodec) ClearValues(message protoreflect.Message)

func (PrimaryKeyCodec) DecodeEntry

func (p PrimaryKeyCodec) DecodeEntry(k, v []byte) (Entry, error)

func (PrimaryKeyCodec) DecodeIndexKey

func (p PrimaryKeyCodec) DecodeIndexKey(k, _ []byte) (indexFields, primaryKey []protoreflect.Value, err error)

func (PrimaryKeyCodec) EncodeEntry

func (p PrimaryKeyCodec) EncodeEntry(entry Entry) (k, v []byte, err error)

func (PrimaryKeyCodec) EncodeKVFromMessage

func (p PrimaryKeyCodec) EncodeKVFromMessage(message protoreflect.Message) (k, v []byte, err error)

func (*PrimaryKeyCodec) Unmarshal

func (p *PrimaryKeyCodec) Unmarshal(key []protoreflect.Value, value []byte, message proto.Message) error

type PrimaryKeyEntry

type PrimaryKeyEntry struct {
	// TableName is the table this entry represents.
	TableName protoreflect.FullName

	// Key represents the primary key values.
	Key []protoreflect.Value

	// Value represents the message stored under the primary key.
	Value proto.Message
}

PrimaryKeyEntry represents a logically decoded primary-key entry.

func (*PrimaryKeyEntry) GetTableName

func (p *PrimaryKeyEntry) GetTableName() protoreflect.FullName

func (*PrimaryKeyEntry) String

func (p *PrimaryKeyEntry) String() string

type SeqCodec

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

SeqCodec is the codec for auto-incrementing uint64 primary key sequences.

func NewSeqCodec

func NewSeqCodec(messageType protoreflect.MessageType, prefix []byte) *SeqCodec

NewSeqCodec creates a new SeqCodec.

func (SeqCodec) DecodeEntry

func (s SeqCodec) DecodeEntry(k, v []byte) (Entry, error)

func (SeqCodec) DecodeValue

func (s SeqCodec) DecodeValue(v []byte) (uint64, error)

func (SeqCodec) EncodeEntry

func (s SeqCodec) EncodeEntry(entry Entry) (k, v []byte, err error)

func (SeqCodec) EncodeValue

func (s SeqCodec) EncodeValue(seq uint64) (v []byte)

func (SeqCodec) Prefix

func (s SeqCodec) Prefix() []byte

type SeqEntry

type SeqEntry struct {
	// TableName is the table this entry represents.
	TableName protoreflect.FullName

	// Value is the uint64 value stored for this sequence.
	Value uint64
}

SeqEntry represents a sequence for tables with auto-incrementing primary keys.

func (*SeqEntry) GetTableName

func (s *SeqEntry) GetTableName() protoreflect.FullName

func (*SeqEntry) String

func (s *SeqEntry) String() string

type UniqueKeyCodec

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

UniqueKeyCodec is the codec for unique indexes.

func NewUniqueKeyCodec

func NewUniqueKeyCodec(prefix []byte, messageType protoreflect.MessageType, indexFields, primaryKeyFields []protoreflect.Name) (*UniqueKeyCodec, error)

NewUniqueKeyCodec creates a new UniqueKeyCodec with an optional prefix for the provided message descriptor, index and primary key fields.

func (UniqueKeyCodec) CompareKeys

func (u UniqueKeyCodec) CompareKeys(key1, key2 []protoreflect.Value) int

func (UniqueKeyCodec) DecodeEntry

func (u UniqueKeyCodec) DecodeEntry(k, v []byte) (Entry, error)

func (UniqueKeyCodec) DecodeIndexKey

func (u UniqueKeyCodec) DecodeIndexKey(k, v []byte) (indexFields, primaryKey []protoreflect.Value, err error)

func (UniqueKeyCodec) EncodeEntry

func (u UniqueKeyCodec) EncodeEntry(entry Entry) (k, v []byte, err error)

func (UniqueKeyCodec) EncodeKVFromMessage

func (u UniqueKeyCodec) EncodeKVFromMessage(message protoreflect.Message) (k, v []byte, err error)

func (UniqueKeyCodec) EncodeKeyFromMessage

func (u UniqueKeyCodec) EncodeKeyFromMessage(message protoreflect.Message) (keyValues []protoreflect.Value, key []byte, err error)

func (UniqueKeyCodec) GetFieldNames

func (u UniqueKeyCodec) GetFieldNames() []protoreflect.Name

func (UniqueKeyCodec) GetKeyCodec

func (u UniqueKeyCodec) GetKeyCodec() *KeyCodec

func (UniqueKeyCodec) GetValueCodec

func (u UniqueKeyCodec) GetValueCodec() *KeyCodec

func (UniqueKeyCodec) IsFullyOrdered

func (u UniqueKeyCodec) IsFullyOrdered() bool

func (UniqueKeyCodec) MessageType

func (u UniqueKeyCodec) MessageType() protoreflect.MessageType

Jump to

Keyboard shortcuts

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