Skip to content

Map operations

Example: user with nested address map

// Store nested structure
userData := map[any]any{
"name": "John Doe",
"address": map[string]any{
"street": "123 Main St",
"city": "San Francisco",
"zip": "94102",
},
}
key, _ := as.NewKey("app", "users", "user123")
_, err := client.Operate(nil, key,
as.MapPutItemsOp(as.DefaultMapPolicy(), "user", userData),
)
// Get nested city
ctx := []*as.CDTContext{
as.CtxMapKey(as.StringValue("address")),
}
record, err := client.Operate(nil, key,
as.MapGetByKeyOp("user", "city", as.MapReturnType.VALUE, ctx...),
)
results := record.Bins["user"].(map[any]any)
city := results["city"].(string)
fmt.Println("City:", city) // Output: City: San Francisco

Example: multi-level configuration

// Store nested configuration
config := map[any]any{
"database": map[string]any{
"primary": map[string]any{
"host": "db1.example.com",
"port": 3306,
},
"replica": map[string]any{
"host": "db2.example.com",
"port": 3306,
},
},
}
key, _ := as.NewKey("app", "config", "production")
_, err := client.Operate(nil, key,
as.MapPutItemsOp(as.DefaultMapPolicy(), "config", config),
)
// Get primary database host
ctx := []*as.CDTContext{
as.CtxMapKey(as.StringValue("database")),
as.CtxMapKey(as.StringValue("primary")),
}
record, err := client.Operate(nil, key,
as.MapGetByKeyOp("config", "host", as.MapReturnType.VALUE, ctx...),
)
host := record.Bins["config"].(string)
fmt.Println("Primary DB host:", host)
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?