dynamodb

package module
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

README

Valkeyrie DynamoDB

GoDoc Build Status Go Report Card

valkeyrie provides a Go native library to store metadata using Distributed Key/Value stores (or common databases).

Compatibility

A storage backend in valkeyrie implements (fully or partially) the Store interface.

Calls DynamoDB
Put 🟢️
Get 🟢️
Delete 🟢️
Exists 🟢️
Watch 🔴
WatchTree 🔴
NewLock (Lock/Unlock) 🟢️
List 🟢️
DeleteTree 🟢️
AtomicPut 🟢️
AtomicDelete 🟢️

Examples

package main

import (
	"context"
	"log"

	"github.com/kvtools/dynamodb"
	"github.com/kvtools/valkeyrie"
)

func main() {
	ctx := context.Background()

	config := &dynamodb.Config{
			Bucket: "example",
	}

	kv, err := valkeyrie.NewStore(ctx, dynamodb.StoreName, []string{"localhost:8500"}, config)
	if err != nil {
		log.Fatal("Cannot create store")
	}

	key := "foo"

	err = kv.Put(ctx, key, []byte("bar"), nil)
	if err != nil {
		log.Fatalf("Error trying to put value at key: %v", key)
	}

	pair, err := kv.Get(ctx, key, nil)
	if err != nil {
		log.Fatalf("Error trying accessing value at key: %v", key)
	}

	err = kv.Delete(ctx, key)
	if err != nil {
		log.Fatalf("Error trying to delete key %v", key)
	}

	log.Printf("value: %s", string(pair.Value))
}

Documentation

Overview

Package dynamodb contains the DynamoDB store implementation.

Index

Constants

View Source
const (
	// DefaultReadCapacityUnits default read capacity used to create table.
	DefaultReadCapacityUnits = 2
	// DefaultWriteCapacityUnits default write capacity used to create table.
	DefaultWriteCapacityUnits = 2
	// DeleteTreeTimeoutSeconds the maximum time we retry a write batch.
	DeleteTreeTimeoutSeconds = 30
)
View Source
const StoreName = "dynamodb"

StoreName the name of the store.

Variables

View Source
var (
	// ErrBucketOptionMissing is returned when bucket config option is missing.
	ErrBucketOptionMissing = errors.New("missing dynamodb bucket/table name")
	// ErrMultipleEndpointsUnsupported is returned when more than one endpoint is provided.
	ErrMultipleEndpointsUnsupported = errors.New("dynamodb only supports one endpoint")
	// ErrDeleteTreeTimeout delete batch timed out.
	ErrDeleteTreeTimeout = errors.New("delete batch timed out")
	// ErrLockAcquireCancelled stop called before lock was acquired.
	ErrLockAcquireCancelled = errors.New("stop called before lock was acquired")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Bucket           string
	Region           *string
	WssServerAddress *string
}

Config the AWS DynamoDB configuration.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store implements the store.Store interface.

func New

func New(_ context.Context, endpoints []string, options *Config) (*Store, error)

New creates a new AWS DynamoDB client.

func (*Store) AtomicDelete

func (ddb *Store) AtomicDelete(ctx context.Context, key string, previous *store.KVPair) (bool, error)

AtomicDelete delete of a single value.

func (*Store) AtomicPut

func (ddb *Store) AtomicPut(ctx context.Context, key string, value []byte, previous *store.KVPair, opts *store.WriteOptions) (bool, *store.KVPair, error)

AtomicPut Atomic CAS operation on a single value.

func (*Store) Close

func (ddb *Store) Close() error

Close nothing to see here.

func (*Store) Delete

func (ddb *Store) Delete(ctx context.Context, key string) error

Delete the value at the specified key.

func (*Store) DeleteTree

func (ddb *Store) DeleteTree(ctx context.Context, keyPrefix string) error

DeleteTree deletes a range of keys under a given directory.

func (*Store) Exists

func (ddb *Store) Exists(ctx context.Context, key string, _ *store.ReadOptions) (bool, error)

Exists if a Key exists in the store.

func (*Store) Get

func (ddb *Store) Get(ctx context.Context, key string, opts *store.ReadOptions) (*store.KVPair, error)

Get a value given its key.

func (*Store) List

func (ddb *Store) List(ctx context.Context, directory string, opts *store.ReadOptions) ([]*store.KVPair, error)

List the content of a given prefix.

func (*Store) NewLock

func (ddb *Store) NewLock(_ context.Context, key string, opts *store.LockOptions) (store.Locker, error)

NewLock has to implemented at the library level since it's not supported by DynamoDB.

func (*Store) Put

func (ddb *Store) Put(ctx context.Context, key string, value []byte, opts *store.WriteOptions) error

Put a value at the specified key.

func (*Store) Watch

func (ddb *Store) Watch(ctx context.Context, key string, _ *store.ReadOptions) (<-chan *store.KVPair, error)

Watch has to implemented at the library level since it's not supported by DynamoDB.

func (*Store) WatchTree

func (ddb *Store) WatchTree(_ context.Context, _ string, _ *store.ReadOptions) (<-chan []*store.KVPair, error)

WatchTree has to implemented at the library level since it's not supported by DynamoDB.

Jump to

Keyboard shortcuts

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