dydb

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2015 License: BSD-2-Clause Imports: 6 Imported by: 0

README

Documentation

Overview

This is an experimental library for use with DynamoDB. It uses github.com/bmizerany/aws4 to sign requests. See Example for use.

Example (CreateAndListTables)
package main

import (
	"fmt"
	"github.com/bmizerany/aws4/dydb"
	"log"
)

func init() {
	log.SetFlags(0)
}

func main() {
	var db dydb.DB

	type AttributeDefinition struct {
		AttributeName string
		AttributeType string
	}

	type KeySchema struct {
		AttributeName string
		KeyType       string
	}

	var posts struct {
		TableName             string
		AttributeDefinitions  []AttributeDefinition
		KeySchema             []KeySchema
		ProvisionedThroughput struct {
			ReadCapacityUnits  int
			WriteCapacityUnits int
		}
	}

	posts.TableName = "Posts"
	posts.AttributeDefinitions = []AttributeDefinition{{"Slug", "S"}}
	posts.KeySchema = []KeySchema{{"Slug", "HASH"}}
	posts.ProvisionedThroughput.ReadCapacityUnits = 4
	posts.ProvisionedThroughput.WriteCapacityUnits = 4

	if err := db.Exec("CreateTable", posts); err != nil {
		if !dydb.IsException(err, "ResourceInUseException") {
			log.Fatal(err)
		}
	}

	var resp struct{ TableNames []string }
	if err := db.Query("ListTables", nil).Decode(&resp); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%q", resp.TableNames)
}
Output:

["Posts"]

Index

Examples

Constants

View Source
const (
	DefaultURL     = "https://dynamodb.us-east-1.amazonaws.com/"
	DefaultVersion = "20120810"
)

Variables

This section is empty.

Functions

func IsException

func IsException(err error, name string) bool

IsException returns true if err is a ResponseError whos TypeName() equals name; false otherwise.

Types

type DB

type DB struct {
	// The version of DynamoDB to use. If empty string, DefaultVersion is
	// used.
	Version string

	// If nil, aws4.DefaultClient is used.
	Client *aws4.Client

	// If empty, DefaultURL is used.
	URL string
}

func (*DB) Exec

func (db *DB) Exec(action string, v interface{}) error

Exec is like Query, but discards the response. It returns the error if there was one.

func (*DB) Query

func (db *DB) Query(action string, v interface{}) Decoder

Query executes an action with a JSON-encoded v as the body. A nil v is represented as the JSON value {}. If an error occurs while communicating with DynamoDB, Query returns a Decoder that returns only the error, otherwise a json.Decoder is returned.

type Decoder

type Decoder interface {
	Decode(v interface{}) error
}

type ResponseError

type ResponseError struct {
	StatusCode int
	Type       string
	Message    string
}

A ResponseError is returned by Decode when an error communicating with DynamoDB occurs.

func (*ResponseError) Error

func (e *ResponseError) Error() string

func (*ResponseError) TypeName

func (e *ResponseError) TypeName() string

TypeName returns the error Type without the namespace.

Jump to

Keyboard shortcuts

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