-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.class.js
67 lines (52 loc) · 1.81 KB
/
db.class.js
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
60
61
62
63
64
65
66
67
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("WeTrust", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("tpoExamen", { keyPath: "id",autoIncrement: 'true' });
var index = store.createIndex("nombre", "nombre", { unique: true });
};
open.onsuccess = function() {
// Start a new transaction
var db = open.result;
var tx = db.transaction("tpoExamen", "readwrite");
var store = tx.objectStore("tpoExamen");
var index = store.index("nombre");
// Add some data
store.put({id: 1, name: "John"});
store.put({id: 2, name: "Bob"});
// Query the data
var getJohn = store.getAll();
getJohn.onsuccess = function() {
for (i = 0; i < getJohn.result.length; i++) {
console.log(getJohn.result[i].name);
}
};
// Close the db when the transaction is done
tx.oncomplete = function() {
db.close();
};
}
async function loadTpoExamen(){
// Start a new transaction
var db = await open.result;
var tx = await db.transaction("tpoExamen", "readwrite");
var store = await tx.objectStore("tpoExamen");
var index = await store.index("nombre");
// Query the data
var getJohn = await store.getAll();
getJohn.onsuccess = function() {
return getJohn.result;
};
// Close the db when the transaction is done
tx.oncomplete = function() {
db.close();
};
}
async function añadir2(x) {
var a = await resolverDespuesDe2Segundos(20);
var b = await resolverDespuesDe2Segundos(30);
return x + a + b;
}