doc.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. Package expression provides types and functions to create Amazon DynamoDB
  3. Expression strings, ExpressionAttributeNames maps, and ExpressionAttributeValues
  4. maps.
  5. Using the Package
  6. The package represents the various DynamoDB Expressions as structs named
  7. accordingly. For example, ConditionBuilder represents a DynamoDB Condition
  8. Expression, an UpdateBuilder represents a DynamoDB Update Expression, and so on.
  9. The following example shows a sample ConditionExpression and how to build an
  10. equilvalent ConditionBuilder
  11. // Let :a be an ExpressionAttributeValue representing the string "No One You
  12. // Know"
  13. condExpr := "Artist = :a"
  14. condBuilder := expression.Name("Artist").Equal(expression.Value("No One You Know"))
  15. In order to retrieve the formatted DynamoDB Expression strings, call the getter
  16. methods on the Expression struct. To create the Expression struct, call the
  17. Build() method on the Builder struct. Because some input structs, such as
  18. QueryInput, can have multiple DynamoDB Expressions, multiple structs
  19. representing various DynamoDB Expressions can be added to the Builder struct.
  20. The following example shows a generic usage of the whole package.
  21. filt := expression.Name("Artist").Equal(expression.Value("No One You Know"))
  22. proj := expression.NamesList(expression.Name("SongTitle"), expression.Name("AlbumTitle"))
  23. expr, err := expression.NewBuilder().WithFilter(filt).WithProjection(proj).Build()
  24. if err != nil {
  25. fmt.Println(err)
  26. }
  27. input := &dynamodb.ScanInput{
  28. ExpressionAttributeNames: expr.Names(),
  29. ExpressionAttributeValues: expr.Values(),
  30. FilterExpression: expr.Filter(),
  31. ProjectionExpression: expr.Projection(),
  32. TableName: aws.String("Music"),
  33. }
  34. The ExpressionAttributeNames and ExpressionAttributeValues member of the input
  35. struct must always be assigned when using the Expression struct because all item
  36. attribute names and values are aliased. That means that if the
  37. ExpressionAttributeNames and ExpressionAttributeValues member is not assigned
  38. with the corresponding Names() and Values() methods, the DynamoDB operation will
  39. run into a logic error.
  40. */
  41. package expression