Storage interface

存储提供程序的接口,用于存储和检索普通旧 JSON 对象。

方法

delete(string[])

从存储中删除存储项

read(string[])

从存储加载存储项

write(StoreItems)

将存储项保存到存储。

方法详细信息

delete(string[])

从存储中删除存储项

function delete(keys: string[]): Promise<void>

参数

keys

string[]

要从存储中删除的项键数组。

返回

Promise<void>

注解

以下示例从存储中删除对象:

await storage.delete(['botState']);

read(string[])

从存储加载存储项

function read(keys: string[]): Promise<StoreItems>

参数

keys

string[]

要从存储中读取的项键数组。

返回

Promise<StoreItems>

注解

此示例从存储读取单个对象:

const items = await storage.read(['botState']);
const state = items['botState'] || {};

write(StoreItems)

将存储项保存到存储。

function write(changes: StoreItems): Promise<void>

参数

changes
StoreItems

要写入存储的项的映射。

返回

Promise<void>

注解

此示例在修改对象后将对象写入存储:

state.topic = 'someTopic';
await storage.write({ 'botState': state });