项目备份
This commit is contained in:
49
static/dexieParse.js
Normal file
49
static/dexieParse.js
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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() )
|
||||
// })
|
||||
Reference in New Issue
Block a user