中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何获取KvStore键值性数据库实例?
微信扫码分享
let kvStore: distributedKVStore.SingleKVStore | undefined = undefined; try { const options: distributedKVStore.Options = { createIfMissing: true, encrypt: false, backup: false, autoSync: false, // kvStoreType不填时,默认创建多设备协同数据库 kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION, // 多设备协同数据库:kvStoreType: distributedKVStore.KVStoreType.DEVICE_COLLABORATION, securityLevel: distributedKVStore.SecurityLevel.S1 }; kvManager.getKVStore<distributedKVStore.SingleKVStore>('storeId', options, (err, store: distributedKVStore.SingleKVStore) => { if (err) { console.error(`Failed to get KVStore: Code:${err.code},message:${err.message}`); return; } console.info('Succeeded in getting KVStore.'); kvStore = store; // 请确保获取到键值数据库实例后,再进行相关数据操作 }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code:${error.code},message:${error.message}`); } if (kvStore !== undefined) { kvStore = kvStore as distributedKVStore.SingleKVStore; //进行后续操作 //... }