Revision 11614403
Von Sven Schöling vor mehr als 3 Jahren hinzugefügt
js/kivi.FileDB.js | ||
---|---|---|
42 | 42 |
}; |
43 | 43 |
|
44 | 44 |
ns.store_image = function (blob, filename, success) { |
45 |
let put_request = ns.open_store("readwrite").add(blob, filename); |
|
45 |
ns.open_rw_store((store) => { |
|
46 |
let put_request = store.add(blob, filename); |
|
46 | 47 |
|
47 |
put_request.onsuccess = success; |
|
48 |
put_request.on_error = ns.onerror; |
|
48 |
put_request.onsuccess = success; |
|
49 |
put_request.on_error = ns.onerror; |
|
50 |
}); |
|
49 | 51 |
}; |
50 | 52 |
|
51 | 53 |
ns.retrieve_image = function(key, success) { |
52 |
let get_request = ns.open_store().objectStore(store).get(key); |
|
54 |
ns.open_ro_store((store) => { |
|
55 |
let get_request = store.get(key); |
|
53 | 56 |
|
54 |
get_request.onsuccess = success; |
|
55 |
get_request.onerror = request.onerror; |
|
57 |
get_request.onsuccess = success; |
|
58 |
get_request.onerror = request.onerror; |
|
59 |
}); |
|
56 | 60 |
}; |
57 | 61 |
|
58 | 62 |
ns.retrieve_all = function(success) { |
59 |
let request = ns.open_store().getAll(); |
|
60 |
request.onsuccess = (event) => { success(event.target.result); }; |
|
61 |
request.onerror = ns.error; |
|
63 |
ns.open_ro_store((store) => { |
|
64 |
let request = store.getAll(); |
|
65 |
request.onsuccess = (event) => { success(event.target.result); }; |
|
66 |
request.onerror = ns.error; |
|
67 |
}); |
|
62 | 68 |
}; |
63 | 69 |
|
64 | 70 |
ns.retrieve_all_keys = function(success) { |
65 |
let request = ns.open_store().getAllKeys(); |
|
66 |
request.onsuccess = (event) => { success(event.target.result); }; |
|
67 |
request.onerror = ns.error; |
|
71 |
ns.open_ro_store((store) => { |
|
72 |
let request = store.getAllKeys(); |
|
73 |
request.onsuccess = (event) => { success(event.target.result); }; |
|
74 |
request.onerror = ns.error; |
|
75 |
}); |
|
68 | 76 |
}; |
69 | 77 |
|
70 | 78 |
ns.delete_all= function() { |
... | ... | |
74 | 82 |
}; |
75 | 83 |
|
76 | 84 |
ns.delete_key= function(key, success) { |
77 |
let request = ns.open_store("readwrite").delete(key); |
|
78 |
request.onsuccess = (event) => { if (success) success(event.target.result); }; |
|
79 |
request.onerror = ns.error; |
|
85 |
ns.open_rw_store((store) => { |
|
86 |
let request = store.delete(key); |
|
87 |
request.onsuccess = (event) => { if (success) success(event.target.result); }; |
|
88 |
request.onerror = ns.error; |
|
89 |
}); |
|
90 |
}; |
|
91 |
|
|
92 |
ns.open_rw_store = function(callback) { |
|
93 |
if (db && db_version == db.version) { |
|
94 |
callback(ns.open_store("readwrite")); |
|
95 |
} else { |
|
96 |
request.aftersuccess.push(() => callback(ns.open_store("readwrite"))); |
|
97 |
} |
|
98 |
}; |
|
99 |
|
|
100 |
ns.open_ro_store = function(callback) { |
|
101 |
if (db && db_version == db.version) { |
|
102 |
callback(ns.open_store("readonly")); |
|
103 |
} else { |
|
104 |
request.aftersuccess.push(() => callback(ns.open_store("readonly"))); |
|
105 |
} |
|
80 | 106 |
}; |
81 | 107 |
|
82 |
ns.open_store = function(mode = "readonly") {
|
|
108 |
ns.open_store = function(mode = "readonly") { |
|
83 | 109 |
return db.transaction([store], mode).objectStore(store); |
84 | 110 |
}; |
85 | 111 |
|
Auch abrufbar als: Unified diff
FileDB: async db.open fixes
Dadurch, dass das komplette Interface asynchron ist, muss jeder Request an
die Datenbank potentiell verzögert werden bis eine Verbindung steht.