fix indexeddb
This commit is contained in:
parent
8fb517c107
commit
d6a473f6e9
@ -4,32 +4,10 @@ class Database {
|
||||
private dbName: string = '4nk';
|
||||
private dbVersion: number = 1;
|
||||
private storeDefinitions = {
|
||||
// SpClient: {
|
||||
// name: "sp_client",
|
||||
// options: {},
|
||||
// indices: []
|
||||
// },
|
||||
// SpOutputs: {
|
||||
// name: "sp_outputs",
|
||||
// options: {'autoIncrement': true},
|
||||
// indices: [{
|
||||
// name: 'by_wallet_fingerprint',
|
||||
// keyPath: 'wallet_fingerprint',
|
||||
// options: {
|
||||
// 'unique': false
|
||||
// }
|
||||
// }]
|
||||
// },
|
||||
AnkUser: {
|
||||
name: "user",
|
||||
options: {'keyPath': 'pre_id'},
|
||||
indices: [{
|
||||
name: 'by_process',
|
||||
keyPath: 'process',
|
||||
options: {
|
||||
'unique': false
|
||||
}
|
||||
}]
|
||||
indices: []
|
||||
},
|
||||
AnkSession: {
|
||||
name: "session",
|
||||
@ -92,11 +70,11 @@ class Database {
|
||||
});
|
||||
}
|
||||
|
||||
public getDb(): IDBDatabase {
|
||||
public async getDb(): Promise<IDBDatabase> {
|
||||
if (!this.db) {
|
||||
throw new Error("Database not initialized");
|
||||
await this.init();
|
||||
}
|
||||
return this.db;
|
||||
return this.db!;
|
||||
}
|
||||
|
||||
public getStoreList(): {[key: string]: string} {
|
||||
|
@ -39,7 +39,7 @@ class Services {
|
||||
let isNew = false;
|
||||
try {
|
||||
const indexedDB = await IndexedDB.getInstance();
|
||||
const db = indexedDB.getDb();
|
||||
const db = await indexedDB.getDb();
|
||||
let userListObject = await indexedDB.getAll<User>(db, indexedDB.getStoreList().AnkUser);
|
||||
if (userListObject.length == 0) {
|
||||
isNew = true;
|
||||
@ -97,7 +97,7 @@ class Services {
|
||||
|
||||
try {
|
||||
const indexedDb = await IndexedDB.getInstance();
|
||||
const db = indexedDb.getDb();
|
||||
const db = await indexedDb.getDb();
|
||||
await indexedDb.writeObject(db, indexedDb.getStoreList().AnkUser, user, null);
|
||||
} catch (error) {
|
||||
console.error("Failed to write user object :", error);
|
||||
@ -243,7 +243,7 @@ class Services {
|
||||
public async addProcess(process: Process): Promise<void> {
|
||||
try {
|
||||
const indexedDB = await IndexedDB.getInstance();
|
||||
const db = indexedDB.getDb();
|
||||
const db = await indexedDB.getDb();
|
||||
await indexedDB.writeObject(db, indexedDB.getStoreList().AnkProcess, process, null);
|
||||
} catch (error) {
|
||||
console.log('addProcess failed: ',error);
|
||||
@ -253,7 +253,7 @@ class Services {
|
||||
public async getAllProcess(): Promise<Process[]> {
|
||||
try {
|
||||
const indexedDB = await IndexedDB.getInstance();
|
||||
const db = indexedDB.getDb();
|
||||
const db = await indexedDB.getDb();
|
||||
let processListObject = await indexedDB.getAll<Process>(db, indexedDB.getStoreList().AnkProcess);
|
||||
return processListObject;
|
||||
} catch (error) {
|
||||
@ -280,7 +280,7 @@ class Services {
|
||||
let userProcessList: Process[] = [];
|
||||
try {
|
||||
const indexedDB = await IndexedDB.getInstance();
|
||||
const db = indexedDB.getDb();
|
||||
const db = await indexedDB.getDb();
|
||||
user = await indexedDB.getObject<User>(db, indexedDB.getStoreList().AnkUser, pre_id);
|
||||
} catch (error) {
|
||||
console.error('getAllUserProcess failed: ',error);
|
||||
@ -304,7 +304,7 @@ class Services {
|
||||
public async getProcessByName(name: string): Promise<Process | null> {
|
||||
console.log('getProcessByName name: '+name);
|
||||
const indexedDB = await IndexedDB.getInstance();
|
||||
const db = indexedDB.getDb();
|
||||
const db = await indexedDB.getDb();
|
||||
const process = await indexedDB.getFirstMatchWithIndex<Process>(db, indexedDB.getStoreList().AnkProcess, 'by_name', name);
|
||||
console.log('getProcessByName process: '+process);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user