Files
deskflow/static/dexieParse.js
2026-04-09 10:37:51 +08:00

50 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// dexie文档https://dexie.org/docs/API-Reference https://www.npmrc.cn/en/Dexie-js.html
class dexieDemo {
dbName = "jafar";
dbVersion = 1;
constructor(dbName, dbVersion) {
if (dbName) {
this.dbName = dbName;
}
if (dbVersion) {
this.dbVersion = dbVersion;
}
this.db = new Dexie(this.dbName);
this.db.version(this.dbVersion).stores(
{ tabName: "++id,nKey,nValue,nTime" }, // 创建表已有表则建立链接id为自增主键仅需要列举需要索引的字段即可
);
}
async get() {
const getLastData = await this.db.tabName.orderBy("id").last();
return getLastData;
}
async post(nKey, nValue) {
await this.db.tabName.add({
nKey: nKey,
nValue: nValue,
nTime: Date.now(),
});
const getLastData = await this.db.tabName.orderBy("id").last();
}
async put(id) {
await this.db.tabName.put({
id: 1,
userName: "zhangsan",
});
}
async del(id) {
await this.db.tabName.delete(id);
}
}
export const myDexie = new dexieDemo();
// document.querySelector("#goto_indexedDB_post").addEventListener("click",async () => {
// let nKey = Math.random()
// let nValue = new Date().getTime();
// await myDexieDemo.post( nKey,nValue );
// })
// document.querySelector("#goto_indexedDB_get").addEventListener("click",async () => {
// console.log( await myDexieDemo.get() )
// })