Skip to content

Commit fd86c3f

Browse files
committed
use native relationalStore api
1 parent 81ea10e commit fd86c3f

File tree

6 files changed

+251
-162
lines changed

6 files changed

+251
-162
lines changed

entry/oh-package-lock.json5

Lines changed: 1 addition & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entry/oh-package.json5

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
"license": "",
88
"dependencies": {
99
"libentry.so": "file:./src/main/cpp/types/libentry",
10-
"@liushengyi/smartdb": "^4.0.1"
1110
}
1211
}

entry/src/main/ets/InputMethodExtensionAbility/model/pasteboard/PasteboardController.ets

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Context } from '@kit.AbilityKit'
22
import { BusinessError, pasteboard } from '@kit.BasicServicesKit'
3-
import sql from '@liushengyi/smartdb'
43
import { PasteboardDao } from './PasteboardDao'
5-
import { PasteboardDatabase } from './PasteboardDatabase'
4+
import { PasteboardDatabase, rdbStore } from './PasteboardDatabase'
65
import { PasteboardEntry } from './PasteboardEntry'
76
import { HashSet } from '@kit.ArkTS'
87
import { StrUtil } from '../../../utils/StrUtil'
@@ -63,15 +62,18 @@ export class PasteboardController {
6362
}
6463

6564
async get(id: number): Promise<PasteboardEntry> {
66-
return await this.psbDao!.getById(id)
65+
const entry = await this.psbDao!.getById(id)
66+
return entry
6767
}
6868

6969
async haveUnpinned(): Promise<boolean> {
70-
return await this.psbDao!.haveUnpinned()
70+
const result = await this.psbDao!.haveUnpinned()
71+
return result
7172
}
7273

73-
async allEntries(): Promise<Array<PasteboardEntry>> {
74-
return await this.psbDao!.allEntries()
74+
async getEntries(offset: number, limit: number): Promise<Array<PasteboardEntry>> {
75+
const entries = await this.psbDao!.getEntries(offset, limit)
76+
return entries
7577
}
7678

7779
async pin(id: number) {
@@ -124,7 +126,6 @@ export class PasteboardController {
124126
await this.updateItemCount()
125127
}
126128

127-
@sql.Transactional()
128129
private async insertEntry(entry: PasteboardEntry): Promise<PasteboardEntry> {
129130
const rowId = await this.psbDao!.insert(entry)
130131
if (!rowId) {
@@ -145,14 +146,20 @@ export class PasteboardController {
145146
return
146147
}
147148
try {
148-
const existed = await pasteboardController.psbDao!.find(entry.text, entry.sensitive)
149+
const existed = await this.psbDao!.find(entry.text, entry.sensitive)
149150
if (existed) {
150151
const copy = existed
151152
copy.timestamp = entry.timestamp
152-
pasteboardController.updateLastEntry(copy)
153-
await pasteboardController.psbDao!.updateTime(existed.id, entry.timestamp)
153+
this.updateLastEntry(copy)
154+
await this.psbDao!.updateTime(existed.id, entry.timestamp)
154155
} else {
155-
const insertedEntry = await pasteboardController.insertEntry(entry)
156+
let temp: PasteboardEntry | undefined = undefined
157+
rdbStore?.createTransaction().then(async () => {
158+
const rowId = await this.psbDao!.insert(entry)
159+
// TODO: removeOutdated()
160+
temp = await this.psbDao?.getByRowId(rowId)
161+
})
162+
const insertedEntry = temp ? temp : entry
156163
console.debug('get entry text: ' + insertedEntry.text)
157164
pasteboardController.updateLastEntry(insertedEntry)
158165
pasteboardController.updateItemCount()

0 commit comments

Comments
 (0)