Developing lightweight computation at the DSG edge

Commit fd650331 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[goclidote] Add function AntidoteAddArrayToSetInMapInMapInBucket

This function allows saving an array to a map which is inside a map
inside a bucket.
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <>
parent 7431530f
......@@ -150,6 +150,62 @@ func AntidoteAddArrayToSetInMapInBucket(bucketName string, mapName string, setNa
return !anyMissing
// AntidoteAddArrayToSetInMapInMapInBucket save an item to a set in a map in a map in a bucket
func AntidoteAddArrayToSetInMapInMapInBucket(bucketName string, outerMapName string, innerMapName string, setName string, itemArray []string, DatabaseHost string, DatabasePort int) bool {
funcName := "AntidoteAddArrayToSetInMapInMapInBucket"
client, err := antidoteclient.NewClient(antidoteclient.Host{Name: DatabaseHost, Port: DatabasePort})
errCheck(err, ERROR, "["+funcName+"]: Unable to create a new AntidoteDB go client")
defer client.Close()
tx, err := client.StartTransaction()
errCheck(err, ERROR, "["+funcName+"]: Unable to start a transaction using the go client")
bucket := antidoteclient.Bucket{Bucket: []byte(bucketName)}
outerMapKey := antidoteclient.Key(outerMapName)
innerMapKey := antidoteclient.Key(innerMapName)
setKey := antidoteclient.Key(setName)
for _, v := range itemArray {
err = bucket.Update(tx, antidoteclient.MapUpdate(outerMapKey,
antidoteclient.SetAdd(setKey, []byte(v)))))
errCheck(err, ERROR, fmt.Sprintf("["+funcName+"]: Unable to add value %s to set %s in map %s in map %s in bucket %s", v, setName, innerMapName, outerMapName, bucketName))
outerMapVal, err := bucket.ReadMap(tx, outerMapKey)
errCheck(err, ERROR, fmt.Sprintf("["+funcName+"]: Unable to read map %s in bucket %s", outerMapName, bucketName))
innerMapVal, err := outerMapVal.Map(innerMapKey)
errCheck(err, ERROR, fmt.Sprintf("["+funcName+"]: Unable to read map %s in map %s in bucket %s", innerMapName, outerMapName, bucketName))
setVal, err := innerMapVal.Set(setKey)
errCheck(err, ERROR, fmt.Sprintf("["+funcName+"]: Unable to read set %s in bucket %s", setName, bucketName))
err = tx.Commit()
errCheck(err, ERROR, "["+funcName+"]: Unable to commit transaction")
// Return true if all values belong now to the set (either they have been added now, or were there already)
anyMissing := false
for _, v := range itemArray {
thisFound := false
for _, w := range setVal {
if v == string(w) {
thisFound = true
if !thisFound {
anyMissing = true
// Return if all itemswere found
return !anyMissing
// AntidoteReadRegisterInBucket read a LWWW register in a bucket
func AntidoteReadRegisterInBucket(bucketName string, registerName string, DatabaseHost string, DatabasePort int) string {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment