store.put()
写入一个键。调用方必须明确选择无条件覆盖、仅首次创建或按版本更新。
Syntax
const result = await host.store.put(key, value, condition);
Parameters
| 参数 | 类型 | 说明 |
|---|---|---|
key |
string |
有界、规范化的应用键 |
value |
ByteSource |
无类型字节值 |
condition |
"any" | "absent" | { version: u64 } |
必填并发前置条件 |
Return value
{ version: u64 }:成功后的新版本。
Examples
const old = await host.store.get('counter');
const next = encode((old ? decode(old.value) : 0) + 1);
await host.store.put('counter', next, old ? { version: old.version } : 'absent');
Errors
特有错误:denied、invalid-key、conflict、quota-exceeded、version-exhausted、limit-exceeded。冲突不得覆盖现值。
Requirements
- 能力:
host:store.put - 用户激活:不需要
- 信任档位:green