# README

aws-sdk-go-v2-wrapper | DynamoDB

Quick Usage

import (
	"context"

	"github.com/evalphobia/aws-sdk-go-v2-wrapper/config"
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/dynamodb"
)

func main() {
	svc, err := dynamodb.New(config.Config{
		AccessKey: "<...>",
		SecretKey: "<...>",
	})
	if err != nil {
		panic(err)
	}

	ctx := context.Background()

	item, err := svc.GetSingleItem(ctx, dynamodb.XGetSingleItem{
		TableName:     "users",
		HashKeyName:   "user_id",
		HashKeyValue:  101,
		RangeKeyName:  "session_id",
		RangeKeyValue: "sess-abcdefg123456",
	})
	if err != nil {
		panic(err)
	}

	mm := dynamodb.ToMapValue(item)
	if mm["user_id"] != 101 {
		panic("`user_id` should be `101`")
	}
	if mm["session_id"] != "sess-abcdefg123456" {
		panic("`session_id` should be `sess-abcdefg123456`")
	}
	// ...
}

X API

NameDescription
XBatchDeleteItemsdeletes multiple items using 'BatchWriteItems'.
XDeleteTableFromNamedeletes a table.
XExistTablechecks if the table already exists or not.
XForceDeleteAlldeletes all data in the table.
XGetSingleItemgets single item.

Other Examples

PutItem

data := map[string]interface{}{
    "user_id": 101,
    "session_id": "sess-abcdefg123456",
}
m, err := dynamodb.MarshalToMap(data)
if err != nil {
    return err
}

svc.PutItem(ctx, dynamodb.PutItemRequest{
	TableName: "users",
	Item:      m,
})

Query

result, err := svc.Query(ctx, dynamodb.QueryRequest{
	TableName: "users",
	IndexName: "gsi-foobar",
	// Select: dynamodb.SelectCount,
	Limit:     1,
	XConditions: dynamodb.XConditions{
		KeyConditions: []dynamodb.XCondition{
			{
				Name:     "user_id",
				Value:    101,
				Operator: dynamodb.ComparisonOperatorEq,
			},
			{
				Name:     "session_id",
				Value:    "sess-abcdefg123456",
				Operator: dynamodb.ComparisonOperatorEq,
			},
		},
	},
})
if err != nil {
    return err
}

if result.Count != 1 {
	panic("result should be one item")
}

mm := result.ToSliceMap()
if len(mm) != 1 {
	panic("result should be one item")
}

if mm["user_id"] != 101 {
    panic("`user_id` should be `101`")
}
if mm["session_id"] != "sess-abcdefg123456" {
    panic("`session_id` should be `sess-abcdefg123456`")
}

UpdateItem

_, err = svc.UpdateItem(ctx, dynamodb.UpdateItemRequest{
	TableName: "users",
	// [WHERE user_id = 101 AND session_id = 'sess-abcdefg123456'] in SQL
	Key: map[string]dynamodb.AttributeValue{
		"user_id": dynamodb.AttributeValue{
			Number: 101,
		},
		"session_id": dynamodb.AttributeValue{
			String: "sess-abcdefg123456",
		},
	},
	ReturnValues: dynamodb.ReturnValueNone,
	XConditions: dynamodb.XConditions{
		Updates: []dynamodb.XUpdateCondition{
			// change email address
			// [UPDATE SET email = '[email protected]'] in SQL
			{
				Name:      "email",
				Value:     "[email protected]",
				Operation: dynamodb.OperationModeSET, // you can omit `set` parameter
			},
			// increment age
			// [UPDATE SET age = age + 1] in SQL
			{
				Name:      "age",
				Value:     1,
				Operation: dynamodb.OperationModeADD,
			},
		},
		// DO NOT create new item when p-key does not exist.
		Conditions: []dynamodb.XCondition{
			{
				Name:     "user_id",
				Operator: dynamodb.ComparisonOperatorAttrExists,
			},
		},
	},
})

# Functions

MarshalFromMap converts result AttributeValue to slice of map values.
MarshalToMap converts result AttributeValue to list values.
MarshalToMap converts result AttributeValue to map values.
MustNewAttributeValue creates AttributeValue from given value, or emits panic.
New returns initialized *DynamoDB.
NewAttributeValue creates AttributeValue from given value.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Unmarshal unmarshals given slice pointer sturct from DynamoDB item result to mapping.
RawUnmarshalWithTagName unmarshals given slice pointer sturct and tag name from DynamoDB item result to mapping.
ToMapValue converts result AttributeValue to map value.
ToSliceMapValues converts result AttributeValue to slice of map values.

# Constants

No description provided by the author
No description provided by the author
for expression condition.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
BatchGetItemRequest has parameters for `BatchGetItem` operation.
BatchGetItemResult contains results from `BatchGetItem` operation.
BatchWriteItemRequest has parameters for `BatchWriteItem` operation.
BatchWriteItemResult contains results from `BatchWriteItem` operation.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CreateTableRequest has parameters for `CreateTable` operation.
CreateTableResult contains results from `CreateTable` operation.
DeleteTableRequest has parameters for `DeleteTable` operation.
DeleteTableResult contains results from `DeleteTable` operation.
DescribeTableRequest has parameters for `DescribeTable` operation.
DescribeTableResult contains results from `DescribeTable` operation.
DynamoDB has DynamoDB client.
No description provided by the author
GetItemRequest has parameters for `GetItem` operation.
GetItemResult contains results from `GetItem` operation.
No description provided by the author
Represents the properties of a global secondary index.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PutItemRequest has parameters for `PutItem` operation.
PutItemResult contains results from `PutItem` operation.
QueryRequest has parameters for `Query` operation.
QueryResult contains results from `Query` operation.
No description provided by the author
No description provided by the author
No description provided by the author
ScanRequest has parameters for `Scan` operation.
ScanResult contains results from `Scan` operation.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
UpdateItemRequest has parameters for `UpdateItem` operation.
UpdateItemResult contains results from `UpdateItem` operation.
No description provided by the author
XBatchDeleteItem contains key values to delete and used in 'XBatchDeleteItemRequest'.
XBatchDeleteItemRequest is parameters of 'XBatchDeleteItems'.
XCondition contains single condition parameters.
XConditions is to build Expression Condition for Query/Scan/Update operation.
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author