dynago

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 10 Imported by: 0

README

Dynago

Note: This library is still under significant development, so breaking changes can happen at any time!

Basic Usage

func main() {
    ...
    // instatiate the global client
    dynago.InstantiateDynamoClient(some_region)
    // get a handle to the a table
    SomeTable := dynago.GetTableClient(some_table)

    // type *SomeItem implements the DynamoItem interface

    // adds an item to the db. only the primary key is required at the moment of creation
    SomeTable.Add(&SomeItem{
        PrimaryKey: key,
        SomeField: 1,
        SomeField: "two",
        ...
    })
    // retrieves an item by its primary key
    SomeTable.Get(&SomeItem{PrimaryKey: key})
    // retrieves items where {"key": 123} by the GSI
    SomeTable.GetByGSI(&SomeItem{}, "key", 123)
    // searches by the primary key, then updates the desired attribute
    SomeTable.Update(&SomeItem, "attribute", new_value)
    // searches by the primary key, then removes the item from the db
    SomeTable.Delete(&SomeItem)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstantiateDynamoClient

func InstantiateDynamoClient(region string) error

instantiates a dynamo client with the region in the environment variable AWS_REGION, or the region provided in the argument if the environment variable is not found

Types

type DynamoItem

type DynamoItem interface {

	// MarshalMap is identical to the aws SDK's MarshalMap function
	MarshalMap() (map[string]types.AttributeValue, error)

	// Returns the primary key map of the item
	GetPrimaryKeyMap() map[string]types.AttributeValue

	// Returns the GSI name and gsi attribute name of the item,
	// or an empty string if the item does not have a GSI configured.
	GetGSI() (gsi string, attr string)

	// Sets attributes found in the GetItemOutput to its own attributes.
	// Attributes in the argument that are not found will be ignored.
	UnmarshalMap(o map[string]types.AttributeValue)
}

type Table

type Table struct {
	// contains filtered or unexported fields
}

func GetTableClient

func GetTableClient(table string) *Table

returns a table client for the table specified

func (*Table) Add

func (d *Table) Add(i DynamoItem) error

add one item to the table

func (*Table) Delete

func (d *Table) Delete(i DynamoItem) error

func (*Table) Get

func (d *Table) Get(i DynamoItem) (map[string]types.AttributeValue, error)

get one item from the table

func (*Table) GetByGSI

func (d *Table) GetByGSI(i DynamoItem, val any) ([]map[string]types.AttributeValue, error)

get a list of items, searching by the GSI. you can think of this as searching by the GSI for when the GSI's attribute is equal to 'val'

func (*Table) GetOneByGSI

func (d *Table) GetOneByGSI(i DynamoItem, val any) (map[string]types.AttributeValue, error)

like GetByGSI, but only returns the first value the query finds. Useful for when you know only one item matches the query.

func (*Table) Scan added in v1.0.2

func (d *Table) Scan() ([]map[string]types.AttributeValue, error)

Returns all entries in the table up to the 1MB scan limit in dynamodb

func (*Table) Update

func (d *Table) Update(i DynamoItem, key, value string) error

update one item in the table

Jump to

Keyboard shortcuts

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