actions

package
v0.0.0-...-7fc628c Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 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(ctx context.Context, movie Movie) error

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

func (PartiQLRunner) AddMovieBatch

func (runner PartiQLRunner) AddMovieBatch(ctx context.Context, 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(ctx context.Context, movie Movie) error

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

func (PartiQLRunner) DeleteMovieBatch

func (runner PartiQLRunner) DeleteMovieBatch(ctx context.Context, 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(ctx context.Context, pageSize int32) ([]map[string]interface{}, error)

GetAllMovies runs a PartiQL SELECT statement to get all movies from the DynamoDB table. pageSize is not typically required and is used to show how to paginate the results. The results are projected to return only the title and rating of each movie.

func (PartiQLRunner) GetMovie

func (runner PartiQLRunner) GetMovie(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, movie Movie) error

AddMovie adds a movie the DynamoDB table.

func (TableBasics) AddMovieBatch

func (basics TableBasics) AddMovieBatch(ctx context.Context, 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(ctx context.Context) (*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(ctx context.Context, movie Movie) error

DeleteMovie removes a movie from the DynamoDB table.

func (TableBasics) DeleteTable

func (basics TableBasics) DeleteTable(ctx context.Context) error

DeleteTable deletes the DynamoDB table and all of its data.

func (TableBasics) GetMovie

func (basics TableBasics) GetMovie(ctx context.Context, 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(ctx context.Context) ([]string, error)

ListTables lists the DynamoDB table names for the current account.

func (TableBasics) Query

func (basics TableBasics) Query(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context) (bool, error)

TableExists determines whether a DynamoDB table exists.

func (TableBasics) UpdateMovie

func (basics TableBasics) UpdateMovie(ctx context.Context, 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