actions

package
v0.0.0-...-e995d3a Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IMovieSampler

type IMovieSampler interface {
	GetURL() string
	GetSampleMovies() []Movie
}

IMovieSampler defines an interface that can be used to download sample movie data from a URL.

type Movie

type Movie struct {
	Title string                 `dynamodbav:"title"`
	Year  int                    `dynamodbav:"year"`
	Info  map[string]interface{} `dynamodbav:"info"`
}

Movie encapsulates data about a movie. Title and Year are the composite primary key of the movie in Amazon DynamoDB. Title is the sort key, Year is the partition key, and Info is additional data.

func (Movie) GetKey

func (movie Movie) GetKey() map[string]types.AttributeValue

GetKey returns the composite primary key of the movie in a format that can be sent to DynamoDB.

func (Movie) String

func (movie Movie) String() string

String returns the title, year, rating, and plot of a movie, formatted for the example.

type MovieSampler

type MovieSampler struct {
	URL string
}

MovieSampler implements IMovieSampler to download movie data from URL.

func (MovieSampler) GetSampleMovies

func (sampler MovieSampler) GetSampleMovies() []Movie

GetSampleMovies downloads a .zip file of movie data, unzips it in memory, and unmarshals it into a Movie slice.

func (MovieSampler) GetURL

func (sampler MovieSampler) GetURL() string

GetURL returns the URL of the sampler.

type PartiQLRunner

type PartiQLRunner struct {
	DynamoDbClient *dynamodb.Client
	TableName      string
}

PartiQLRunner encapsulates the Amazon DynamoDB service actions used in the PartiQL examples. It contains a DynamoDB service client that is used to act on the specified table.

func (PartiQLRunner) AddMovie

func (runner PartiQLRunner) AddMovie(movie Movie) error

AddMovie runs a PartiQL INSERT statement to add a movie to the DynamoDB table.

func (PartiQLRunner) AddMovieBatch

func (runner PartiQLRunner) AddMovieBatch(movies []Movie) error

AddMovieBatch runs a batch of PartiQL INSERT statements to add multiple movies to the DynamoDB table.

func (PartiQLRunner) DeleteMovie

func (runner PartiQLRunner) DeleteMovie(movie Movie) error

DeleteMovie runs a PartiQL DELETE statement to remove a movie from the DynamoDB table.

func (PartiQLRunner) DeleteMovieBatch

func (runner PartiQLRunner) DeleteMovieBatch(movies []Movie) error

DeleteMovieBatch runs a batch of PartiQL DELETE statements to remove multiple movies from the DynamoDB table.

func (PartiQLRunner) GetAllMovies

func (runner PartiQLRunner) GetAllMovies() ([]map[string]interface{}, error)

GetAllMovies runs a PartiQL SELECT statement to get all movies from the DynamoDB table. The results are projected to return only the title and rating of each movie.

func (PartiQLRunner) GetMovie

func (runner PartiQLRunner) GetMovie(title string, year int) (Movie, error)

GetMovie runs a PartiQL SELECT statement to get a movie from the DynamoDB table by title and year.

func (PartiQLRunner) GetMovieBatch

func (runner PartiQLRunner) GetMovieBatch(movies []Movie) ([]Movie, error)

GetMovieBatch runs a batch of PartiQL SELECT statements to get multiple movies from the DynamoDB table by title and year.

func (PartiQLRunner) UpdateMovie

func (runner PartiQLRunner) UpdateMovie(movie Movie, rating float64) error

UpdateMovie runs a PartiQL UPDATE statement to update the rating of a movie that already exists in the DynamoDB table.

func (PartiQLRunner) UpdateMovieBatch

func (runner PartiQLRunner) UpdateMovieBatch(movies []Movie, ratings []float64) error

UpdateMovieBatch runs a batch of PartiQL UPDATE statements to update the rating of multiple movies that already exist in the DynamoDB table.

type TableBasics

type TableBasics struct {
	DynamoDbClient *dynamodb.Client
	TableName      string
}

TableBasics encapsulates the Amazon DynamoDB service actions used in the examples. It contains a DynamoDB service client that is used to act on the specified table.

func (TableBasics) AddMovie

func (basics TableBasics) AddMovie(movie Movie) error

AddMovie adds a movie the DynamoDB table.

func (TableBasics) AddMovieBatch

func (basics TableBasics) AddMovieBatch(movies []Movie, maxMovies int) (int, error)

AddMovieBatch adds a slice of movies to the DynamoDB table. The function sends batches of 25 movies to DynamoDB until all movies are added or it reaches the specified maximum.

func (TableBasics) CreateMovieTable

func (basics TableBasics) CreateMovieTable() (*types.TableDescription, error)

CreateMovieTable creates a DynamoDB table with a composite primary key defined as a string sort key named `title`, and a numeric partition key named `year`. This function uses NewTableExistsWaiter to wait for the table to be created by DynamoDB before it returns.

func (TableBasics) DeleteMovie

func (basics TableBasics) DeleteMovie(movie Movie) error

DeleteMovie removes a movie from the DynamoDB table.

func (TableBasics) DeleteTable

func (basics TableBasics) DeleteTable() error

DeleteTable deletes the DynamoDB table and all of its data.

func (TableBasics) GetMovie

func (basics TableBasics) GetMovie(title string, year int) (Movie, error)

GetMovie gets movie data from the DynamoDB table by using the primary composite key made of title and year.

func (TableBasics) ListTables

func (basics TableBasics) ListTables() ([]string, error)

ListTables lists the DynamoDB table names for the current account.

func (TableBasics) Query

func (basics TableBasics) Query(releaseYear int) ([]Movie, error)

Query gets all movies in the DynamoDB table that were released in the specified year. The function uses the `expression` package to build the key condition expression that is used in the query.

func (TableBasics) Scan

func (basics TableBasics) Scan(startYear int, endYear int) ([]Movie, error)

Scan gets all movies in the DynamoDB table that were released in a range of years and projects them to return a reduced set of fields. The function uses the `expression` package to build the filter and projection expressions.

func (TableBasics) TableExists

func (basics TableBasics) TableExists() (bool, error)

TableExists determines whether a DynamoDB table exists.

func (TableBasics) UpdateMovie

func (basics TableBasics) UpdateMovie(movie Movie) (map[string]map[string]interface{}, error)

UpdateMovie updates the rating and plot of a movie that already exists in the DynamoDB table. This function uses the `expression` package to build the update expression.

Jump to

Keyboard shortcuts

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