/
d3_indexdb2.html
59 lines (29 loc) · 1.5 KB
/
d3_indexdb2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<html>
<body>
<script>
function appDB(databaseName,objectStoreName,objectStoreKey){
this.databaseName = databaseName;
this.objectStoreName = objectStoreName;
this.objectStoreKey = objectStoreKey;
this.databaseVersion = 1;
this.configureIndexedDb = function (){
var that = this;
var request = window.indexedDB.open(that.databaseName, that.databaseVersion);
// debugger;
request.onupgradeneeded = function(event){
var db = event.target.result;
var objectStore = db.createObjectStore(that.objectStoreName,{keyPath: that.objectStoreKey});
console.log(`${that.objectStoreName} Object Store Successfully created with version number ${that.databaseVersion}`);
};
request.onsuccess = function(event){
db = event.target.result;
console.log(`${that.objectStoreName} Object Store in ${that.databaseName} successfully opened with version number ${that.databaseVersion}`);
};
request.onerror = function(event) {
alert("Why didn't you allow my web app to use IndexedDB?!"+event.target.errorCode);
};
}
}
</script>
</body>
</html>