#鸿蒙学习大百科#键值型数据库如何获取指定key的value?

键值型数据库如何获取指定key的value?

HarmonyOS
2024-10-23 11:23:14
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
莫名瞄一眼
try {
  kvStore.put("name", "张三", (err) => {
    if (err !== undefined) {
      console.error(`Failed to put data. Code:${err.code},message:${err.message}`);
      return;
    }
    console.info('Succeeded in putting data.');
    kvStore = kvStore as distributedKVStore.SingleKVStore;
    kvStore.get("name", (err, data) => {
      if (err != undefined) {
        console.error(`Failed to get data. Code:${err.code},message:${err.message}`);
        return;
      }
      console.info(`Succeeded in getting data. Data:${data}`);
    });
  });
} catch (e) {
  let error = e as BusinessError;
  console.error(`Failed to get data. Code:${error.code},message:${error.message}`);
}
分享
微博
QQ
微信
回复
2024-10-23 15:36:59
相关问题