ddb

package
v0.0.0-...-461d331 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Codec10

func Codec10[T dynamo.Thing, A, B, C, D, E, F, G, H, I, J any](a, b, c, d, e, f, g, h, i, j string) (
	CodecOf[T, A],
	CodecOf[T, B],
	CodecOf[T, C],
	CodecOf[T, D],
	CodecOf[T, E],
	CodecOf[T, F],
	CodecOf[T, G],
	CodecOf[T, H],
	CodecOf[T, I],
	CodecOf[T, J],
)

Codec10 builds Codec for 10 attributes

func Codec2

func Codec2[T dynamo.Thing, A, B any](a, b string) (
	CodecOf[T, A],
	CodecOf[T, B],
)

Codec2 builds Codec for 2 attributes

func Codec3

func Codec3[T dynamo.Thing, A, B, C any](a, b, c string) (
	CodecOf[T, A],
	CodecOf[T, B],
	CodecOf[T, C],
)

Codec4 builds Codec for 4 attributes

func Codec4

func Codec4[T dynamo.Thing, A, B, C, D any](a, b, c, d string) (
	CodecOf[T, A],
	CodecOf[T, B],
	CodecOf[T, C],
	CodecOf[T, D],
)

Codec4 builds Codec for 4 attributes

func Codec5

func Codec5[T dynamo.Thing, A, B, C, D, E any](a, b, c, d, e string) (
	CodecOf[T, A],
	CodecOf[T, B],
	CodecOf[T, C],
	CodecOf[T, D],
	CodecOf[T, E],
)

Codec5 builds Codec for 5 attributes

func Codec6

func Codec6[T dynamo.Thing, A, B, C, D, E, F any](a, b, c, d, e, f string) (
	CodecOf[T, A],
	CodecOf[T, B],
	CodecOf[T, C],
	CodecOf[T, D],
	CodecOf[T, E],
	CodecOf[T, F],
)

Codec6 builds Codec for 6 attributes

func Codec7

func Codec7[T dynamo.Thing, A, B, C, D, E, F, G any](a, b, c, d, e, f, g string) (
	CodecOf[T, A],
	CodecOf[T, B],
	CodecOf[T, C],
	CodecOf[T, D],
	CodecOf[T, E],
	CodecOf[T, F],
	CodecOf[T, G],
)

Codec7 builds Codec for 7 attributes

func Codec8

func Codec8[T dynamo.Thing, A, B, C, D, E, F, G, H any](a, b, c, d, e, f, g, h string) (
	CodecOf[T, A],
	CodecOf[T, B],
	CodecOf[T, C],
	CodecOf[T, D],
	CodecOf[T, E],
	CodecOf[T, F],
	CodecOf[T, G],
	CodecOf[T, H],
)

Codec8 builds Codec for 8 attributes

func Codec9

func Codec9[T dynamo.Thing, A, B, C, D, E, F, G, H, I any](a, b, c, d, e, f, g, h, i string) (
	CodecOf[T, A],
	CodecOf[T, B],
	CodecOf[T, C],
	CodecOf[T, D],
	CodecOf[T, E],
	CodecOf[T, F],
	CodecOf[T, G],
	CodecOf[T, H],
	CodecOf[T, I],
)

Codec9 builds Codec for 9 attributes

func Decode

func Decode(av types.AttributeValue, val interface{}, coder ...Coder) (err error)

Decode is a helper function to decode core domain types from Dynamo DB format. The helper ensures compact URI de-serialization from DynamoDB schema.

  type MyType struct {
    ID   MyComplexType
    Name MyComplexType
  }
  var ID, Name = dynamo.Codec2[MyType, MyDynamoType, MyDynamoType]("ID", "Name")

  func (x *MyType) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error {
    type tStruct *MyType
    return dynamo.Decode(av, tStruct(x),
      ID.Decode((*MyDynamoType)(&x.ID)),
			Name.Decode((*MyDynamoType)(&x.Name)),
    )
  }

func Encode

func Encode(val interface{}, coder ...Coder) (types.AttributeValue, error)

Encode is a helper function to encode core domain types into struct. The helper ensures compact URI serialization into DynamoDB schema.

  type MyType struct {
    ID   MyComplexType
    Name MyComplexType
  }
  var ID, Name = dynamo.Codec2[MyType, MyDynamoType, MyDynamoType]("ID", "Name")

  func (x MyType) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
    type tStruct MyType
    return dynamo.Encode(av, tStruct(x),
      ID.Encode(MyDynamoType(x.ID)),
			Name.Encode(MyDynamoType(x.Name)),
    )
  }

func Must

func Must[T dynamo.Thing](keyval dynamo.KeyVal[T], err error) dynamo.KeyVal[T]

func New

func New[T dynamo.Thing](
	connector string,
	service dynamo.DynamoDB,
	prefixes curie.Prefixes,
) (dynamo.KeyVal[T], error)

New creates instance of DynamoDB api

Types

type CodecOf

type CodecOf[T dynamo.Thing, A any] interface {
	Decode(*A) Coder
	Encode(A) Coder
}

CodecOf for struct fields, the type implement Encode/Decode primitives. Codec helps to implement semi-automated encoding/decoding algebraic data type into the format compatible with storage.

Let's consider scenario were application uses complex types that skips implementation of marshal/unmarshal protocols. Here the type MyComplexType needs to be casted to MyDynamoType that knows how to marshal/unmarshal the type.

type MyType struct {
  ID   MyComplexType
  Name MyComplexType
}
var ID, Name = dynamo.Codec2[MyType, MyDynamoType, MyDynamoType]("ID", "Name")

func (t MyType) MarshalDynamoDBAttributeValue() (*dynamodb.AttributeValue, error) {
  type tStruct MyType
  return dynamo.Encode(tStruct(p),
    ID.Encode(MyDynamoType(t.ID)),
    Name.Encode(MyDynamoType(t.Name)),
  )
}

func Codec1

func Codec1[T dynamo.Thing, A any](a string) CodecOf[T, A]

Codec1 builds Codec for 1 attributes

type Coder

Coder is a function, applies transformation of generic dynamodb AttributeValue

Jump to

Keyboard shortcuts

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