-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
127 lines (120 loc) · 4.66 KB
/
script.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var PeopleDBschema = {
db: 'PeopleDB',
v: 1,
upgrade: {
stores: [
{
name: 'humans',
opts: {keyPath: 'id', autoIncrement: true},
indices: [
{index: 'name', opts: {unique: false}},
{index: 'email', opts: {unique: true}}
]
},
{
name: 'aliens',
opts: {keyPath: 'id', autoIncrement: true},
indices: [
{index: 'name', opts: {unique: false}},
{index: 'email', opts: {unique: true}}
]
}
]
}
};
var PeopleDBHook = sdb.req(PeopleDBschema, function(PeopleDB){ // create database from schema
PeopleDBHook.tr(PeopleDB, ['humans', 'aliens'], 'readwrite')
.store('humans')
.put({id: 1, name: 'versions', email: '[email protected]', versions: [
{versionName: 'myOtherVersionName1', pubKey: 'myOtherPubKey1'}
] // we added "id" some that if db is created&pagerefreshed, it still "puts"
})
.get('[email protected]', function(item){
console.log('humans GOT ITEM', item);
})
.store('aliens')
.put({id: 1, name: 'versions', email: '[email protected]', versions: [
{versionName: 'myOtherVersionName1', pubKey: 'myOtherPubKey1'}
]
})
.get('[email protected]', function(item){
console.log('aliens GOT ITEM', item);
});
/*.cursor(function(data){
console.log('aliens data', data);
});*/
PeopleDBHook.tr(PeopleDB, ['humans', 'aliens'], 'readwrite')
.store('aliens')
.put({id: 1, name: 'versions', email: '[email protected]', versions: [
{versionName: 'myOtherVersionName1', pubKey: 'myOtherPubKey1'},
{versionName: 'myOtherVersionName2', pubKey: 'myOtherPubKey2'},
{versionName: 'myOtherVersionName3', pubKey: 'myOtherPubKey3'},
{versionName: 'myOtherVersionName4', pubKey: 'myOtherPubKey4'}
]
});
});
var PeopleDBHook = sdb.req('PeopleDB', function(PeopleDB){ // reopen database
PeopleDBHook.tr(PeopleDB, ['humans', 'aliens'], 'readwrite')
.store('aliens')
.put({id: 1, name: 'versions1', email: '[email protected]', versions: [
{versionName: 'myOtherVersionName1', pubKey: 'myOtherPubKey1'},
{versionName: 'myOtherVersionName2', pubKey: 'myOtherPubKey2'},
{versionName: 'myOtherVersionName3', pubKey: 'myOtherPubKey3'},
{versionName: 'myOtherVersionName4', pubKey: 'myOtherPubKey4'},
{versionName: 'myOtherVersionName5', pubKey: 'myOtherPubKey5'},
{versionName: 'myOtherVersionName6', pubKey: 'myOtherPubKey6'}
]
})
.put({id: 2, name: 'versions2', email: '[email protected]', versions: [
{versionName: 'myOtherVersionName1', pubKey: 'myOtherPubKey1'},
{versionName: 'myOtherVersionName2', pubKey: 'myOtherPubKey2'},
{versionName: 'myOtherVersionName3', pubKey: 'myOtherPubKey3'},
{versionName: 'myOtherVersionName4', pubKey: 'myOtherPubKey4'},
{versionName: 'myOtherVersionName5', pubKey: 'myOtherPubKey5'},
{versionName: 'myOtherVersionName6', pubKey: 'myOtherPubKey6'}
]
})
.put({id: 3, name: 'versions3', email: '[email protected]', versions: [
{versionName: 'myOtherVersionName1', pubKey: 'myOtherPubKey1'},
{versionName: 'myOtherVersionName2', pubKey: 'myOtherPubKey2'},
{versionName: 'myOtherVersionName3', pubKey: 'myOtherPubKey3'},
{versionName: 'myOtherVersionName4', pubKey: 'myOtherPubKey4'},
{versionName: 'myOtherVersionName5', pubKey: 'myOtherPubKey5'},
{versionName: 'myOtherVersionName6', pubKey: 'myOtherPubKey6'}
]
})
.put({id: 4, name: 'versions4', email: '[email protected]', versions: [
{versionName: 'myOtherVersionName1', pubKey: 'myOtherPubKey1'},
{versionName: 'myOtherVersionName2', pubKey: 'myOtherPubKey2'},
{versionName: 'myOtherVersionName3', pubKey: 'myOtherPubKey3'},
{versionName: 'myOtherVersionName4', pubKey: 'myOtherPubKey4'},
{versionName: 'myOtherVersionName5', pubKey: 'myOtherPubKey5'},
{versionName: 'myOtherVersionName6', pubKey: 'myOtherPubKey6'}
]
})
.cursor(function(data, cursor){
if(data.id <= 2){
console.log('@OpenCursor__:', data);
console.log('data.id === ', data.id, 'condition is: data.id <= 2');
cursor.continue();
}else{
console.log('@OpenCursor__: cursor stopped based upon callback conditions :-) ');
}
})
.cursor(function(data, cursor){
console.log('@OpenCursor 2');
console.log('@OpenCursor:', data);
cursor.continue();
}, 2)
.cursor(function(data, cursor){
console.log("@OpenCursor {bound: [1, 8], direction: 'prev'}");
console.log('@OpenCursor:', data);
cursor.continue();
}, {bound: [1, 8], direction: 'prev'})
.cursor(function(data, cursor){
console.log("@OpenCursor {bound: [x, x, boolean, boolean]}");
console.log('@OpenCursor:', data);
cursor.continue();
}, {bound: [1, 4, true, true]}); // {bound: [1, 8], direction: 'next'} 2
});
console.log('PeopleDBHook', PeopleDBHook, '\n\n');