|
@@ -4,14 +4,17 @@ import { Pet, RDBMapper, RelationalStoreUtils, Test } from "basic";
|
|
|
export struct ThirdView {
|
|
export struct ThirdView {
|
|
|
@State list: Test[] = []
|
|
@State list: Test[] = []
|
|
|
@State list2: Pet[] = []
|
|
@State list2: Pet[] = []
|
|
|
|
|
+ id1:number = 0
|
|
|
|
|
+ id2:number = 0
|
|
|
petMapper:RDBMapper<Pet> = new RDBMapper(Pet)
|
|
petMapper:RDBMapper<Pet> = new RDBMapper(Pet)
|
|
|
build() {
|
|
build() {
|
|
|
Column() {
|
|
Column() {
|
|
|
Row() {
|
|
Row() {
|
|
|
Button('测试新增')
|
|
Button('测试新增')
|
|
|
.onClick(() => {
|
|
.onClick(() => {
|
|
|
- RelationalStoreUtils.insert(Test, { name: 'test1', age: 18 }, () => {
|
|
|
|
|
|
|
+ RelationalStoreUtils.insert(Test, { name: 'test1', age: 18 }, (id) => {
|
|
|
console.log('insert success');
|
|
console.log('insert success');
|
|
|
|
|
+ this.id1 = id
|
|
|
let list = RelationalStoreUtils.getListSync(Test)
|
|
let list = RelationalStoreUtils.getListSync(Test)
|
|
|
this.list = list
|
|
this.list = list
|
|
|
console.log('list:', JSON.stringify(list))
|
|
console.log('list:', JSON.stringify(list))
|
|
@@ -20,7 +23,7 @@ export struct ThirdView {
|
|
|
|
|
|
|
|
Button('测试修改')
|
|
Button('测试修改')
|
|
|
.onClick(() => {
|
|
.onClick(() => {
|
|
|
- RelationalStoreUtils.updateItemById(Test, { id: 1, name: '测试1修改', age: 20 }, () => {
|
|
|
|
|
|
|
+ RelationalStoreUtils.updateItemById(Test, { id: this.id1, name: '测试1修改', age: 20 }, () => {
|
|
|
console.log('insert success');
|
|
console.log('insert success');
|
|
|
let list = RelationalStoreUtils.getListSync(Test)
|
|
let list = RelationalStoreUtils.getListSync(Test)
|
|
|
this.list = list
|
|
this.list = list
|
|
@@ -29,7 +32,7 @@ export struct ThirdView {
|
|
|
})
|
|
})
|
|
|
Button('测试删除')
|
|
Button('测试删除')
|
|
|
.onClick(() => {
|
|
.onClick(() => {
|
|
|
- RelationalStoreUtils.deleteItemById(Test, 1)
|
|
|
|
|
|
|
+ RelationalStoreUtils.deleteItemById(Test, this.id1)
|
|
|
console.log('insert success');
|
|
console.log('insert success');
|
|
|
let list = RelationalStoreUtils.getListSync(Test)
|
|
let list = RelationalStoreUtils.getListSync(Test)
|
|
|
this.list = list
|
|
this.list = list
|
|
@@ -47,8 +50,9 @@ export struct ThirdView {
|
|
|
Row() {
|
|
Row() {
|
|
|
Button('测试新增2')
|
|
Button('测试新增2')
|
|
|
.onClick(() => {
|
|
.onClick(() => {
|
|
|
- this.petMapper.insert( { name: 'test1', tag: '标签' }, () => {
|
|
|
|
|
|
|
+ this.petMapper.insert( { name: 'test1', tag: '标签' }, (id:number) => {
|
|
|
console.log('insert success');
|
|
console.log('insert success');
|
|
|
|
|
+ this.id2 = id
|
|
|
let list = this.petMapper.getListSync()
|
|
let list = this.petMapper.getListSync()
|
|
|
this.list2 = list
|
|
this.list2 = list
|
|
|
console.log('list:', JSON.stringify(list))
|
|
console.log('list:', JSON.stringify(list))
|
|
@@ -57,7 +61,7 @@ export struct ThirdView {
|
|
|
|
|
|
|
|
Button('测试修改2')
|
|
Button('测试修改2')
|
|
|
.onClick(() => {
|
|
.onClick(() => {
|
|
|
- this.petMapper.updateItemById({ id: 1, name: '测试1修改',tag: '标签2' }, () => {
|
|
|
|
|
|
|
+ this.petMapper.updateItemById({ id: this.id2, name: '测试1修改',tag: '标签2' }, () => {
|
|
|
console.log('insert success');
|
|
console.log('insert success');
|
|
|
let list = this.petMapper.getListSync()
|
|
let list = this.petMapper.getListSync()
|
|
|
this.list2= list
|
|
this.list2= list
|
|
@@ -66,7 +70,7 @@ export struct ThirdView {
|
|
|
})
|
|
})
|
|
|
Button('测试删除2')
|
|
Button('测试删除2')
|
|
|
.onClick(() => {
|
|
.onClick(() => {
|
|
|
- this.petMapper.deleteItemByIdSync(1)
|
|
|
|
|
|
|
+ this.petMapper.deleteItemByIdSync(this.id2)
|
|
|
console.log('insert success');
|
|
console.log('insert success');
|
|
|
let list = this.petMapper.getListSync()
|
|
let list = this.petMapper.getListSync()
|
|
|
this.list2 = list
|
|
this.list2 = list
|