Entity

Entity - An entity is the base data record or item that is stored in CanDB

type PK = Text

Partition Key

type SK = Text

Sort Key

type AttributeKey = Text

Attribute Key

type AttributeValuePrimitive = {#text : Text; #int : Int; #bool : Bool; #float : Float}

AttributeValue primitive options

type AttributeValueCandyPrimitive = {#candy : CandyTypes.CandyShared}

AttributeValueCandy primitive options

type AttributeValueBlob = {#blob : Blob}

type AttributeValueTuple = {#tuple : [AttributeValuePrimitive]}

An AttributeValue can be an array of AttributeValuePrimitive (tuple type)

type AttributeValueArray = {#arrayText : [Text]; #arrayInt : [Int]; #arrayBool : [Bool]; #arrayFloat : [Float]}

An AttributeValue can be an array of any single one the primitive types (i.e. [Int])

type AttributeValueRBTreeValue = AttributeValuePrimitive or AttributeValueBlob or AttributeValueTuple or AttributeValueArray or AttributeValueCandyPrimitive

type AttributeValueRBTree = {#tree : RBT.Tree<Text, AttributeValueRBTreeValue>}

An AttributeValue can be a map (tree) with text keys and values as AttributeValuePrimitive or AttributeValueArray

type AttributeValue = AttributeValuePrimitive or AttributeValueBlob or AttributeValueTuple or AttributeValueArray or AttributeValueRBTree or AttributeValueCandyPrimitive

Attribute Value (Variant). Represents the value of a specific Attribute in an AttributeMap.

type AttributeMap = RBT.Tree<AttributeKey, AttributeValue>

Key to Value mapping of all Entity attributes, stored in a Red-Black Tree

type Entity = { pk : PK; sk : SK; attributes : AttributeMap }

An Entity is the base data item or record that is stored in CanDB.

An entity consists of:

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 equal(e1 : Entity, e2 : Entity) : Bool

Determines if two Entities are equal

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