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://github.com/eliben/gocdkx/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
Example ¶
package main import ( "context" "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/eliben/gocdkx/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", "") if err != nil { fmt.Println(err) return } errs := coll.Actions().Put(map[string]interface{}{"_id": "Alice", "score": 25}).Do(ctx) fmt.Println(errs) }
Output:
Index ¶
Examples ¶
Constants ¶
const Scheme = "dynamodb"
Scheme is the URL scheme dynamodb registers its URLOpener under on docstore.DefaultMux.
Variables ¶
This section is empty.
Functions ¶
func Dial ¶
func Dial(p client.ConfigProvider) (*dyn.DynamoDB, error)
Dial gets an AWS DynamoDB service client.
func OpenCollection ¶
func OpenCollection(db *dyn.DynamoDB, tableName, partitionKey, sortKey string) (*docstore.Collection, error)
OpenCollection creates a *docstore.Collection representing a DynamoDB collection.
Types ¶
type URLOpener ¶
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.
See https://godoc.org/github.com/eliben/gocdkx/aws#ConfigFromURLParams for supported query parameters for overriding the aws.Session from the URL.
func (*URLOpener) OpenCollectionURL ¶
OpenCollectionURL opens the collection at the URL's path. See the package doc for more details.