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 ¶
- Variables
- func All(tableName string, item interface{}) (interface{}, error)
- func BatchDelete(tableName string, items interface{}) error
- func BatchPut(tableName string, items interface{}) error
- func CreateTable(tableName string, item interface{}, read, write int) error
- func Delete(tableName string, item interface{}) error
- func DeleteTable(tableName string) error
- func DescribeTable(tableName string) (types.Table, error)
- func Get(tableName string, item interface{}) error
- func ListTables() ([]string, error)
- func Pluck(tableName string, item interface{}, attrs ...string) (interface{}, error)
- func Put(tableName string, item interface{}) error
- type Service
- func (s *Service) All(tableName string, item interface{}) (interface{}, error)
- func (s *Service) BatchDelete(tableName string, items interface{}) error
- func (s *Service) BatchPut(tableName string, items interface{}) error
- func (s *Service) CreateTable(tableName string, item interface{}, read, write int) error
- func (s *Service) Delete(tableName string, item interface{}) error
- func (s *Service) DeleteTable(tableName string) error
- func (s *Service) DescribeTable(tableName string) (types.Table, error)
- func (s *Service) Do(action string, body interface{}, a interface{}) error
- func (s *Service) Get(tableName string, item interface{}) error
- func (s *Service) ListTables() ([]string, error)
- func (s *Service) Pluck(tableName string, item interface{}, attrs ...string) (interface{}, error)
- func (s *Service) Put(tableName string, item interface{}) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultService = &Service{ Region: "us-east-1", Version: "20120810", Client: aws.DefaultClient, } )
Functions ¶
func All ¶
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 CreateTable ¶
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 ¶
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 ¶
Deletes the given table.
Example ¶
package main import ( "github.com/cyberdelia/dynamodb" ) func main() { err := dynamodb.DeleteTable("papers") if err != nil { // ... } }
Output:
func DescribeTable ¶
Describe given table.
func Get ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (*Service) BatchDelete ¶
func (*Service) CreateTable ¶
Creates table corresponding to the given item.
func (*Service) DeleteTable ¶
Deletes the given table.
func (*Service) DescribeTable ¶
Describe given table.