Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
ef141659e2 | |||
0b3dec53dd |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/webstore",
|
"name": "@pushrocks/webstore",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/webstore",
|
"name": "@pushrocks/webstore",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "high performance storage in the browser using indexed db",
|
"description": "high performance storage in the browser using indexed db",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -5,7 +5,8 @@ let testWebstore: webstore.WebStore;
|
|||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
testWebstore = new webstore.WebStore({
|
testWebstore = new webstore.WebStore({
|
||||||
storeName: 'mystore'
|
dbName: 'mytestdb',
|
||||||
|
storeName: 'myteststore'
|
||||||
});
|
});
|
||||||
expect(testWebstore).to.be.instanceOf(webstore.WebStore);
|
expect(testWebstore).to.be.instanceOf(webstore.WebStore);
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as plugins from './webstore.plugins';
|
import * as plugins from './webstore.plugins';
|
||||||
|
|
||||||
export interface IWebStoreOptions {
|
export interface IWebStoreOptions {
|
||||||
|
dbName: string;
|
||||||
storeName: string;
|
storeName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,30 +16,30 @@ export class WebStore<T = any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async init () {
|
public async init () {
|
||||||
this.db = await plugins.idb.openDB(this.options.storeName, 1, {
|
this.db = await plugins.idb.openDB(this.options.dbName, 1, {
|
||||||
upgrade(db) {
|
upgrade: (db) => {
|
||||||
db.createObjectStore('keyval');
|
db.createObjectStore(this.options.storeName);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(key) {
|
async get(key) {
|
||||||
return this.db.get('keyval', key);
|
return this.db.get(this.options.storeName, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
async set(key, val) {
|
async set(key, val) {
|
||||||
return this.db.put('keyval', val, key);
|
return this.db.put(this.options.storeName, val, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(key) {
|
async delete(key) {
|
||||||
return this.db.delete('keyval', key);
|
return this.db.delete(this.options.storeName, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
async clear() {
|
async clear() {
|
||||||
return this.db.clear('keyval');
|
return this.db.clear(this.options.storeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
async keys() {
|
async keys() {
|
||||||
return this.db.getAllKeys('keyval');
|
return this.db.getAllKeys(this.options.storeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user