dynamo

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: MIT Imports: 4 Imported by: 0

README

go-dynamo

A utility library for interacting with DynamoDB in AWS SDK v2.

Supports marshaling of JSON-serializable types to/from DynamoDB String attributes.

Example

package main

import (
	"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
	"github.com/josephvusich/go-dynamo"
)

type Nested struct {
	String string
}

type JSONRecord struct {
	Number int
	Blob   dynamo.JSON[Nested]
}

type MapRecord struct {
	Number int
	Blob   Nested
}

func main() {
	jsonRecord := &JSONRecord{Number: -1}
	jsonRecord.Blob.Value = Nested{"Hello World"}
	
	attributevalue.MarshalMap(jsonRecord)
	// Output record represented as DynamoDB JSON:
	// {
	//   "Number": { "N": "-1" },
	//   "Blob":   { "S": "{\"String\":\"Hello World\"}" }
	// }
	
	mapRecord := &MapRecord{Number: -1}
	mapRecord.Blob = Nested{"Hello World"}
	
	attributevalue.MarshalMap(mapRecord)
	// Output record represented as DynamoDB JSON:
	// {
	//   "Number": { "N": "-1" },
	//   "Blob":   { "M": {
	//     "String": { "S": "Hello World" }
	//   }}
	// }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSON

type JSON[T any] struct{ Value T }

func (JSON[T]) MarshalDynamoDBAttributeValue

func (j JSON[T]) MarshalDynamoDBAttributeValue() (types.AttributeValue, error)

func (*JSON[T]) UnmarshalDynamoDBAttributeValue

func (j *JSON[T]) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error

Jump to

Keyboard shortcuts

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