#鸿蒙学习大百科#如何获取关系型数据库的relationalStore实例?

如何获取关系型数据库的relationalStore实例?

HarmonyOS
2024-10-23 11:27:56
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
耗子煨汁r
import { relationalStore } from '@kit.ArkData';
import { common } from '@kit.AbilityKit';

@Entry
@Component
struct Index {
  context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext
  @Provide store: relationalStore.RdbStore | undefined = undefined
  build() {
    Column() {
      Button("获取relationalStore实例").onClick(() => {
        relationalStore.getRdbStore(this.context, {
          name: "mydb.db",
          securityLevel: relationalStore.SecurityLevel.S1,
          // encrypt:true
        }, (err, store) => {
          if (err) {
            console.error(`Failed to get RdbStore. Code:${err.code}, message:${err.message}`);
            return;
          } else {
            console.info(`Succeeded in getting RdbStore.`);
            console.log("=======version:" + store.version)
          }
          this.store = store;

        })
      })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
}
分享
微博
QQ
微信
回复
2024-10-23 17:12:38
相关问题