Documentation ¶
Index ¶
- func NewAWSDynamoDBClient(awsConfig aws.Config) *dynamodb.Client
- type Delete
- type DynamoDB
- func (d *DynamoDB) CreateTable(ctx context.Context, model Model) error
- func (d *DynamoDB) CreateTables(ctx context.Context, models ...Model) error
- func (d *DynamoDB) Delete(model Model) *Delete
- func (d *DynamoDB) DeleteAllTables(ctx context.Context) error
- func (d *DynamoDB) DeleteTable(ctx context.Context, model Model) error
- func (d *DynamoDB) Get(target Model) *Query
- func (d *DynamoDB) Insert(model Model) *InsertOne
- func (d *DynamoDB) ListTables(ctx context.Context) ([]string, error)
- func (d *DynamoDB) Query(targetSlice any) *Query
- func (d *DynamoDB) Update(target Model) *Update
- type ExecutionResult
- type InsertOne
- type Model
- type ModelWithUpdateTs
- type PrimaryKey
- type Query
- type Update
- func (u *Update) AddToSet(field string, values ...any) *Update
- func (u *Update) AppendToList(field string, values ...any) *Update
- func (u *Update) Execute(ctx context.Context) (ExecutionResult, error)
- func (u *Update) Increment(field string, value any) *Update
- func (u *Update) Remove(field string) *Update
- func (u *Update) RemoveFromList(field string, idx int) *Update
- func (u *Update) RemoveFromSet(field string, values ...any) *Update
- func (u *Update) Set(field string, value any) *Update
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Delete ¶
type Delete struct { Result ExecutionResult // contains filtered or unexported fields }
type DynamoDB ¶
type DynamoDB struct { NowFunc func() time.Time TimeMarshalerFunc func(time.Time) any // contains filtered or unexported fields }
func (*DynamoDB) CreateTable ¶
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 ¶
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) DeleteAllTables ¶
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 ¶
DeleteTable deletes a table for the given model.
func (*DynamoDB) Get ¶
Get returns a new Query builder for the provided target model. It will expect a single result.
func (*DynamoDB) ListTables ¶
ListTables returns a list of tables that match the table prefix. The table prefix is: Env.Name + "_".
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 }
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 ¶
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) Where ¶
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 ¶
WithAllowScan allows the query to perform a scan operation. By default, scan operations are not allowed.
func (*Query) WithConsistentRead ¶
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 ¶
AddToSet adds values to a set field. Note: the provided field name must be the same as in the partiql tag.
func (*Update) AppendToList ¶
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 ¶
Increment increments or decrements a numeric field. Note: the provided field name must be the same as in the partiql tag.
func (*Update) Remove ¶
Remove removes a field from the item. Note: the provided field name must be the same as in the partiql tag.
func (*Update) RemoveFromList ¶
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 ¶
RemoveFromSet removes values from a set field. Note: the provided field name must be the same as in the partiql tag.