Entity - An entity is the base data record or item that is stored in CanDB
Partition Key
Sort Key
Attribute Key
AttributeValue primitive options
AttributeValueCandy primitive options
An AttributeValue can be an array of AttributeValuePrimitive (tuple type)
An AttributeValue can be an array of any single one the primitive types (i.e. [Int])
An AttributeValue can be a map (tree) with text keys and values as AttributeValuePrimitive or AttributeValueArray
Attribute Value (Variant). Represents the value of a specific Attribute in an AttributeMap.
Key to Value mapping of all Entity attributes, stored in a Red-Black Tree
An Entity is the base data item or record that is stored in CanDB.
An entity consists of:
Partition Key (PK) - A text/string partition key identifier used to partition your data.
Sort Key (SK) - A text/string key identifier used to sort your data. Some examples might be a timestamp, an incrementing identifier, or a numerical value (turned into a string).
Attributes - Additional key/value data pertaining to the entity. All attribute keys are of type text/string, and attribute values are expressed as variants, allowing for the dynamic insertion of different types of attribute values.
The combination of an entity's partition key + sort key is unique in CanDB, meaning only one entity can have the exact same partition key and sort key.
public func createAttributeMapFromKVPairs(attributePairs : [(AttributeKey, AttributeValue)]) : AttributeMap
Creates an AttributeMap Red-Black Tree from an Array of (AttributeKey, AttributeValue)
public func createAttributeValueRBTreeFromKVPairs(attributePairs : [(Text, AttributeValueRBTreeValue)]) : RBT.Tree<Text, AttributeValueRBTreeValue>
Creates an AttributeValueRBTree from an array of key value pairs
public func updateAttributeMapWithKVPairs(attributeMap : AttributeMap, attributePairs : [(AttributeKey, AttributeValue)]) : AttributeMap
Updates an AttributeMap Red-Black Tree with an Array of (AttributeKey, AttributeValue)
public func getAttributeMapValueForKey(attributeMap : AttributeMap, k : AttributeKey) : ?AttributeValue
Gets a value from AttributeMap corresponding to a specific key
let { sk; attributes } = entity;
let userAttributeTree = getAttributeMapValueForKey(attributes, "userAttributes");
public func getAttributeValueRBTreeValue(attributeValueRBTree : RBT.Tree<Text, AttributeValueRBTreeValue>, k : Text) : ?AttributeValueRBTreeValue
Extracts a single value from an AttributeValueRBTree if it exists for the key provided
example
let { sk; attributes } = entity;
let userAttributeTree = getAttributeMapValueForKey(attributes, "userAttributes");
let userBirthday = switch(userAttributes) {
case (#tree(attrs)) { getAttributeValueRBTreeValue(attrs, "birthday") };
case _ { null };
};
public func extractKVPairsFromAttributeMap(attributeMap : AttributeMap) : [(AttributeKey, AttributeValue)]
Extracts all non-null kv pairs as an Array of (AttributeKey, AttributeValue) from the AttributeMap Red-Black Tree This is function to aid developers in extracting the AttributeKey and AttributeValue from the AttributeMaps for an Entity that is returned from CanDB
public func AtributeValueRBTreeToIter(attributeValueRBTree : RBT.Tree<Text, AttributeValueRBTreeValue>) : Iter.Iter<(Text, AttributeValueRBTreeValue)>
Helper method for extracting all key value pairs from an AttributeValueRBTree.
Returns an Iterator of all attributes in the inner AttributeValueRBTree
public func attributeMapsEqual(m1 : AttributeMap, m2 : AttributeMap) : Bool
Determines if two AttributeMaps are equal, ignoring deleted values in the AttributeMap Red-Black Tree
public func attributeMapToText(map : AttributeMap) : Text.Text
Mostly for testing/debugging purposes, generates a textual representation of the AttributeMap and its underlying Red-Black Tree
public func createEntity(
pk : PK,
sk : SK,
attributeMap : AttributeMap
) : Entity
Creates an Entity from a Partition Key, Sort Key, and Red-Black Tree mapping of Attributes
public func toText(e : Entity) : Text
Mostly for testing/debugging purposes, generates a textual representation of an entity
public func attributeValuesEqual(av1 : AttributeValue, av2 : AttributeValue) : Bool