dynamodb

package module
v0.0.0-...-3b54d80 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

An intelligible dynamodb client

This package allows you to store almost any struct with dynamodb. Each exported struct field becomes a member of the object unless the field's tag is "-".

Default attribute name is the struct field name but can be specified in the struct field's tag value. The "dynamo" key in the struct field's tag value is the attribute name, followed by an optional comma and options. Examples:

// Field is ignored by this package.
Field int `dynamo:"-"`

// Field appears in table as attribute "myName".
Field int `dynamo:"myName"`

// Field is considered as an hash or range key in table.
Field string `dynamo:",hash"`
Field int    `dynamo:",range"`

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	DefaultService = &Service{
		Region:  "us-east-1",
		Version: "20120810",
		Client:  aws.DefaultClient,
	}
)

Functions

func All

func All(tableName string, item interface{}) (interface{}, error)

Return all items in the given table.

Example
package main

import (
	"fmt"
	"github.com/cyberdelia/dynamodb"
)

type Paper struct {
	Title   string   `dynamo:"title,hash"`
	Year    int      `dynamo:"year,range"`
	Score   float64  `dynamo:"score"`
	Authors []string `dynamo:"authors"`
}

func main() {
	items, err := dynamodb.All("papers", &Paper{})
	if err != nil {
		// ...
	}
	papers := items.([]*Paper)
	fmt.Println(papers)
}
Output:

func BatchDelete

func BatchDelete(tableName string, items interface{}) error

func BatchPut

func BatchPut(tableName string, items interface{}) error

func CreateTable

func CreateTable(tableName string, item interface{}, read, write int) error

Creates table corresponding to the given item.

Example
package main

import (
	"github.com/cyberdelia/dynamodb"
)

type Paper struct {
	Title   string   `dynamo:"title,hash"`
	Year    int      `dynamo:"year,range"`
	Score   float64  `dynamo:"score"`
	Authors []string `dynamo:"authors"`
}

func main() {
	err := dynamodb.CreateTable("papers", &Paper{}, 1, 1)
	if err != nil {
		// ...
	}
}
Output:

func Delete

func Delete(tableName string, item interface{}) error

Deletes corresponding item in the given table.

Example
package main

import (
	"github.com/cyberdelia/dynamodb"
)

type Paper struct {
	Title   string   `dynamo:"title,hash"`
	Year    int      `dynamo:"year,range"`
	Score   float64  `dynamo:"score"`
	Authors []string `dynamo:"authors"`
}

func main() {
	paper := &Paper{
		Title: "Dynamo: Amazon’s Highly Available Key-value Store",
		Year:  2007,
	}
	err := dynamodb.Delete("papers", paper)
	if err != nil {
		// ...
	}
}
Output:

func DeleteTable

func DeleteTable(tableName string) error

Deletes the given table.

Example
package main

import (
	"github.com/cyberdelia/dynamodb"
)

func main() {
	err := dynamodb.DeleteTable("papers")
	if err != nil {
		// ...
	}
}
Output:

func DescribeTable

func DescribeTable(tableName string) (types.Table, error)

Describe given table.

func Get

func Get(tableName string, item interface{}) error

Get the corresponding item from the given table.

Example
package main

import (
	"github.com/cyberdelia/dynamodb"
)

type Paper struct {
	Title   string   `dynamo:"title,hash"`
	Year    int      `dynamo:"year,range"`
	Score   float64  `dynamo:"score"`
	Authors []string `dynamo:"authors"`
}

func main() {
	paper := &Paper{
		Title: "Dynamo: Amazon’s Highly Available Key-value Store",
		Year:  2007,
	}
	err := dynamodb.Get("papers", paper)
	if err != nil {
		// ...
	}
}
Output:

func ListTables

func ListTables() ([]string, error)

List existing tables.

Example
package main

import (
	"fmt"
	"github.com/cyberdelia/dynamodb"
)

func main() {
	tables, err := dynamodb.ListTables()
	if err != nil {
		// ...
	}
	fmt.Println(tables)
}
Output:

func Pluck

func Pluck(tableName string, item interface{}, attrs ...string) (interface{}, error)

Return given attributes for all item in the given table.

Example
package main

import (
	"fmt"
	"github.com/cyberdelia/dynamodb"
)

type Paper struct {
	Title   string   `dynamo:"title,hash"`
	Year    int      `dynamo:"year,range"`
	Score   float64  `dynamo:"score"`
	Authors []string `dynamo:"authors"`
}

func main() {
	items, err := dynamodb.Pluck("papers", &Paper{}, "title", "year")
	if err != nil {
		// ...
	}
	for _, paper := range items.([]*Paper) {
		fmt.Println(paper.Title)
	}

}
Output:

func Put

func Put(tableName string, item interface{}) error

Create or replace the item in the given table.

Example
package main

import (
	"github.com/cyberdelia/dynamodb"
)

type Paper struct {
	Title   string   `dynamo:"title,hash"`
	Year    int      `dynamo:"year,range"`
	Score   float64  `dynamo:"score"`
	Authors []string `dynamo:"authors"`
}

func main() {
	err := dynamodb.Put("papers", &Paper{
		Title:   "Dynamo: Amazon’s Highly Available Key-value Store",
		Year:    2007,
		Score:   1.5,
		Authors: []string{"Giuseppe DeCandia", "Werner Vogels", "Deniz Hastorun"},
	})
	if err != nil {
		// ...
	}
}
Output:

Types

type Service

type Service struct {
	Region  string
	Version string
	Client  *aws.Client
}

func (*Service) All

func (s *Service) All(tableName string, item interface{}) (interface{}, error)

Return all items in the given table.

func (*Service) BatchDelete

func (s *Service) BatchDelete(tableName string, items interface{}) error

func (*Service) BatchPut

func (s *Service) BatchPut(tableName string, items interface{}) error

func (*Service) CreateTable

func (s *Service) CreateTable(tableName string, item interface{}, read, write int) error

Creates table corresponding to the given item.

func (*Service) Delete

func (s *Service) Delete(tableName string, item interface{}) error

Deletes corresponding item in the given table.

func (*Service) DeleteTable

func (s *Service) DeleteTable(tableName string) error

Deletes the given table.

func (*Service) DescribeTable

func (s *Service) DescribeTable(tableName string) (types.Table, error)

Describe given table.

func (*Service) Do

func (s *Service) Do(action string, body interface{}, a interface{}) error

func (*Service) Get

func (s *Service) Get(tableName string, item interface{}) error

Get the corresponding item from the given table.

func (*Service) ListTables

func (s *Service) ListTables() ([]string, error)

List existing tables.

func (*Service) Pluck

func (s *Service) Pluck(tableName string, item interface{}, attrs ...string) (interface{}, error)

Return given attributes for all item in the given table.

func (*Service) Put

func (s *Service) Put(tableName string, item interface{}) error

Create or replace the item in the given table.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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