中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何获取关系型数据库的relationalStore实例?
微信扫码分享
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) } }