Documentation
¶
Index ¶
- Constants
- func DbBatchDeleteItem[T DBItem](d *EspDB, tableName string, v []T) error
- func DbBatchGetItemLoop[T any](input DbBatchGetItemLoopInput) ([]T, error)
- func DbBatchPutItem[T any](d *EspDB, tableName string, v []T) error
- func DbQueryWithLoop[T any](input QueryWithLoopInput[T]) ([]T, map[string]types.AttributeValue, error)
- func GetItemExistsCondition(keys map[string]types.AttributeValue) expression.ConditionBuilder
- func GetItemNotExistsCondition(query DBItem) expression.ConditionBuilder
- type DBItem
- type DbBatchGetItemLoopInput
- type DbQueryCountInput
- type DbUpdateItemInput
- type DbUpdateItemStructSetInput
- type EspDB
- func (d *EspDB) DbCreateItem(tableName string, v DBItem) error
- func (d *EspDB) DbDeleteItem(tableName string, query DBItem) error
- func (d *EspDB) DbGetItem(tableName string, query DBItem, out interface{}) error
- func (d *EspDB) DbQueryCountLoop(input DbQueryCountInput) (int32, error)
- func (d *EspDB) DbUpdateItem(input DbUpdateItemInput) (*dynamodb.UpdateItemOutput, error)
- func (d *EspDB) DbUpdateItemStructSet(input DbUpdateItemStructSetInput) (*dynamodb.UpdateItemOutput, error)
- type QueryWithLoopInput
Constants ¶
View Source
const DYNAMODB_BATCH_GET_LIMIT = 100
View Source
const DYNAMODB_BATCH_WRITE_LIMIT = 25
Variables ¶
This section is empty.
Functions ¶
func DbBatchGetItemLoop ¶
func DbBatchGetItemLoop[T any](input DbBatchGetItemLoopInput) ([]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:
- 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 }
- 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 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 ¶
DbCreateItem creates an item in the database using condition builder
func (*EspDB) DbDeleteItem ¶
DbDeleteItem deletes the items in 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 }
Click to show internal directories.
Click to hide internal directories.