dynamodocstore

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package dynamodocstore provides a docstore implementation backed by AWS DynamoDB. Use OpenCollection to construct a *docstore.Collection.

URLs

For docstore.OpenCollection, dynamodocstore registers for the scheme "dynamodb". The default URL opener will use an AWS session with the default credentials and configuration; see https://docs.aws.amazon.com/sdk-for-go/api/aws/session/ for more details. To customize the URL opener, or for more details on the URL format, see URLOpener. See https://gocloud.dev/concepts/urls/ for background information.

As

dynamodocstore exposes the following types for As:

  • Collection.As: *dynamodb.DynamoDB
  • ActionList.BeforeDo: *dynamodb.TransactGetItemsInput or *dynamodb.TransactWriteItemsInput
  • Query.BeforeQuery: *dynamodb.QueryInput or *dynamodb.ScanInput
  • DocumentIterator: *dynamodb.QueryOutput or *dynamodb.ScanOutput

Index

Examples

Constants

View Source
const Scheme = "dynamodb"

Scheme is the URL scheme dynamodb registers its URLOpener under on docstore.DefaultMux.

Variables

This section is empty.

Functions

func Dial added in v0.13.0

Dial gets an AWS DynamoDB service client.

func OpenCollection

func OpenCollection(db *dyn.DynamoDB, tableName, partitionKey, sortKey string, opts *Options) (*docstore.Collection, error)

OpenCollection creates a *docstore.Collection representing a DynamoDB collection.

Example
package main

import (
	"context"
	"fmt"

	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/dynamodb"
	"gocloud.dev/internal/docstore/dynamodocstore"
)

func main() {
	ctx := context.Background()
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println(err)
		return
	}
	coll, err := dynamodocstore.OpenCollection(dynamodb.New(sess), "docstore-test", "_id", "", nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	errs := coll.Actions().Put(map[string]interface{}{"_id": "Alice", "score": 25}).Do(ctx)
	fmt.Println(errs)
}
Output:

Types

type Options added in v0.14.0

type Options struct {
	// If false, queries that can only be executed by scanning the entire table
	// return an error instead (with the exception of a query with no filters).
	AllowScans bool
}

type URLOpener added in v0.13.0

type URLOpener struct {
	// ConfigProvider must be set to a non-nil value.
	ConfigProvider client.ConfigProvider
}

URLOpener opens dynamodb URLs like "dynamodb://mytable?partition_key=partkey&sort_key=sortkey".

The URL Host is used as the table name. See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html for more details.

The following query parameters are supported:

  • partition_key (required): the path to the partition key of a table or an index.
  • sort_key: the path to the sort key of a table or an index.
  • allow_scans: if "true", allow table scans to be used for queries

See https://godoc.org/gocloud.dev/aws#ConfigFromURLParams for supported query parameters for overriding the aws.Session from the URL.

func (*URLOpener) OpenCollectionURL added in v0.13.0

func (o *URLOpener) OpenCollectionURL(_ context.Context, u *url.URL) (*docstore.Collection, error)

OpenCollectionURL opens the collection at the URL's path. See the package doc for more details.

Jump to

Keyboard shortcuts

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