Skip to content

Creation and setup

MapPutOp: put single key-value pair

Creates or updates a single key-value pair in a map.

// Put a single key-value pair
_, err := client.Operate(nil, key,
as.MapPutOp(as.DefaultMapPolicy(), "profile", "name", "John Doe"),
)

MapPutItemsOp: put multiple key-value pairs

Creates or updates multiple key-value pairs in a single operation.

// Put multiple items at once
items := map[any]any{
"name": "John Doe",
"email": "john@example.com",
"age": 30,
"city": "San Francisco",
}
_, err := client.Operate(nil, key,
as.MapPutItemsOp(as.DefaultMapPolicy(), "profile", items),
)

MapCreateOp: create empty map

Creates an empty map with a specific policy. Useful when you want to ensure a map exists before operations.

// Create an ordered map
policy := as.NewMapPolicy(as.MapOrder.KEY_ORDERED, as.MapWriteMode.UPDATE)
_, err := client.Operate(nil, key,
as.MapCreateOp("leaderboard", policy, nil),
)

Map policies

UNORDERED (default): No specific order, fastest performance.

policy := as.DefaultMapPolicy() // UNORDERED

KEY_ORDERED: Map is ordered by key values.

policy := as.NewMapPolicy(as.MapOrder.KEY_ORDERED, as.MapWriteMode.UPDATE)

KEY_VALUE_ORDERED: Map is ordered by key, then by value.

policy := as.NewMapPolicy(as.MapOrder.KEY_VALUE_ORDERED, as.MapWriteMode.UPDATE)

Use KEY_ORDERED or KEY_VALUE_ORDERED when:

  • You need range queries by key.
  • You need to maintain sorted order.
  • You’re building leaderboards or rankings.
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?