jsonapidynamodb

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: MIT Imports: 8 Imported by: 0

README

jsonapi-aws-dynamodb

Documentation

Index

Constants

View Source
const (
	PaginationCursorItemAttribute = "pagination_cursor" // references the page cursor in the page record.
	PaginationKeyItemAttribute    = "pagination_key"    // references the last evaluated key in the page record.
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Getter

type Getter interface {
	Get(context.Context, *dynamodb.GetItemInput, ...func(*dynamodb.Options)) (*dynamodb.GetItemOutput, error)
}

Getter implements the DynamoDB client Get API.

type Pagination

type Pagination struct {
	Provider            PaginationKeyProvider // The provider to manage the pagination table.
	TimeToLiveAttribute string                // The optional attribute that stores the TTL attribute.
	Lifespan            time.Duration         // The optional lifespace of a page record. Default is 24 hours.
}

Pagination structs provide a way to generate and store pagination cursors within a DynamoDB table.

func NewPagination

func NewPagination(provider PaginationKeyProvider, options ...func(*Pagination)) Pagination

NewPagination creates a new pagination instance.

func (Pagination) GetCursor

func (p Pagination) GetCursor(ctx context.Context,
	lastEvaluatedKey Record, putter Putter, options ...func(*dynamodb.Options)) (string, error)

GetCursor generates a new page cursor from the last evaluated key that is returned from a DynamoDB query or scan. If the key is nil, then an empty string is returned.

func (Pagination) GetLastEvaluatedKey

func (p Pagination) GetLastEvaluatedKey(ctx context.Context,
	cursor string, getter Getter, options ...func(*dynamodb.Options)) (Record, error)

GetLastEvaluatedKey retrieves the last evaluated key referenced by the provided page cursor.

type PaginationKeyProvider

type PaginationKeyProvider interface {
	// GenerateCursor generates a unique string that can be used by jsonapi clients
	// for pagination.
	GenerateCursor() string
	// GetPaginationKeyInput returns a DynamoDB GetItemInput struct that must contain
	// the following fields:
	//	- the table name
	//	- the record key associated with the provided cursor
	GetPaginationKeyInput(cursor string) dynamodb.GetItemInput
	// SetPaginationKeyInput returns a DynamoDB PutItemInput struct that must contain
	// the following fields:
	//	- the table name
	//  - the partial record item associated with the provided cursor
	SetPaginationKeyInput(cursor string) dynamodb.PutItemInput
}

PaginationKeyProvider is responsible for generating DynamoDB API input structs that allows the client to retrieve and store page records to a dynamodb table.

type Putter

type Putter interface {
	Put(context.Context, *dynamodb.PutItemInput, ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error)
}

Putter implements the DynamoDB client Put API.

type Record

type Record = map[string]types.AttributeValue

Record is a type alias for DynamoDB attribute value map.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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