|
1 | 1 | import IndexedDBP from '../src/main';
|
| 2 | +import {openDBTest, deleteDBTest} from '../test/example/db'; |
| 3 | +import {deleteOSTest, createOSTest, createIndexTest, deleteIndexTest} from '../test/example/objectStore'; |
| 4 | +import {simpleDOCount, simpleDOFind, simpleDOInsert, simpleDORemove, simpleDOUpdate, |
| 5 | + complexDOFind, complexDOInsert, complexDORemove, complexDOUpdate} from '../test/example/document'; |
2 | 6 |
|
| 7 | +// db test |
| 8 | +// (async () => { |
| 9 | +// const res1 = await openDBTest(); |
| 10 | +// console.log(res1); |
| 11 | +// const res2 = await deleteDBTest(); |
| 12 | +// console.log(res2); |
| 13 | +// })(); |
| 14 | + |
| 15 | +// objectStore test |
| 16 | +// (async () => { |
| 17 | +// const res3 = await createOSTest(); |
| 18 | +// console.log(res3); |
| 19 | +// const res4 = await deleteOSTest(); |
| 20 | +// console.log(res4); |
| 21 | +// const res5 = await createIndexTest(); |
| 22 | +// console.log(res5); |
| 23 | +// const res6 = await deleteIndexTest(); |
| 24 | +// console.log(res6); |
| 25 | +// })(); |
| 26 | + |
| 27 | +// document test |
3 | 28 | (async () => {
|
4 |
| - const mydb = new IndexedDBP({ |
5 |
| - name: 'testDB', |
6 |
| - }); |
7 |
| - await mydb.init(); |
8 |
| - console.log(mydb.db); |
9 |
| - mydb.dropDatabase(); |
10 |
| - console.log(mydb.db); |
11 |
| - return false; |
12 |
| - // deleteIndex |
13 |
| - // const isContainIndex = await mydb.$db.indexObjectStore.containIndex('time'); |
14 |
| - // if (mydb.containObjectStore('indexObjectStore') && isContainIndex) { |
15 |
| - // await mydb.$db.indexObjectStore.deleteIndex('time'); |
16 |
| - // } else if (mydb.containObjectStore('indexObjectStore')) { |
17 |
| - // await mydb.$db.indexObjectStore.createIndex('time', 'time', {unique: false, multiEntry: false}); |
18 |
| - // } |
| 29 | + const res1 = await simpleDOInsert(); |
| 30 | + console.log(res1); |
| 31 | + const res2 = await simpleDOCount(); |
| 32 | + console.log(res2); |
| 33 | + const res3 = await simpleDOFind(); |
| 34 | + console.log(res3); |
| 35 | + const res4 = await simpleDOUpdate(); |
| 36 | + console.log(res4); |
| 37 | + const res5 = await simpleDORemove(); |
| 38 | + console.log(res5); |
| 39 | + const res6 = await complexDOInsert(); |
| 40 | + console.log(res6); |
| 41 | + const res7 = await complexDOFind(); |
| 42 | + console.log(res7); |
| 43 | + const res8 = await complexDOUpdate(); |
| 44 | + console.log(res8); |
| 45 | + const res9 = await complexDORemove(); |
| 46 | + console.log(res9); |
| 47 | +})(); |
19 | 48 |
|
20 |
| - // create objectStore |
21 |
| - if (!mydb.containObjectStore('testObjectStore')) { |
22 |
| - await mydb.createObjectStore('testObjectStore'); |
23 |
| - } |
24 |
| - if (!mydb.containObjectStore('indexObjectStore')) { |
25 |
| - await mydb.createObjectStore('indexObjectStore', {keyPath: 'randomId'}); |
26 |
| - await mydb.$db.indexObjectStore.createIndex('time', 'time', {unique: false, multiEntry: false}); |
27 |
| - } |
| 49 | +// (async () => { |
| 50 | +// const mydb = new IndexedDBP({ |
| 51 | +// name: 'testDB', |
| 52 | +// }); |
| 53 | +// await mydb.init(); |
| 54 | +// // deleteIndex |
| 55 | +// // const isContainIndex = await mydb.$db.indexObjectStore.containIndex('time'); |
| 56 | +// // if (mydb.containObjectStore('indexObjectStore') && isContainIndex) { |
| 57 | +// // await mydb.$db.indexObjectStore.deleteIndex('time'); |
| 58 | +// // } else if (mydb.containObjectStore('indexObjectStore')) { |
| 59 | +// // await mydb.$db.indexObjectStore.createIndex('time', 'time', {unique: false, multiEntry: false}); |
| 60 | +// // } |
28 | 61 |
|
29 |
| - // delete ObjectStore |
30 |
| - // if (mydb.containObjectStore('testObjectStore2')) { |
31 |
| - // mydb.deleteObjectStore('testObjectStore2'); |
32 |
| - // } |
| 62 | +// // create objectStore |
| 63 | +// if (!mydb.containObjectStore('testObjectStore')) { |
| 64 | +// await mydb.createObjectStore('testObjectStore'); |
| 65 | +// } |
| 66 | +// if (!mydb.containObjectStore('indexObjectStore')) { |
| 67 | +// await mydb.createObjectStore('indexObjectStore', {keyPath: 'randomId'}); |
| 68 | +// await mydb.$db.indexObjectStore.createIndex('time', 'time', {unique: false, multiEntry: false}); |
| 69 | +// } |
33 | 70 |
|
34 |
| - // insert Data |
35 |
| - const count = await mydb.$db.testObjectStore.count({$lte: 2}); |
36 |
| - console.log(count); |
37 |
| - await mydb.$db.testObjectStore.insert({key1: 'hello', key2: 123, key3: true, key4: new Date()}); |
38 |
| - const rand1: number = Math.random(); |
39 |
| - const rand2: number = Math.random(); |
40 |
| - await mydb.$db.indexObjectStore.insert({randomId: rand1, time: new Date('2019/04/03')}); |
41 |
| - await mydb.$db.indexObjectStore.insert({randomId: rand2, time: new Date('2019/04/05')}); |
42 |
| - // find Data |
43 |
| - const res0 = await mydb.$db.testObjectStore.find(1); |
44 |
| - const res1 = await mydb.$db.indexObjectStore.find(new Date('2019/04/03'), 'time'); |
45 |
| - const res2 = await mydb.$db.indexObjectStore.find({$lte: rand2 , count: 5}); |
46 |
| - console.log(res0, res1); |
47 |
| - console.log(res2, rand2); |
48 |
| - // remove data |
49 |
| - // let resRemove = await mydb.$db.testObjectStore.remove({$lte: 5}); |
50 |
| - // console.log(resRemove); |
51 |
| - // update data |
52 |
| - // let resUpdate = await mydb.$db.testObjectStore.update({$lte: 10}, {test: 222}, {multi: true}); |
53 |
| - const resUpdate = await mydb.$db.testObjectStore.update(1, {test: 222}, {upsert: true}); |
54 |
| - console.log(resUpdate); |
55 |
| -})(); |
| 71 | +// // delete ObjectStore |
| 72 | +// // if (mydb.containObjectStore('testObjectStore2')) { |
| 73 | +// // mydb.deleteObjectStore('testObjectStore2'); |
| 74 | +// // } |
| 75 | + |
| 76 | +// // insert Data |
| 77 | +// const count = await mydb.$db.testObjectStore.count({$lte: 2}); |
| 78 | +// console.log(count); |
| 79 | +// await mydb.$db.testObjectStore.insert({key1: 'hello', key2: 123, key3: true, key4: new Date()}); |
| 80 | +// const rand1: number = Math.random(); |
| 81 | +// const rand2: number = Math.random(); |
| 82 | +// await mydb.$db.indexObjectStore.insert({randomId: rand1, time: new Date('2019/04/03')}); |
| 83 | +// await mydb.$db.indexObjectStore.insert({randomId: rand2, time: new Date('2019/04/05')}); |
| 84 | +// // find Data |
| 85 | +// const res0 = await mydb.$db.testObjectStore.find(1); |
| 86 | +// const res1 = await mydb.$db.indexObjectStore.find(new Date('2019/04/03'), 'time'); |
| 87 | +// const res2 = await mydb.$db.indexObjectStore.find({$lte: rand2 , count: 5}); |
| 88 | +// console.log(res0, res1); |
| 89 | +// console.log(res2, rand2); |
| 90 | +// // remove data |
| 91 | +// // let resRemove = await mydb.$db.testObjectStore.remove({$lte: 5}); |
| 92 | +// // console.log(resRemove); |
| 93 | +// // update data |
| 94 | +// // let resUpdate = await mydb.$db.testObjectStore.update({$lte: 10}, {test: 222}, {multi: true}); |
| 95 | +// const resUpdate = await mydb.$db.testObjectStore.update(1, {test: 222}, {upsert: true}); |
| 96 | +// console.log(resUpdate); |
| 97 | +// })(); |
0 commit comments