import { Pet, RDBMapper, RelationalStoreUtils, Test } from 'basic'; @Component export struct ThirdView { @State list: Test[] = [] @State list2: Pet[] = [] id1: number = 0 id2: number = 0 petMapper: RDBMapper = new RDBMapper(Pet) petMapper2: RDBMapper = new RDBMapper(Test) build() { Column() { Row() { Button('测试新增') .onClick(() => { RelationalStoreUtils.insert(Test, { name: 'test1', age: 18 }, (id) => { console.log('insert success'); this.id1 = id let list = RelationalStoreUtils.getListSync(Test) this.list = list console.log('list:', JSON.stringify(list)) }) }) Button('测试修改') .onClick(() => { RelationalStoreUtils.updateItemById(Test, { id: this.id1, name: '测试1修改', age: 20 }, () => { console.log('insert success'); let list = RelationalStoreUtils.getListSync(Test) this.list = list console.log('list:', JSON.stringify(list)) }) }) Button('测试删除') .onClick(() => { RelationalStoreUtils.deleteItemById(Test, this.id1) console.log('insert success'); let list = RelationalStoreUtils.getListSync(Test) this.list = list console.log('list:', JSON.stringify(list)) }) } .width('100%') .justifyContent(FlexAlign.SpaceAround) .margin({ bottom: 30 }) Text(JSON.stringify(this.list)) .font({ size: 20 }) .margin({ bottom: 20 }) Row() { Button('测试新增2') .onClick(() => { this.petMapper.insert({ name: 'test1', tag: '标签' }, (id: number) => { console.log('insert success'); this.id2 = id let list = this.petMapper.getListSync() this.list2 = list console.log('list:', JSON.stringify(list)) }) }) Button('测试修改2') .onClick(() => { this.petMapper.updateItemById({ id: this.id2, name: '测试1修改', tag: '标签2' }, () => { console.log('insert success'); let list = this.petMapper.getListSync() this.list2 = list console.log('list:', JSON.stringify(list)) }) }) Button('测试删除2') .onClick(() => { this.petMapper.deleteItemByIdSync(this.id2) console.log('insert success'); let list = this.petMapper.getListSync() this.list2 = list console.log('list:', JSON.stringify(list)) }) } .width('100%') .justifyContent(FlexAlign.SpaceAround) .margin({ bottom: 30 }) Text(JSON.stringify(this.list2)) .font({ size: 20 }) .margin({ bottom: 20 }) } .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) .height('100%') .width('100%') } }