dynamodb

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAWSDynamoDBClient

func NewAWSDynamoDBClient(awsConfig aws.Config) *dynamodb.Client

Types

type Delete

type Delete struct {
	Result ExecutionResult
	// contains filtered or unexported fields
}

func (*Delete) Execute

func (d *Delete) Execute(ctx context.Context) (ExecutionResult, error)

type DynamoDB

type DynamoDB struct {
	NowFunc           func() time.Time
	TimeMarshalerFunc func(time.Time) any
	// contains filtered or unexported fields
}

func NewDynamoDB

func NewDynamoDB(conf config.Config, dynamoDBClient *dynamodb.Client) *DynamoDB

func (*DynamoDB) CreateTable

func (d *DynamoDB) CreateTable(ctx context.Context, model Model) error

CreateTable creates a table for the given model. The model PrimaryKey must be set before calling this method. The table name will be composed as: Env.Name + "_" + model.GetTableName().

func (*DynamoDB) CreateTables

func (d *DynamoDB) CreateTables(ctx context.Context, models ...Model) error

CreateTables creates tables for the given models. It will call CreateTable for each model, and return an aggregated error if any CreateTable call fails.

func (*DynamoDB) Delete

func (d *DynamoDB) Delete(model Model) *Delete

func (*DynamoDB) DeleteAllTables

func (d *DynamoDB) DeleteAllTables(ctx context.Context) error

DeleteAllTables deletes all tables returned by ListTables. It will call DeleteTable for each table, and return an aggregated error if any DeleteTable call fails.

func (*DynamoDB) DeleteTable

func (d *DynamoDB) DeleteTable(ctx context.Context, model Model) error

DeleteTable deletes a table for the given model.

func (*DynamoDB) Get

func (d *DynamoDB) Get(target Model) *Query

Get returns a new Query builder for the provided target model. It will expect a single result.

func (*DynamoDB) Insert

func (d *DynamoDB) Insert(model Model) *InsertOne

func (*DynamoDB) ListTables

func (d *DynamoDB) ListTables(ctx context.Context) ([]string, error)

ListTables returns a list of tables that match the table prefix. The table prefix is: Env.Name + "_".

func (*DynamoDB) Query

func (d *DynamoDB) Query(targetSlice any) *Query

Query returns a new Query builder for the provided target slice. Passing a prefilled slice with elements will result in a query by PK.

func (*DynamoDB) Update

func (d *DynamoDB) Update(target Model) *Update

Update returns a new Update builder for the provided target model. The target model must have its primary key set.

type ExecutionResult

type ExecutionResult struct {
	Err              error
	Metadata         middleware.Metadata
	ConsumedCapacity *types.ConsumedCapacity
}

ExecutionResult represents the result of an execution

type InsertOne

type InsertOne struct {
	Result ExecutionResult
	// contains filtered or unexported fields
}

func (*InsertOne) Execute

func (i *InsertOne) Execute(ctx context.Context) (ExecutionResult, error)

type Model

type Model interface {
	GetTableName() string
	GetPK() PrimaryKey
	SetPK(PrimaryKey)
	GetCreateTs() time.Time
	SetCreateTs(time.Time)
}

Model is a model with a primary key

type ModelWithUpdateTs

type ModelWithUpdateTs interface {
	GetUpdateTsKey() string
	GetUpdateTs() time.Time
	SetUpdateTs(time.Time)
}

ModelWithUpdateTs is a model that can be updated

type PrimaryKey

type PrimaryKey struct {
	HashKey  string
	Hash     string
	RangeKey string
	Range    any
}

PrimaryKey represents a DynamoDB primary key. Provide a RangeKey and Range value if the model has a range key.

type Query

type Query struct {
	ExecuteStatementInput dynamodb.ExecuteStatementInput
	WhereClause           string
	WhereArgs             []any
	AllowScan             bool

	Result ExecutionResult
	// contains filtered or unexported fields
}

Query is a builder for querying items in a DynamoDB table using PartiQL.

func (*Query) Execute

func (q *Query) Execute(ctx context.Context) (ExecutionResult, error)

func (*Query) Where

func (q *Query) Where(where string, args ...any) *Query

Where sets the where clause and arguments for the query. It must be written in PartiQL syntax with the field names being the same as the DynamoDB table. There is no named parameters support. Caution: Calling this function will override any previous where clause and arguments Example:

Where("id = ? AND name = ?", "123", "John")

Refer to: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.html

func (*Query) WithAllowScan

func (q *Query) WithAllowScan() *Query

WithAllowScan allows the query to perform a scan operation. By default, scan operations are not allowed.

func (*Query) WithConsistentRead

func (q *Query) WithConsistentRead() *Query

WithConsistentRead sets the query to use consistent read. By default, queries use eventually consistent read.

func (*Query) WithPKs

func (q *Query) WithPKs(pks ...PrimaryKey) *Query

type Update

type Update struct {
	Result ExecutionResult
	// contains filtered or unexported fields
}

Update is a builder for updating items in a DynamoDB table using PartiQL. AWS docs: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.update.html

func (*Update) AddToSet

func (u *Update) AddToSet(field string, values ...any) *Update

AddToSet adds values to a set field. Note: the provided field name must be the same as in the partiql tag.

func (*Update) AppendToList

func (u *Update) AppendToList(field string, values ...any) *Update

AppendToList appends values to a list field. Note: the provided field name must be the same as in the partiql tag.

func (*Update) Execute

func (u *Update) Execute(ctx context.Context) (ExecutionResult, error)

Execute executes the update operation. It will return immediately if there is an error in the builder.

func (*Update) Increment

func (u *Update) Increment(field string, value any) *Update

Increment increments or decrements a numeric field. Note: the provided field name must be the same as in the partiql tag.

func (*Update) Remove

func (u *Update) Remove(field string) *Update

Remove removes a field from the item. Note: the provided field name must be the same as in the partiql tag.

func (*Update) RemoveFromList

func (u *Update) RemoveFromList(field string, idx int) *Update

RemoveFromList removes an item from a list field. Note: the provided field name must be the same as in the partiql tag.

func (*Update) RemoveFromSet

func (u *Update) RemoveFromSet(field string, values ...any) *Update

RemoveFromSet removes values from a set field. Note: the provided field name must be the same as in the partiql tag.

func (*Update) Set

func (u *Update) Set(field string, value any) *Update

Set sets a field in the item. Note: the provided field name must be the same as in the partiql tag.

Jump to

Keyboard shortcuts

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