| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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)
- 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%')
- }
- }
|