| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 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<Pet> = new RDBMapper(Pet)
- petMapper2: RDBMapper<Test> = 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%')
- }
- }
|