Skip to content

Commit 0389095

Browse files
committed
change to typescript
1 parent 422f0eb commit 0389095

15 files changed

+944
-1713
lines changed

.babelrc

-5
This file was deleted.

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
# indexDBP
2-
indexDB Promise Api, similiar to mongoDB api
2+
indexDBP is a simple way to use indexDB in browsers, base on Promise, similiar to mongoDB api.
3+
4+
```npm install indexdb-p```
5+
6+
#### Database Operation
7+
8+
9+
#### Collection Operation
10+
11+
12+
#### Document Operation
13+
14+
15+
#### Other Property
16+
17+

demo/index.js

-44
This file was deleted.

demo/index.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import IndexDBP from '../dist/indexDBP.js';
2+
3+
(async () => {
4+
const mydb = new IndexDBP({
5+
name: 'testDB',
6+
});
7+
await mydb.init();
8+
// deleteIndex
9+
// if (mydb.containObjectStore('indexObjectStore') && mydb.$db.indexObjectStore.containIndex('time')) {
10+
// await mydb.$db.indexObjectStore.deleteIndex('time')
11+
// }
12+
13+
// create objectStore
14+
if (!mydb.containObjectStore('testObjectStore')) {
15+
await mydb.createObjectStore('testObjectStore');
16+
}
17+
if (!mydb.containObjectStore('indexObjectStore')) {
18+
await mydb.createObjectStore('indexObjectStore', {keyPath: 'randomId'});
19+
await mydb.$db.indexObjectStore.createIndex('time', 'time', {unique: false, multiEntry: false});
20+
}
21+
22+
// delete ObjectStore
23+
// if (mydb.containObjectStore('testObjectStore2')) {
24+
// mydb.deleteObjectStore('testObjectStore2');
25+
// }
26+
27+
// insert Data
28+
await mydb.$db.testObjectStore.insert({key1: 'hello', key2: 123, key3: true, key4: new Date()});
29+
const rand1: number = Math.random();
30+
const rand2: number = Math.random();
31+
await mydb.$db.indexObjectStore.insert({randomId: rand1, time: new Date('2019/04/03')});
32+
await mydb.$db.indexObjectStore.insert({randomId: rand2, time: new Date('2019/04/05')});
33+
// find Data
34+
const res0 = await mydb.$db.testObjectStore.find(1);
35+
const res1 = await mydb.$db.indexObjectStore.find(new Date('2019/04/03'), 'time');
36+
const res2 = await mydb.$db.indexObjectStore.find({$lte: rand2 , count: 5});
37+
console.log(res0, res1);
38+
console.log(res2, rand2);
39+
// remove data
40+
// let resRemove = await mydb.$db.testObjectStore.remove({$lte: 5});
41+
// console.log(resRemove);
42+
// update data
43+
// let resUpdate = await mydb.$db.testObjectStore.update({$lte: 10}, {test: 222}, {multi: true});
44+
const resUpdate = await mydb.$db.testObjectStore.update(1, {test: 222}, {upsert: true});
45+
console.log(resUpdate);
46+
})();

dist/indexDBP.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)