ddbpath

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ddbpath provides logic for building and parsing Dynamo document paths

Index

Constants

This section is empty.

Variables

View Source
var NoInfo = FieldInfo{}

NoInfo is the FieldInfo zero value

Functions

func Register added in v0.2.6

func Register(nb NameBuilder, fields map[string]FieldInfo)

Register a generated name building struct with the default registry. It panics if the type is already registered.

func SelectMapValues added in v0.2.3

func SelectMapValues(v map[string]types.AttributeValue, paths ...string) (res map[string]types.AttributeValue, err error)

SelectMapValues is a convenient wrapper around SelectValues for the common scenario of selecting from map of attribute values.

func SelectValues

func SelectValues(v types.AttributeValue, paths ...string) (res map[string]types.AttributeValue, err error)

SelectValues will return a subset of a composite attribute value 'v' (maps or sets), specified by 'paths'. This is usefull when only part of a DynamoDB item is allowed or desired for an operation. For example when only the keys need to be selected, or a partial update is performed using a mask.

func Validate added in v0.2.5

func Validate(nb NameBuilder, paths ...string) error

Validate each path in 'paths' given the path naming struct 'nb' as the root message where the paths are started from agains the default registery.

Types

type AnyPath added in v0.2.6

type AnyPath struct{ expression.NameBuilder }

AnyPath is registered to support path validation into anypb structs

func (AnyPath) TypeURL added in v0.2.6

func (p AnyPath) TypeURL() expression.NameBuilder

TypeURL appends the path of the type url

func (AnyPath) Value added in v0.2.6

func (p AnyPath) Value() expression.NameBuilder

Value appends the path of the value

func (AnyPath) WithDynamoNameBuilder added in v0.2.6

func (p AnyPath) WithDynamoNameBuilder(n expression.NameBuilder) AnyPath

WithDynamoNameBuilder allows generic types to overwrite the path

type ErrFieldNotAllowed added in v0.2.6

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

func (ErrFieldNotAllowed) Error added in v0.2.6

func (e ErrFieldNotAllowed) Error() string

type ErrIndexNotAllowed added in v0.2.6

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

func (ErrIndexNotAllowed) Error added in v0.2.6

func (e ErrIndexNotAllowed) Error() string

type ErrTypeNotRegistered added in v0.2.6

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

ErrTypeNotRegistered is returned when a type is not registered in the registry being used

func (ErrTypeNotRegistered) Error added in v0.2.6

func (e ErrTypeNotRegistered) Error() string

type ErrUnknownField added in v0.2.6

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

func (ErrUnknownField) Error added in v0.2.6

func (e ErrUnknownField) Error() string

type FieldInfo added in v0.2.5

type FieldInfo struct {
	Kind    FieldKind    // list, map, basic, any etc
	Message reflect.Type // field holds a non-basic type, or nil if its a basic type
}

FieldInfo of a field on a message

func (FieldInfo) String added in v0.2.6

func (fi FieldInfo) String() string

String returns a human readable form of the field info

type FieldKind added in v0.2.6

type FieldKind int

FieldKind describes the kind of field

const (
	// FieldKindUndefined means the kind was unknown
	FieldKindUndefined FieldKind = iota
	// FiledKindSingle represents a single instance of something
	FieldKindSingle
	// FieldKindList means a list of something
	FieldKindList
	// FieldKindMap means a map of something
	FieldKindMap
)

func (FieldKind) String added in v0.2.6

func (fi FieldKind) String() string

String provides human readable form for the kind

type FieldMaskPath added in v0.2.6

type FieldMaskPath struct{ expression.NameBuilder }

FieldMaskPath is registered to support path validation of fieldmask

func (FieldMaskPath) Masks added in v0.2.6

func (p FieldMaskPath) Masks() List

Masks appends the path of the value

func (FieldMaskPath) WithDynamoNameBuilder added in v0.2.6

func (p FieldMaskPath) WithDynamoNameBuilder(n expression.NameBuilder) FieldMaskPath

WithDynamoNameBuilder allows generic types to overwrite the path

type ItemList added in v0.2.4

type ItemList[T interface {
	WithDynamoNameBuilder(expression.NameBuilder) T
}] struct{ expression.NameBuilder }

ItemList is a list of nested items

func (ItemList[T]) Index added in v0.2.4

func (p ItemList[T]) Index(i int) T

Index into a list of items

type ItemMap added in v0.2.4

type ItemMap[T interface {
	WithDynamoNameBuilder(expression.NameBuilder) T
}] struct{ expression.NameBuilder }

ItemMap is a list of nested items

func (ItemMap[T]) Key added in v0.2.4

func (p ItemMap[T]) Key(k string) T

Key into a list of items

type List added in v0.2.4

type List struct{ expression.NameBuilder }

List of basic type(s)

func (List) Index added in v0.2.4

func (p List) Index(i int) expression.NameBuilder

Index into a list of basic types

type Map added in v0.2.4

type Map struct{ expression.NameBuilder }

Map of basic type(s)

func (Map) Key added in v0.2.4

func (p Map) Key(k string) expression.NameBuilder

Key into a map of basic types

type NameBuilder added in v0.2.6

type NameBuilder interface {
	AppendName(field expression.NameBuilder) expression.NameBuilder
}

NameBuilder inteface is implemented by generated name building structs

type PathElement

type PathElement struct {
	Field string
	Index int
}

PathElement describes a part of the path. It is either an numeric index into a list (or set) or it is a string key into the field.

func AppendParsePath

func AppendParsePath(p string, r []PathElement) ([]PathElement, error)

AppendParsePath will parse path 'p' and append elements to 'r'. If 'r' is already allocated with enough space to hold all the parts of 'p' it will not allocate any additional memory on the heap.

func ParsePath

func ParsePath(p string) ([]PathElement, error)

ParsePath will parse 'p' in its elements and return them.

type Registry added in v0.2.6

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

Registry holds type information so validation of string paths can happen efficiently

func NewRegistry added in v0.2.6

func NewRegistry() Registry

NewRegistry inits an empty registry

func (Registry) FieldsOf added in v0.2.6

func (r Registry) FieldsOf(nb NameBuilder) (fi map[string]FieldInfo, ok bool)

FieldsOf returns field information of a name builder implementation

func (Registry) Register added in v0.2.6

func (r Registry) Register(nb NameBuilder, fields map[string]FieldInfo)

Register a name builder with the registry for efficient validation. It panics if the typ is already registered.

func (Registry) Traverse added in v0.2.6

func (r Registry) Traverse(nb NameBuilder, p string) (fi FieldInfo, flds map[string]FieldInfo, err error)

Traverse a message name builder 'nb' via path 'p' and return field info and any fields.

func (Registry) Validate added in v0.2.6

func (r Registry) Validate(nb NameBuilder, paths ...string) (err error)

Validate given the types in the registry

type ValuePath added in v0.2.6

type ValuePath struct{ expression.NameBuilder }

ValuePath is registered to support path validation into structpb's value fields. It has no fields but is special in that it will accept any path into it.

func (ValuePath) WithDynamoNameBuilder added in v0.2.6

func (p ValuePath) WithDynamoNameBuilder(n expression.NameBuilder) ValuePath

WithDynamoNameBuilder allows generic types to overwrite the path

Jump to

Keyboard shortcuts

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