dynamodbav

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 3 Imported by: 0

README

Go Reference

dynamodbav - DynamoDB Marshal/Unmarshal utilities

Intended as a complement to the official AWS SDK V2 for Go, this micro library provides marshal/unmarshal helpers using Go 1.18+ generics to reduce boilerplate.

As an example, here is how the following code using the SDK may be simplified using this package:

    // Using SDK directly
    result := new(MyType)

    if err := attributevalue.UnmarshalMap(item, result); err != nil {
        return nil, err
    }

    return result, nil

    // Using this package, reduce 5 lines of code to 1:
    return dynamodbav.UnmarshalItem[MyType](item)

Documentation

Overview

Package dynamodbav provides Marshal/Unmarshal utilities for DynamoDB, intended to complement the AWS Go SDK V2 github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalItem

func MarshalItem(v interface{}) (map[string]types.AttributeValue, error)

MarshalItem marshals a generic type into its DB representation. This function is just a simple wrapper around attributevalue.MarshalMap() but is included for completeness.

func MarshalList

func MarshalList[T any](vals []T) ([]map[string]types.AttributeValue, error)

MarshalList marshals a list of values into a list of their DB representations.

func UnmarshalItem

func UnmarshalItem[T any](item map[string]types.AttributeValue) (*T, error)

UnmarshalItem unmarshals a value from its DB represenations. The type to return must be specified as a generic parameter, for example:

val, err := dynamodbav.UnmarshalItem[MyType](out.Item)

func UnmarshalList

func UnmarshalList[T any](items []map[string]types.AttributeValue) ([]T, error)

UnmarshalList unmarshals a list of values from their DB representations. The type to return must be specified as a generic parameter, for example:

vals, err := dynamodbav.UnmarshalList[MyType](out.Items)

Types

This section is empty.

Jump to

Keyboard shortcuts

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