espdynamodb

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DYNAMODB_BATCH_GET_LIMIT = 100
View Source
const DYNAMODB_BATCH_WRITE_LIMIT = 25

Variables

This section is empty.

Functions

func DbBatchDeleteItem

func DbBatchDeleteItem[T DBItem](d *EspDB, tableName string, v []T) error

func DbBatchGetItemLoop

func DbBatchGetItemLoop[T any](input DbBatchGetItemLoopInput) ([]T, error)

func DbBatchPutItem

func DbBatchPutItem[T any](d *EspDB, tableName string, v []T) error

func DbQueryWithLoop

func DbQueryWithLoop[T any](input QueryWithLoopInput[T]) ([]T, map[string]types.AttributeValue, error)

DbQueryWithLoop ... Query based on some conditions on the composite keys.

This function is a generalized function to query a table until required. AppendAndReInitialize Function controls the flow of the query. Examples:

  1. To get all the elements for the matching condition appendAndReInitialize := func(out, fOut interface{}, nxtID map[string]*dynamodb.AttributeValue, count int64) (map[string]*dynamodb.AttributeValue, bool) { if out != nil && fOut != nil { temp := out.((*[]models.NodeInfo)) fTemp := fOut.((*[]models.NodeInfo)) *fTemp = append(*fTemp, *temp...) temp = new([]models.NodeInfo) } return nxtID, true }
  2. When filter condition is present and you want to query for certain number of records appendAndReInitialize := func(out, fOut interface{}, nxtID map[string]*dynamodb.AttributeValue, count int64) (map[string]*dynamodb.AttributeValue, bool) { if out != nil && fOut != nil { tempResult := out.(*[]models.FileDetails) finalResult := fOut.(*[]models.FileDetails) fTempLen := len(*finalResult) tempLen := len(*tempResult) if tempLen+fTempLen > int(count) { if count != 0 { *finalResult = append(*finalResult, (*tempResult)[0:count-int64(fTempLen)]...) } else { *finalResult = append(*finalResult, *tempResult...) // If count is 0(i.e ∞), add all of temp to fTemp, instead of slicing. } nxtID[constants.USER_ID] = &dynamodb.AttributeValue{S: aws.String((*finalResult)[len(*finalResult)-1].UserId)} nxtID["file_id"] = &dynamodb.AttributeValue{S: aws.String((*finalResult)[len(*finalResult)-1].FileId)} return nxtID, false // If we get more records than required, take as many as required, return the lastEvaluatedKey and don't paginate further. } else { *finalResult = append(*finalResult, *tempResult...) fTempLen += tempLen if fTempLen == int(count) || nxtID == nil { return nxtID, false // If desired no. of records are retrieved OR there are no more records at DB, return lastEvaluatedKey and don't paginate further. } *tempResult = []models.FileDetails{} return nxtID, true // If there still are more records to retrieve, return lastEvaluatedKey and paginate further. } } return nxtID, true }

func GetItemExistsCondition

func GetItemExistsCondition(keys map[string]types.AttributeValue) expression.ConditionBuilder

func GetItemNotExistsCondition

func GetItemNotExistsCondition(query DBItem) expression.ConditionBuilder

Types

type DBItem

type DBItem interface {
	GetHKey() string
	GetRKey() string
}

type DbBatchGetItemLoopInput

type DbBatchGetItemLoopInput struct {
	TableName string
	Expr      expression.Expression
	Keys      []map[string]types.AttributeValue
	DBConn    *EspDB
}

type DbQueryCountInput

type DbQueryCountInput struct {
	TableName string
	IndexName string
	Expr      expression.Expression
	StartID   map[string]types.AttributeValue
	// ConsistentRead forces a strongly consistent count. Only valid on a
	// base-table query (IndexName empty); DynamoDB rejects it on a GSI.
	ConsistentRead bool
}

type DbUpdateItemInput

type DbUpdateItemInput struct {
	TableName string
	Update    expression.UpdateBuilder
	Query     DBItem
	Condition expression.ConditionBuilder
}

type DbUpdateItemStructSetInput

type DbUpdateItemStructSetInput struct {
	TableName string
	Item      DBItem
	Condition expression.ConditionBuilder
}

type EspDB

type EspDB struct {
	DB *db.DB
	// Should a DB Context have a 'User'? Well at least we need a
	// Accessor - ID and their permission set
	Ctx *rmngctx.RmngContext
}

func NewEspDB

func NewEspDB(ctx *rmngctx.RmngContext) EspDB

func (*EspDB) DbCreateItem

func (d *EspDB) DbCreateItem(tableName string, v DBItem) error

DbCreateItem creates an item in the database using condition builder

func (*EspDB) DbDeleteItem

func (d *EspDB) DbDeleteItem(tableName string, query DBItem) error

DbDeleteItem deletes the items in the database

func (*EspDB) DbGetItem

func (d *EspDB) DbGetItem(tableName string, query DBItem, out interface{}) error

DbGetItem gets a single item from the database

func (*EspDB) DbQueryCountLoop

func (d *EspDB) DbQueryCountLoop(input DbQueryCountInput) (int32, error)

func (*EspDB) DbUpdateItem

func (d *EspDB) DbUpdateItem(input DbUpdateItemInput) (*dynamodb.UpdateItemOutput, error)

DbUpdateItem updates the items in the database

func (*EspDB) DbUpdateItemStructSet

func (d *EspDB) DbUpdateItemStructSet(input DbUpdateItemStructSetInput) (*dynamodb.UpdateItemOutput, error)

DbUpdateItemStructSet updates all non-key fields of a struct in DynamoDB item should implement the DBItem interface and contain the updated values

type QueryWithLoopInput

type QueryWithLoopInput[T any] struct {
	DBHandle              *EspDB
	TableName             string
	IndexName             string
	Limit                 int64
	StartKey              map[string]types.AttributeValue
	Expr                  expression.Expression
	SortOrder             *bool
	AppendAndReInitialize func(*[]T, *[]T, map[string]types.AttributeValue, int64) (map[string]types.AttributeValue, bool)
	GetKey                func(T, ...string) map[string]types.AttributeValue // Required when limit is passed and AppendAndReInitialize is to be skipped
}

Jump to

Keyboard shortcuts

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