ddb

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: 14 Imported by: 0

Documentation

Overview

Package ddb provides DynamoDB utility for Protobuf messages

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedEmbedEncoding is returned when a unsupported embed encoding is used
	ErrUnsupportedEmbedEncoding = fmt.Errorf("unsupported embed encoding, supports: %s %s",
		ddbv1.Encoding_ENCODING_JSON, ddbv1.Encoding_ENCODING_DYNAMO)
)

Functions

func BoolMapKey added in v0.2.0

func BoolMapKey(s string) (bool, error)

BoolMapKey parses 's' as a boolean 'true' or 'false' value

func IntMapKey added in v0.2.0

func IntMapKey[K ~int32 | ~int64](s string) (K, error)

IntMapKey parses 's' as a signed integer value

func Marshal added in v0.2.0

func Marshal(in any, os ...Option) (types.AttributeValue, error)

Marshal will marshal basic types, and composite types that only hold basic types. It defers to the offical AWS sdk but is still put here to make it easier to change behaviour in the future.

func MarshalMappedMessage added in v0.2.0

func MarshalMappedMessage[K comparable, T any, TP ProtoMessage[T]](x map[K]TP, os ...Option) (types.AttributeValue, error)

MarshalMappedMessage takes a map of messages and marshals it to a dynamodb representation

func MarshalMessage added in v0.2.0

func MarshalMessage(x proto.Message, os ...Option) (a types.AttributeValue, err error)

MarshalMessage will marshal a protobuf message 'm' into an attribute value. It supports several well-known Protobuf types and if 'x' implements its own MarshalDynamoItem method it will be called to delegate the marshalling.

func MarshalRepeatedMessage added in v0.2.0

func MarshalRepeatedMessage[T any, TP ProtoMessage[T]](x []TP, os ...Option) (av types.AttributeValue, err error)

MarshalRepeatedMessage provides a generic function for marshalling a repeated field as long as the generated code provides the concrete type as the Type parameter.

func MarshalSet added in v0.2.0

func MarshalSet[T ~uint64 | ~uint32 | ~int32 | ~int64 | string | []byte](s []T, os ...Option) (types.AttributeValue, error)

MarshalSet will marshal a slice of 'T' to a dynamo set.

func StringMapKey added in v0.2.0

func StringMapKey(s string) (string, error)

StringMapKey parses 's' as a string map key

func UintMapKey added in v0.2.0

func UintMapKey[K ~uint32 | ~uint64](s string) (K, error)

UintMapKey parses 's' as an unsigned integer value

func Unmarshal added in v0.2.0

func Unmarshal(av types.AttributeValue, out any, os ...Option) error

Unmarshal will marshal basic types, and composite types that only hold basic types. It takes into account the embed encoding option.

func UnmarshalMappedMessage added in v0.2.0

func UnmarshalMappedMessage[K comparable, T any, TP ProtoMessage[T]](m types.AttributeValue, fv func(s string) (K, error), os ...Option) (xm map[K]TP, err error)

UnmarshalMappedMessage decodes the dynamodb representation of a map of messages

func UnmarshalMessage added in v0.2.0

func UnmarshalMessage(m types.AttributeValue, x proto.Message, os ...Option) (err error)

UnmarshalMessage will attempt to unmarshal 'm' into a protobuf message 'x'. It provides special support for several well-known protobuf message types. If 'x' implements the MarshalDynamoItem method it will be called to delegate the unmarshalling.

func UnmarshalRepeatedMessage added in v0.2.0

func UnmarshalRepeatedMessage[T any, TP ProtoMessage[T]](m types.AttributeValue, os ...Option) (xl []TP, err error)

UnmarshalRepeatedMessage provides a generic function for unmarshalling a repeated field of messages from the DynamoDB representation.

Types

type Option added in v0.2.0

type Option func(*opts)

Option configures the shared logic

func Embed added in v0.2.0

func Embed(v ddbv1.Encoding) Option

Embed option will signal to the marshalling/unmarshalling logic that the field id embedded in the Dynamo item and should be decoded.

type ProtoMessage added in v0.2.0

type ProtoMessage[T any] interface {
	proto.Message
	*T
}

ProtoMessage is a constraint to a protobuf message pointer.

Directories

Path Synopsis
Package ddbpath provides logic for building and parsing Dynamo document paths
Package ddbpath provides logic for building and parsing Dynamo document paths

Jump to

Keyboard shortcuts

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