|
@@ -1,8 +1,10 @@
|
|
|
-import { RelationalStoreUtils, Test } from "basic";
|
|
|
|
|
|
|
+import { Pet, RDBMapper, RelationalStoreUtils, Test } from "basic";
|
|
|
|
|
|
|
|
@Component
|
|
@Component
|
|
|
export struct ThirdView {
|
|
export struct ThirdView {
|
|
|
@State list: Test[] = []
|
|
@State list: Test[] = []
|
|
|
|
|
+ @State list2: Pet[] = []
|
|
|
|
|
+ testMapper:RDBMapper<Pet> = new RDBMapper(Pet)
|
|
|
build() {
|
|
build() {
|
|
|
Column() {
|
|
Column() {
|
|
|
Row() {
|
|
Row() {
|
|
@@ -42,6 +44,43 @@ export struct ThirdView {
|
|
|
.font({ size: 20 })
|
|
.font({ size: 20 })
|
|
|
.margin({ bottom: 20 })
|
|
.margin({ bottom: 20 })
|
|
|
|
|
|
|
|
|
|
+ Row() {
|
|
|
|
|
+ Button('测试新增2')
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.testMapper.insert( { name: 'test1', tag: '标签' }, () => {
|
|
|
|
|
+ console.log('insert success');
|
|
|
|
|
+ let list = this.testMapper.getListSync()
|
|
|
|
|
+ this.list2 = list
|
|
|
|
|
+ console.log('list:', JSON.stringify(list))
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ Button('测试修改2')
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.testMapper.updateItemById({ id: 1, name: '测试1修改',tag: '标签2' }, () => {
|
|
|
|
|
+ console.log('insert success');
|
|
|
|
|
+ let list = this.testMapper.getListSync()
|
|
|
|
|
+ this.list2= list
|
|
|
|
|
+ console.log('list:', JSON.stringify(list))
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ Button('测试删除2')
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.testMapper.deleteItemByIdSync(1)
|
|
|
|
|
+ console.log('insert success');
|
|
|
|
|
+ let list = this.testMapper.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)
|
|
.justifyContent(FlexAlign.Center)
|
|
|
.alignItems(HorizontalAlign.Center)
|
|
.alignItems(HorizontalAlign.Center)
|